Merge branch 'master' into new-jsonrpc
This commit is contained in:
@@ -20,7 +20,7 @@ use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View, Stream};
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View};
|
||||
use util::{Bytes, Address, Uint, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP};
|
||||
use util::error::{Mismatch, OutOfBounds};
|
||||
|
||||
@@ -59,8 +59,8 @@ impl Block {
|
||||
pub fn rlp_bytes(&self, seal: Seal) -> Bytes {
|
||||
let mut block_rlp = RlpStream::new_list(3);
|
||||
self.header.stream_rlp(&mut block_rlp, seal);
|
||||
block_rlp.append(&self.transactions);
|
||||
block_rlp.append(&self.uncles);
|
||||
block_rlp.append_list(&self.transactions);
|
||||
block_rlp.append_list(&self.uncles);
|
||||
block_rlp.out()
|
||||
}
|
||||
}
|
||||
@@ -507,7 +507,7 @@ impl SealedBlock {
|
||||
pub fn rlp_bytes(&self) -> Bytes {
|
||||
let mut block_rlp = RlpStream::new_list(3);
|
||||
self.block.header.stream_rlp(&mut block_rlp, Seal::With);
|
||||
block_rlp.append(&self.block.transactions);
|
||||
block_rlp.append_list(&self.block.transactions);
|
||||
block_rlp.append_raw(&self.uncle_bytes, 1);
|
||||
block_rlp.out()
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ impl Encodable for BlockDetails {
|
||||
s.append(&self.number);
|
||||
s.append(&self.total_difficulty);
|
||||
s.append(&self.parent);
|
||||
s.append(&self.children);
|
||||
s.append_list(&self.children);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ impl Decodable for BlockReceipts {
|
||||
|
||||
impl Encodable for BlockReceipts {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.receipts, s);
|
||||
s.append_list(&self.receipts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ impl Encodable for Block {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(3);
|
||||
s.append(&self.header);
|
||||
s.append(&self.transactions);
|
||||
s.append(&self.uncles);
|
||||
s.append_list(&self.transactions);
|
||||
s.append_list(&self.uncles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ impl Decodable for BloomGroup {
|
||||
|
||||
impl Encodable for BloomGroup {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.blooms, s)
|
||||
s.append_list(&self.blooms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use util::*;
|
||||
use super::{Height, View, BlockHash, Step};
|
||||
use error::Error;
|
||||
use header::Header;
|
||||
use rlp::{Rlp, UntrustedRlp, RlpStream, Stream, RlpEncodable, Encodable, Decodable, Decoder, DecoderError, View as RlpView};
|
||||
use rlp::{Rlp, UntrustedRlp, RlpStream, Encodable, Decodable, Decoder, DecoderError, View as RlpView};
|
||||
use ethkey::{recover, public_to_address};
|
||||
use super::super::vote_collector::Message;
|
||||
|
||||
@@ -162,7 +162,7 @@ impl Decodable for Step {
|
||||
|
||||
impl Encodable for Step {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
RlpEncodable::rlp_append(&self.number(), s);
|
||||
s.append_internal(&self.number());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,6 +278,7 @@ mod tests {
|
||||
::rlp::encode(&H520::default()).to_vec(),
|
||||
Vec::new()
|
||||
];
|
||||
|
||||
header.set_seal(seal);
|
||||
let message = ConsensusMessage::new_proposal(&header).unwrap();
|
||||
assert_eq!(
|
||||
|
||||
@@ -243,7 +243,7 @@ impl Tendermint {
|
||||
let seal = vec![
|
||||
::rlp::encode(&view).to_vec(),
|
||||
::rlp::encode(&seal.proposal).to_vec(),
|
||||
::rlp::encode(&seal.votes).to_vec()
|
||||
::rlp::encode_list(&seal.votes).to_vec()
|
||||
];
|
||||
self.submit_seal(block_hash, seal);
|
||||
self.to_next_height(height);
|
||||
@@ -825,7 +825,7 @@ mod tests {
|
||||
let vote_info = message_info_rlp(&VoteStep::new(2, 0, Step::Precommit), Some(header.bare_hash()));
|
||||
let signature1 = tap.sign(proposer, None, vote_info.sha3()).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode(&vec![H520::from(signature1.clone())]).to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).to_vec();
|
||||
header.set_seal(seal.clone());
|
||||
|
||||
// One good signature is not enough.
|
||||
@@ -837,7 +837,7 @@ mod tests {
|
||||
let voter = insert_and_unlock(&tap, "0");
|
||||
let signature0 = tap.sign(voter, None, vote_info.sha3()).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).to_vec();
|
||||
header.set_seal(seal.clone());
|
||||
|
||||
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
|
||||
@@ -845,7 +845,7 @@ mod tests {
|
||||
let bad_voter = insert_and_unlock(&tap, "101");
|
||||
let bad_signature = tap.sign(bad_voter, None, vote_info.sha3()).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode(&vec![H520::from(signature1), H520::from(bad_signature)]).to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).to_vec();
|
||||
header.set_seal(seal);
|
||||
|
||||
// One good and one bad signature.
|
||||
|
||||
@@ -245,7 +245,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn seal_retrieval() {
|
||||
let collector = VoteCollector::default();
|
||||
let collector = VoteCollector::default();
|
||||
let bh = Some("1".sha3());
|
||||
let mut signatures = Vec::new();
|
||||
for _ in 0..5 {
|
||||
@@ -284,7 +284,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn count_votes() {
|
||||
let collector = VoteCollector::default();
|
||||
let collector = VoteCollector::default();
|
||||
let round1 = 1;
|
||||
let round3 = 3;
|
||||
// good 1
|
||||
@@ -318,7 +318,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn remove_old() {
|
||||
let collector = VoteCollector::default();
|
||||
let collector = VoteCollector::default();
|
||||
let vote = |round, hash| {
|
||||
random_vote(&collector, H520::random(), round, hash);
|
||||
};
|
||||
@@ -334,7 +334,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn malicious_authority() {
|
||||
let collector = VoteCollector::default();
|
||||
let collector = VoteCollector::default();
|
||||
let round = 3;
|
||||
// Vote is inserted fine.
|
||||
assert!(full_vote(&collector, H520::random(), round, Some("0".sha3()), &Address::default()).is_none());
|
||||
|
||||
@@ -36,7 +36,7 @@ const STACK_SIZE_PER_DEPTH: usize = 24*1024;
|
||||
|
||||
/// Returns new address created from address and given nonce.
|
||||
pub fn contract_address(address: &Address, nonce: &U256) -> Address {
|
||||
use rlp::{RlpStream, Stream};
|
||||
use rlp::RlpStream;
|
||||
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(address);
|
||||
|
||||
@@ -26,7 +26,7 @@ use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress
|
||||
use util::sha3::Hashable;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rlp::{decode, Rlp, RlpStream, Stream, View};
|
||||
use rlp::{decode, Rlp, RlpStream, View};
|
||||
|
||||
|
||||
// attempt to migrate a key, value pair. None if migration not possible.
|
||||
@@ -199,7 +199,7 @@ impl OverlayRecentV7 {
|
||||
stream.begin_list(2).append(&k).append(&v);
|
||||
}
|
||||
|
||||
stream.append(&deleted_keys);
|
||||
stream.append_list(&deleted_keys);
|
||||
|
||||
// and insert it into the new database.
|
||||
batch.insert(entry_key, stream.out(), dest)?;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
//! This migration consolidates all databases into single one using Column Families.
|
||||
|
||||
use rlp::{Rlp, RlpStream, View, Stream};
|
||||
use rlp::{Rlp, RlpStream, View};
|
||||
use util::kvdb::Database;
|
||||
use util::migration::{Batch, Config, Error, Migration, Progress};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
use std::time::Duration;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::cell::Cell;
|
||||
use transaction::{SignedTransaction, Action};
|
||||
use transient_hashmap::TransientHashMap;
|
||||
use miner::{TransactionQueue, TransactionQueueDetailsProvider, TransactionImportResult, TransactionOrigin};
|
||||
@@ -47,15 +46,15 @@ impl Default for Threshold {
|
||||
pub struct BanningTransactionQueue {
|
||||
queue: TransactionQueue,
|
||||
ban_threshold: Threshold,
|
||||
senders_bans: TransientHashMap<Address, Cell<Count>>,
|
||||
recipients_bans: TransientHashMap<Address, Cell<Count>>,
|
||||
codes_bans: TransientHashMap<H256, Cell<Count>>,
|
||||
senders_bans: TransientHashMap<Address, Count>,
|
||||
recipients_bans: TransientHashMap<Address, Count>,
|
||||
codes_bans: TransientHashMap<H256, Count>,
|
||||
}
|
||||
|
||||
impl BanningTransactionQueue {
|
||||
/// Creates new banlisting transaction queue
|
||||
pub fn new(queue: TransactionQueue, ban_threshold: Threshold, ban_lifetime: Duration) -> Self {
|
||||
let ban_lifetime_sec = ban_lifetime.as_secs();
|
||||
let ban_lifetime_sec = ban_lifetime.as_secs() as u32;
|
||||
assert!(ban_lifetime_sec > 0, "Lifetime has to be specified in seconds.");
|
||||
BanningTransactionQueue {
|
||||
queue: queue,
|
||||
@@ -87,7 +86,7 @@ impl BanningTransactionQueue {
|
||||
|
||||
// Check sender
|
||||
let sender = transaction.sender();
|
||||
let count = self.senders_bans.direct().get(&sender).map(|v| v.get()).unwrap_or(0);
|
||||
let count = self.senders_bans.direct().get(&sender).cloned().unwrap_or(0);
|
||||
if count > threshold {
|
||||
debug!(target: "txqueue", "Ignoring transaction {:?} because sender is banned.", transaction.hash());
|
||||
return Err(Error::Transaction(TransactionError::SenderBanned));
|
||||
@@ -95,7 +94,7 @@ impl BanningTransactionQueue {
|
||||
|
||||
// Check recipient
|
||||
if let Action::Call(recipient) = transaction.action {
|
||||
let count = self.recipients_bans.direct().get(&recipient).map(|v| v.get()).unwrap_or(0);
|
||||
let count = self.recipients_bans.direct().get(&recipient).cloned().unwrap_or(0);
|
||||
if count > threshold {
|
||||
debug!(target: "txqueue", "Ignoring transaction {:?} because recipient is banned.", transaction.hash());
|
||||
return Err(Error::Transaction(TransactionError::RecipientBanned));
|
||||
@@ -105,7 +104,7 @@ impl BanningTransactionQueue {
|
||||
// Check code
|
||||
if let Action::Create = transaction.action {
|
||||
let code_hash = transaction.data.sha3();
|
||||
let count = self.codes_bans.direct().get(&code_hash).map(|v| v.get()).unwrap_or(0);
|
||||
let count = self.codes_bans.direct().get(&code_hash).cloned().unwrap_or(0);
|
||||
if count > threshold {
|
||||
debug!(target: "txqueue", "Ignoring transaction {:?} because code is banned.", transaction.hash());
|
||||
return Err(Error::Transaction(TransactionError::CodeBanned));
|
||||
@@ -147,9 +146,9 @@ impl BanningTransactionQueue {
|
||||
/// queue.
|
||||
fn ban_sender(&mut self, address: Address) -> bool {
|
||||
let count = {
|
||||
let mut count = self.senders_bans.entry(address).or_insert_with(|| Cell::new(0));
|
||||
*count.get_mut() = count.get().saturating_add(1);
|
||||
count.get()
|
||||
let mut count = self.senders_bans.entry(address).or_insert_with(|| 0);
|
||||
*count = count.saturating_add(1);
|
||||
*count
|
||||
};
|
||||
match self.ban_threshold {
|
||||
Threshold::BanAfter(threshold) if count > threshold => {
|
||||
@@ -167,9 +166,9 @@ impl BanningTransactionQueue {
|
||||
/// Returns true if bans threshold has been reached.
|
||||
fn ban_recipient(&mut self, address: Address) -> bool {
|
||||
let count = {
|
||||
let mut count = self.recipients_bans.entry(address).or_insert_with(|| Cell::new(0));
|
||||
*count.get_mut() = count.get().saturating_add(1);
|
||||
count.get()
|
||||
let mut count = self.recipients_bans.entry(address).or_insert_with(|| 0);
|
||||
*count = count.saturating_add(1);
|
||||
*count
|
||||
};
|
||||
match self.ban_threshold {
|
||||
// TODO [ToDr] Consider removing other transactions to the same recipient from the queue?
|
||||
@@ -183,12 +182,12 @@ impl BanningTransactionQueue {
|
||||
/// If bans threshold is reached all subsequent transactions to contracts with this codehash will be rejected.
|
||||
/// Returns true if bans threshold has been reached.
|
||||
fn ban_codehash(&mut self, code_hash: H256) -> bool {
|
||||
let mut count = self.codes_bans.entry(code_hash).or_insert_with(|| Cell::new(0));
|
||||
*count.get_mut() = count.get().saturating_add(1);
|
||||
let mut count = self.codes_bans.entry(code_hash).or_insert_with(|| 0);
|
||||
*count = count.saturating_add(1);
|
||||
|
||||
match self.ban_threshold {
|
||||
// TODO [ToDr] Consider removing other transactions with the same code from the queue?
|
||||
Threshold::BanAfter(threshold) if count.get() > threshold => true,
|
||||
Threshold::BanAfter(threshold) if *count > threshold => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ struct SealingWork {
|
||||
/// Handles preparing work for "work sealing" or seals "internally" if Engine does not require work.
|
||||
pub struct Miner {
|
||||
// NOTE [ToDr] When locking always lock in this order!
|
||||
transaction_queue: Arc<Mutex<BanningTransactionQueue>>,
|
||||
transaction_queue: Arc<RwLock<BanningTransactionQueue>>,
|
||||
sealing_work: Mutex<SealingWork>,
|
||||
next_allowed_reseal: Mutex<Instant>,
|
||||
next_mandatory_reseal: RwLock<Instant>,
|
||||
@@ -271,7 +271,7 @@ impl Miner {
|
||||
};
|
||||
|
||||
Miner {
|
||||
transaction_queue: Arc::new(Mutex::new(txq)),
|
||||
transaction_queue: Arc::new(RwLock::new(txq)),
|
||||
next_allowed_reseal: Mutex::new(Instant::now()),
|
||||
next_mandatory_reseal: RwLock::new(Instant::now() + options.reseal_max_period),
|
||||
sealing_block_last_request: Mutex::new(0),
|
||||
@@ -304,9 +304,7 @@ impl Miner {
|
||||
}
|
||||
|
||||
fn forced_sealing(&self) -> bool {
|
||||
self.options.force_sealing
|
||||
|| !self.notifiers.read().is_empty()
|
||||
|| Instant::now() > *self.next_mandatory_reseal.read()
|
||||
self.options.force_sealing || !self.notifiers.read().is_empty()
|
||||
}
|
||||
|
||||
/// Clear all pending block states
|
||||
@@ -330,7 +328,7 @@ impl Miner {
|
||||
let _timer = PerfTimer::new("prepare_block");
|
||||
let chain_info = chain.chain_info();
|
||||
let (transactions, mut open_block, original_work_hash) = {
|
||||
let transactions = {self.transaction_queue.lock().top_transactions_at(chain_info.best_block_number, chain_info.best_block_timestamp)};
|
||||
let transactions = {self.transaction_queue.read().top_transactions_at(chain_info.best_block_number, chain_info.best_block_timestamp)};
|
||||
let mut sealing_work = self.sealing_work.lock();
|
||||
let last_work_hash = sealing_work.queue.peek_last_ref().map(|pb| pb.block().fields().header.hash());
|
||||
let best_hash = chain_info.best_block_hash;
|
||||
@@ -377,7 +375,7 @@ impl Miner {
|
||||
// Check for heavy transactions
|
||||
match self.options.tx_queue_banning {
|
||||
Banning::Enabled { ref offend_threshold, .. } if &took > offend_threshold => {
|
||||
match self.transaction_queue.lock().ban_transaction(&hash) {
|
||||
match self.transaction_queue.write().ban_transaction(&hash) {
|
||||
true => {
|
||||
warn!(target: "miner", "Detected heavy transaction. Banning the sender and recipient/code.");
|
||||
},
|
||||
@@ -430,7 +428,7 @@ impl Miner {
|
||||
let fetch_nonce = |a: &Address| chain.latest_nonce(a);
|
||||
|
||||
{
|
||||
let mut queue = self.transaction_queue.lock();
|
||||
let mut queue = self.transaction_queue.write();
|
||||
for hash in invalid_transactions {
|
||||
queue.remove_invalid(&hash, &fetch_nonce);
|
||||
}
|
||||
@@ -447,13 +445,13 @@ impl Miner {
|
||||
let txq = self.transaction_queue.clone();
|
||||
self.gas_pricer.lock().recalibrate(move |price| {
|
||||
debug!(target: "miner", "minimal_gas_price: Got gas price! {}", price);
|
||||
txq.lock().set_minimal_gas_price(price);
|
||||
txq.write().set_minimal_gas_price(price);
|
||||
});
|
||||
}
|
||||
|
||||
/// Check is reseal is allowed and necessary.
|
||||
fn requires_reseal(&self, best_block: BlockNumber) -> bool {
|
||||
let has_local_transactions = self.transaction_queue.lock().has_local_pending_transactions();
|
||||
let has_local_transactions = self.transaction_queue.read().has_local_pending_transactions();
|
||||
let mut sealing_work = self.sealing_work.lock();
|
||||
if sealing_work.enabled {
|
||||
trace!(target: "miner", "requires_reseal: sealing enabled");
|
||||
@@ -484,7 +482,7 @@ impl Miner {
|
||||
|
||||
/// Attempts to perform internal sealing (one that does not require work) and handles the result depending on the type of Seal.
|
||||
fn seal_and_import_block_internally(&self, chain: &MiningBlockChainClient, block: ClosedBlock) -> bool {
|
||||
if !block.transactions().is_empty() || self.forced_sealing() {
|
||||
if !block.transactions().is_empty() || self.forced_sealing() || Instant::now() > *self.next_mandatory_reseal.read() {
|
||||
trace!(target: "miner", "seal_block_internally: attempting internal seal.");
|
||||
match self.engine.generate_seal(block.block()) {
|
||||
// Save proposal for later seal submission and broadcast it.
|
||||
@@ -559,7 +557,7 @@ impl Miner {
|
||||
|
||||
fn update_gas_limit(&self, client: &MiningBlockChainClient) {
|
||||
let gas_limit = client.best_block_header().gas_limit();
|
||||
let mut queue = self.transaction_queue.lock();
|
||||
let mut queue = self.transaction_queue.write();
|
||||
queue.set_gas_limit(gas_limit);
|
||||
if let GasLimit::Auto = self.options.tx_queue_gas_limit {
|
||||
// Set total tx queue gas limit to be 20x the block gas limit.
|
||||
@@ -681,7 +679,7 @@ const SEALING_TIMEOUT_IN_BLOCKS : u64 = 5;
|
||||
impl MinerService for Miner {
|
||||
|
||||
fn clear_and_reset(&self, chain: &MiningBlockChainClient) {
|
||||
self.transaction_queue.lock().clear();
|
||||
self.transaction_queue.write().clear();
|
||||
// --------------------------------------------------------------------------
|
||||
// | NOTE Code below requires transaction_queue and sealing_work locks. |
|
||||
// | Make sure to release the locks before calling that method. |
|
||||
@@ -690,7 +688,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn status(&self) -> MinerStatus {
|
||||
let status = self.transaction_queue.lock().status();
|
||||
let status = self.transaction_queue.read().status();
|
||||
let sealing_work = self.sealing_work.lock();
|
||||
MinerStatus {
|
||||
transactions_in_pending_queue: status.pending,
|
||||
@@ -820,16 +818,16 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn set_minimal_gas_price(&self, min_gas_price: U256) {
|
||||
self.transaction_queue.lock().set_minimal_gas_price(min_gas_price);
|
||||
self.transaction_queue.write().set_minimal_gas_price(min_gas_price);
|
||||
}
|
||||
|
||||
fn minimal_gas_price(&self) -> U256 {
|
||||
*self.transaction_queue.lock().minimal_gas_price()
|
||||
*self.transaction_queue.read().minimal_gas_price()
|
||||
}
|
||||
|
||||
fn sensible_gas_price(&self) -> U256 {
|
||||
// 10% above our minimum.
|
||||
*self.transaction_queue.lock().minimal_gas_price() * 110.into() / 100.into()
|
||||
*self.transaction_queue.read().minimal_gas_price() * 110.into() / 100.into()
|
||||
}
|
||||
|
||||
fn sensible_gas_limit(&self) -> U256 {
|
||||
@@ -837,15 +835,15 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn transactions_limit(&self) -> usize {
|
||||
self.transaction_queue.lock().limit()
|
||||
self.transaction_queue.read().limit()
|
||||
}
|
||||
|
||||
fn set_transactions_limit(&self, limit: usize) {
|
||||
self.transaction_queue.lock().set_limit(limit)
|
||||
self.transaction_queue.write().set_limit(limit)
|
||||
}
|
||||
|
||||
fn set_tx_gas_limit(&self, limit: U256) {
|
||||
self.transaction_queue.lock().set_tx_gas_limit(limit)
|
||||
self.transaction_queue.write().set_tx_gas_limit(limit)
|
||||
}
|
||||
|
||||
/// Get the author that we will seal blocks as.
|
||||
@@ -875,7 +873,7 @@ impl MinerService for Miner {
|
||||
) -> Vec<Result<TransactionImportResult, Error>> {
|
||||
trace!(target: "external_tx", "Importing external transactions");
|
||||
let results = {
|
||||
let mut transaction_queue = self.transaction_queue.lock();
|
||||
let mut transaction_queue = self.transaction_queue.write();
|
||||
self.add_transactions_to_queue(
|
||||
chain, transactions, TransactionOrigin::External, None, &mut transaction_queue
|
||||
)
|
||||
@@ -902,7 +900,7 @@ impl MinerService for Miner {
|
||||
|
||||
let imported = {
|
||||
// Be sure to release the lock before we call prepare_work_sealing
|
||||
let mut transaction_queue = self.transaction_queue.lock();
|
||||
let mut transaction_queue = self.transaction_queue.write();
|
||||
// We need to re-validate transactions
|
||||
let import = self.add_transactions_to_queue(
|
||||
chain, vec![pending.transaction.into()], TransactionOrigin::Local, pending.condition, &mut transaction_queue
|
||||
@@ -939,12 +937,12 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn pending_transactions(&self) -> Vec<PendingTransaction> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
let queue = self.transaction_queue.read();
|
||||
queue.pending_transactions(BlockNumber::max_value(), u64::max_value())
|
||||
}
|
||||
|
||||
fn local_transactions(&self) -> BTreeMap<H256, LocalTransactionStatus> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
let queue = self.transaction_queue.read();
|
||||
queue.local_transactions()
|
||||
.iter()
|
||||
.map(|(hash, status)| (*hash, status.clone()))
|
||||
@@ -952,11 +950,11 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn future_transactions(&self) -> Vec<PendingTransaction> {
|
||||
self.transaction_queue.lock().future_transactions()
|
||||
self.transaction_queue.read().future_transactions()
|
||||
}
|
||||
|
||||
fn ready_transactions(&self, best_block: BlockNumber, best_block_timestamp: u64) -> Vec<PendingTransaction> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
let queue = self.transaction_queue.read();
|
||||
match self.options.pending_set {
|
||||
PendingSet::AlwaysQueue => queue.pending_transactions(best_block, best_block_timestamp),
|
||||
PendingSet::SealingOrElseQueue => {
|
||||
@@ -977,7 +975,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn pending_transactions_hashes(&self, best_block: BlockNumber) -> Vec<H256> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
let queue = self.transaction_queue.read();
|
||||
match self.options.pending_set {
|
||||
PendingSet::AlwaysQueue => queue.pending_hashes(),
|
||||
PendingSet::SealingOrElseQueue => {
|
||||
@@ -998,7 +996,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn transaction(&self, best_block: BlockNumber, hash: &H256) -> Option<PendingTransaction> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
let queue = self.transaction_queue.read();
|
||||
match self.options.pending_set {
|
||||
PendingSet::AlwaysQueue => queue.find(hash),
|
||||
PendingSet::SealingOrElseQueue => {
|
||||
@@ -1019,7 +1017,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn remove_pending_transaction(&self, chain: &MiningBlockChainClient, hash: &H256) -> Option<PendingTransaction> {
|
||||
let mut queue = self.transaction_queue.lock();
|
||||
let mut queue = self.transaction_queue.write();
|
||||
let tx = queue.find(hash);
|
||||
if tx.is_some() {
|
||||
let fetch_nonce = |a: &Address| chain.latest_nonce(a);
|
||||
@@ -1079,7 +1077,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn last_nonce(&self, address: &Address) -> Option<U256> {
|
||||
self.transaction_queue.lock().last_nonce(address)
|
||||
self.transaction_queue.read().last_nonce(address)
|
||||
}
|
||||
|
||||
/// Update sealing if required.
|
||||
@@ -1169,7 +1167,7 @@ impl MinerService for Miner {
|
||||
// Then import all transactions...
|
||||
{
|
||||
|
||||
let mut transaction_queue = self.transaction_queue.lock();
|
||||
let mut transaction_queue = self.transaction_queue.write();
|
||||
for hash in retracted {
|
||||
let block = chain.block(BlockId::Hash(*hash))
|
||||
.expect("Client is sending message after commit to db and inserting to chain; the block is available; qed");
|
||||
@@ -1187,7 +1185,7 @@ impl MinerService for Miner {
|
||||
balance: chain.latest_balance(a),
|
||||
};
|
||||
let time = chain.chain_info().best_block_number;
|
||||
let mut transaction_queue = self.transaction_queue.lock();
|
||||
let mut transaction_queue = self.transaction_queue.write();
|
||||
transaction_queue.remove_old(&fetch_account, time);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use state::Account;
|
||||
use account_db::AccountDBMut;
|
||||
use ethjson;
|
||||
use types::account_diff::*;
|
||||
use rlp::{self, RlpStream, Stream};
|
||||
use rlp::{self, RlpStream};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
/// An account, expressed as Plain-Old-Data (hence the name).
|
||||
|
||||
@@ -22,7 +22,7 @@ use snapshot::Error;
|
||||
|
||||
use util::{U256, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::trie::{TrieDB, Trie};
|
||||
use rlp::{RlpStream, Stream, UntrustedRlp, View};
|
||||
use rlp::{RlpStream, UntrustedRlp, View};
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use block::Block;
|
||||
use header::Header;
|
||||
|
||||
use views::BlockView;
|
||||
use rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp, View};
|
||||
use util::{Bytes, Hashable, H256};
|
||||
use util::triehash::ordered_trie_root;
|
||||
|
||||
@@ -69,7 +69,9 @@ impl AbridgedBlock {
|
||||
.append(&header.extra_data());
|
||||
|
||||
// write block values.
|
||||
stream.append(&block_view.transactions()).append(&block_view.uncles());
|
||||
stream
|
||||
.append_list(&block_view.transactions())
|
||||
.append_list(&block_view.uncles());
|
||||
|
||||
// write seal fields.
|
||||
for field in seal_fields {
|
||||
@@ -108,7 +110,7 @@ impl AbridgedBlock {
|
||||
header.set_receipts_root(receipts_root);
|
||||
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append(&uncles);
|
||||
uncles_rlp.append_list(&uncles);
|
||||
header.set_uncles_hash(uncles_rlp.as_raw().sha3());
|
||||
|
||||
let mut seal_fields = Vec::new();
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use util::Bytes;
|
||||
use util::hash::H256;
|
||||
use rlp::{self, Encodable, RlpStream, UntrustedRlp, Stream, View};
|
||||
use rlp::{self, Encodable, RlpStream, UntrustedRlp, View};
|
||||
|
||||
use super::ManifestData;
|
||||
|
||||
@@ -122,8 +122,8 @@ impl SnapshotWriter for PackedWriter {
|
||||
// they are consistent with ours.
|
||||
let mut stream = RlpStream::new_list(5);
|
||||
stream
|
||||
.append(&self.state_hashes)
|
||||
.append(&self.block_hashes)
|
||||
.append_list(&self.state_hashes)
|
||||
.append_list(&self.block_hashes)
|
||||
.append(&manifest.state_root)
|
||||
.append(&manifest.block_number)
|
||||
.append(&manifest.block_hash);
|
||||
@@ -428,4 +428,4 @@ mod tests {
|
||||
reader.chunk(hash.clone()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ use util::journaldb::{self, Algorithm, JournalDB};
|
||||
use util::kvdb::Database;
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use rlp::{RlpStream, Stream, UntrustedRlp, View};
|
||||
use rlp::{RlpStream, UntrustedRlp, View};
|
||||
use bloom_journal::Bloom;
|
||||
|
||||
use self::block::AbridgedBlock;
|
||||
|
||||
@@ -99,7 +99,7 @@ fn chunk_and_restore_40k() { chunk_and_restore(40000) }
|
||||
|
||||
#[test]
|
||||
fn checks_flag() {
|
||||
use ::rlp::{RlpStream, Stream};
|
||||
use rlp::RlpStream;
|
||||
use util::H256;
|
||||
|
||||
let mut stream = RlpStream::new_list(5);
|
||||
|
||||
@@ -95,7 +95,7 @@ fn snap_and_restore() {
|
||||
#[test]
|
||||
fn get_code_from_prev_chunk() {
|
||||
use std::collections::HashSet;
|
||||
use rlp::{RlpStream, Stream};
|
||||
use rlp::RlpStream;
|
||||
use util::{HashDB, H256, U256, Hashable};
|
||||
|
||||
use account_db::{AccountDBMut, AccountDB};
|
||||
|
||||
@@ -64,9 +64,12 @@ impl Into<Generic> for AuthorityRound {
|
||||
|
||||
impl Into<Generic> for Tendermint {
|
||||
fn into(self) -> Generic {
|
||||
let mut s = RlpStream::new_list(3);
|
||||
s.append(&self.round).append(&self.proposal).append(&self.precommits);
|
||||
Generic(s.out())
|
||||
let mut stream = RlpStream::new_list(3);
|
||||
stream
|
||||
.append(&self.round)
|
||||
.append(&self.proposal)
|
||||
.append_list(&self.precommits);
|
||||
Generic(stream.out())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ use super::genesis::Genesis;
|
||||
use super::seal::Generic as GenericSeal;
|
||||
use ethereum;
|
||||
use ethjson;
|
||||
use rlp::{Rlp, RlpStream, View, Stream};
|
||||
use rlp::{Rlp, RlpStream, View};
|
||||
|
||||
/// Parameters common to all engines.
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
|
||||
@@ -34,7 +34,7 @@ use devtools::*;
|
||||
use miner::Miner;
|
||||
use header::Header;
|
||||
use transaction::{Action, Transaction, SignedTransaction};
|
||||
use rlp::{self, RlpStream, Stream};
|
||||
use rlp::{self, RlpStream};
|
||||
use views::BlockView;
|
||||
|
||||
#[cfg(feature = "json-tests")]
|
||||
@@ -129,7 +129,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa
|
||||
for t in transactions {
|
||||
rlp.append_raw(&rlp::encode(t).to_vec(), 1);
|
||||
}
|
||||
rlp.append(&uncles);
|
||||
rlp.append_list(&uncles);
|
||||
rlp.out()
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ impl Decodable for BlockTracesBloomGroup {
|
||||
|
||||
impl Encodable for BlockTracesBloomGroup {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.blooms, s)
|
||||
s.append_list(&self.blooms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Encodable for LogEntry {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(3);
|
||||
s.append(&self.address);
|
||||
s.append(&self.topics);
|
||||
s.append_list(&self.topics);
|
||||
s.append(&self.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Encodable for Receipt {
|
||||
}
|
||||
s.append(&self.gas_used);
|
||||
s.append(&self.log_bloom);
|
||||
s.append(&self.logs);
|
||||
s.append_list(&self.logs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ impl ManifestData {
|
||||
/// Encode the manifest data to rlp.
|
||||
pub fn into_rlp(self) -> Bytes {
|
||||
let mut stream = RlpStream::new_list(5);
|
||||
stream.append(&self.state_hashes);
|
||||
stream.append(&self.block_hashes);
|
||||
stream.append_list(&self.state_hashes);
|
||||
stream.append_list(&self.block_hashes);
|
||||
stream.append(&self.state_root);
|
||||
stream.append(&self.block_number);
|
||||
stream.append(&self.block_hash);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Trace errors.
|
||||
|
||||
use std::fmt;
|
||||
use rlp::{RlpEncodable, Encodable, RlpStream, Decodable, Decoder, DecoderError, View};
|
||||
use rlp::{Encodable, RlpStream, Decodable, Decoder, DecoderError, View};
|
||||
use evm::Error as EvmError;
|
||||
|
||||
/// Trace evm errors.
|
||||
@@ -85,7 +85,8 @@ impl Encodable for Error {
|
||||
OutOfStack => 4,
|
||||
Internal => 5,
|
||||
};
|
||||
RlpEncodable::rlp_append(&value, s);
|
||||
|
||||
s.append_internal(&value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Encodable for FlatTrace {
|
||||
s.append(&self.action);
|
||||
s.append(&self.result);
|
||||
s.append(&self.subtraces);
|
||||
s.append(&self.trace_address.clone().into_iter().collect::<Vec<_>>());
|
||||
s.append_list::<usize, &usize>(&self.trace_address.iter().collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ impl FlatTransactionTraces {
|
||||
|
||||
impl Encodable for FlatTransactionTraces {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.0, s);
|
||||
s.append_list(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ impl FlatBlockTraces {
|
||||
|
||||
impl Encodable for FlatBlockTraces {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.0, s);
|
||||
s.append_list(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ impl Encodable for VMExecutedOperation {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(4);
|
||||
s.append(&self.gas_used);
|
||||
s.append(&self.stack_push);
|
||||
s.append_list(&self.stack_push);
|
||||
s.append(&self.mem_diff);
|
||||
s.append(&self.store_diff);
|
||||
}
|
||||
@@ -551,8 +551,8 @@ impl Encodable for VMTrace {
|
||||
s.begin_list(4);
|
||||
s.append(&self.parent_step);
|
||||
s.append(&self.code);
|
||||
s.append(&self.operations);
|
||||
s.append(&self.subs);
|
||||
s.append_list(&self.operations);
|
||||
s.append_list(&self.subs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg_attr(feature="dev", allow(similar_names))]
|
||||
fn test_verify_block() {
|
||||
use rlp::{RlpStream, Stream};
|
||||
use rlp::RlpStream;
|
||||
|
||||
// Test against morden
|
||||
let mut good = Header::new();
|
||||
@@ -460,7 +460,7 @@ mod tests {
|
||||
|
||||
let good_uncles = vec![ good_uncle1.clone(), good_uncle2.clone() ];
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append(&good_uncles);
|
||||
uncles_rlp.append_list(&good_uncles);
|
||||
let good_uncles_hash = uncles_rlp.as_raw().sha3();
|
||||
let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| ::rlp::encode::<UnverifiedTransaction>(t).to_vec()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user