From bbcd094906188d765a6999fe7604d0370df9c893 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 23 Feb 2020 16:49:17 +0100 Subject: [PATCH] Misc fixes (#11510) * Misc fixes Did some code reading and made random changes as I went. * Update ethcore/src/client/client.rs Co-Authored-By: Andronik Ordian Co-authored-by: Andronik Ordian --- ethcore/account-state/src/state.rs | 10 +++++----- ethcore/engines/authority-round/src/lib.rs | 2 +- ethcore/pod/src/account.rs | 2 +- ethcore/src/block.rs | 10 +++++----- ethcore/src/client/client.rs | 4 ++-- ethcore/src/client/config.rs | 2 +- ethcore/src/miner/miner.rs | 2 +- ethcore/src/test_helpers/mod.rs | 4 ++-- ethcore/src/tests/trace.rs | 2 +- parity/cache.rs | 14 ++++++++------ 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ethcore/account-state/src/state.rs b/ethcore/account-state/src/state.rs index 6155b7f09..13086d7b1 100644 --- a/ethcore/account-state/src/state.rs +++ b/ethcore/account-state/src/state.rs @@ -434,7 +434,7 @@ impl State { /// Get the nonce of account `a`. pub fn nonce(&self, a: &Address) -> TrieResult { self.ensure_cached(a, RequireCache::None, true, - |a| a.as_ref().map_or(self.account_start_nonce, |account| *account.nonce())) + |a| a.map_or(self.account_start_nonce, |account| *account.nonce())) } /// Whether the base storage root of an account remains unchanged. @@ -1014,13 +1014,13 @@ impl State { } /// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too. - pub fn require<'a>(&'a self, a: &Address, require_code: bool) -> TrieResult> { + pub fn require(&self, a: &Address, require_code: bool) -> TrieResult> { self.require_or_from(a, require_code, || Account::new_basic(0u8.into(), self.account_start_nonce), |_| {}) } /// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too. /// If it doesn't exist, make account equal the evaluation of `default`. - pub fn require_or_from<'a, F, G>(&'a self, a: &Address, require_code: bool, default: F, not_default: G) -> TrieResult> + pub fn require_or_from(&self, a: &Address, require_code: bool, default: F, not_default: G) -> TrieResult> where F: FnOnce() -> Account, G: FnOnce(&mut Account), { let contains_key = self.cache.borrow().contains_key(a); @@ -1137,8 +1137,8 @@ impl State { } } -//// TODO: cloning for `State` shouldn't be possible in general; Remove this and use -//// checkpoints where possible. +// TODO: cloning for `State` shouldn't be possible in general; Remove this and use +// checkpoints where possible. impl Clone for State { fn clone(&self) -> State { let cache = { diff --git a/ethcore/engines/authority-round/src/lib.rs b/ethcore/engines/authority-round/src/lib.rs index 919319d06..553aaecd8 100644 --- a/ethcore/engines/authority-round/src/lib.rs +++ b/ethcore/engines/authority-round/src/lib.rs @@ -2558,7 +2558,7 @@ mod tests { gas: U256::from(53_000), value: U256::from(1), data: vec![], - }.fake_sign(addr2), None).unwrap(); + }.fake_sign(addr2)).unwrap(); let b2 = b2.close_and_lock().unwrap(); // we will now seal a block with 1tx and include the accumulated empty step message diff --git a/ethcore/pod/src/account.rs b/ethcore/pod/src/account.rs index f3a3c9f4d..e0b11be72 100644 --- a/ethcore/pod/src/account.rs +++ b/ethcore/pod/src/account.rs @@ -100,7 +100,7 @@ impl From for PodAccount { } } -/// Determine difference between two optionally existant `Account`s. Returns None +/// Determine difference between two optionally existent `Account`s. Returns None /// if they are the same. pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option { match (pre, post) { diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 06127a77e..7dc8c4276 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -35,7 +35,7 @@ use std::{cmp, ops}; use std::sync::Arc; use bytes::Bytes; -use ethereum_types::{H256, U256, Address, Bloom}; +use ethereum_types::{U256, Address, Bloom}; use engine::Engine; use trie_vm_factories::Factories; @@ -168,7 +168,7 @@ impl<'x> OpenBlock<'x> { /// Push a transaction into the block. /// /// If valid, it will be executed, and archived together with the receipt. - pub fn push_transaction(&mut self, t: SignedTransaction, h: Option) -> Result<&Receipt, Error> { + pub fn push_transaction(&mut self, t: SignedTransaction) -> Result<&Receipt, Error> { if self.block.transactions_set.contains(&t.hash()) { return Err(TransactionError::AlreadyImported.into()); } @@ -176,7 +176,7 @@ impl<'x> OpenBlock<'x> { let env_info = self.block.env_info(); let outcome = self.block.state.apply(&env_info, self.engine.machine(), &t, self.block.traces.is_enabled())?; - self.block.transactions_set.insert(h.unwrap_or_else(||t.hash())); + self.block.transactions_set.insert(t.hash()); self.block.transactions.push(t.into()); if let Tracing::Enabled(ref mut traces) = self.block.traces { traces.push(outcome.trace.into()); @@ -189,7 +189,7 @@ impl<'x> OpenBlock<'x> { #[cfg(not(feature = "slow-blocks"))] fn push_transactions(&mut self, transactions: Vec) -> Result<(), Error> { for t in transactions { - self.push_transaction(t, None)?; + self.push_transaction(t)?; } Ok(()) } @@ -203,7 +203,7 @@ impl<'x> OpenBlock<'x> { for t in transactions { let hash = t.hash(); let start = time::Instant::now(); - self.push_transaction(t, None)?; + self.push_transaction(t)?; let took = start.elapsed(); let took_ms = took.as_secs() * 1000 + took.subsec_nanos() as u64 / 1000000; if took > time::Duration::from_millis(slow_tx) { diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 9ceeff78e..4033ce347 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -742,7 +742,7 @@ impl Client { let chain = Arc::new(BlockChain::new(config.blockchain.clone(), &gb, db.clone())); let tracedb = RwLock::new(TraceDB::new(config.tracing.clone(), db.clone(), chain.clone())); - trace!("Cleanup journal: DB Earliest = {:?}, Latest = {:?}", state_db.journal_db().earliest_era(), state_db.journal_db().latest_era()); + debug!(target: "client", "Cleanup journal: DB Earliest = {:?}, Latest = {:?}", state_db.journal_db().earliest_era(), state_db.journal_db().latest_era()); let history = if config.history < MIN_HISTORY_SIZE { info!(target: "client", "Ignoring pruning history parameter of {}\ @@ -942,7 +942,6 @@ impl Client { let (result, items) = self.prove_transaction(tx, id) .ok_or_else(|| "Unable to make call. State unavailable?".to_string())?; - let items = items.into_iter().map(|x| x.to_vec()).collect(); Ok((result, items)) }; @@ -1070,6 +1069,7 @@ impl Client { // early exit for pruned blocks if db.is_prunable() && self.pruning_info().earliest_state > block_number { + trace!(target: "client", "State for block #{} is pruned. Earliest state: {:?}", block_number, self.pruning_info().earliest_state); return None; } diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index 690596c33..409800619 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -78,7 +78,7 @@ pub struct ClientConfig { pub spec_name: String, /// Type of block verifier used by client. pub verifier_type: VerifierType, - /// State db cache-size. + /// State db cache-size. Default: 25Mb. pub state_cache_size: usize, /// EVM jump-tables cache size. pub jump_table_size: usize, diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 9dbfca612..afb2baeee 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -535,7 +535,7 @@ impl Miner { let result = client.verify_for_pending_block(&transaction, &open_block.header) .map_err(|e| e.into()) .and_then(|_| { - open_block.push_transaction(transaction, None) + open_block.push_transaction(transaction) }); let took = start.elapsed(); diff --git a/ethcore/src/test_helpers/mod.rs b/ethcore/src/test_helpers/mod.rs index 216086934..711f2fcc0 100644 --- a/ethcore/src/test_helpers/mod.rs +++ b/ethcore/src/test_helpers/mod.rs @@ -190,7 +190,7 @@ pub fn generate_dummy_client_with_spec_and_data( action: Action::Create, data: vec![], value: U256::zero(), - }.sign(kp.secret(), Some(test_spec.chain_id())), None).unwrap(); + }.sign(kp.secret(), Some(test_spec.chain_id()))).unwrap(); n += 1; } @@ -247,7 +247,7 @@ pub fn push_block_with_transactions(client: &Arc, transactions: &[Signed b.set_timestamp(block_number * 10); for t in transactions { - b.push_transaction(t.clone(), None).unwrap(); + b.push_transaction(t.clone()).unwrap(); } let b = b.close_and_lock().unwrap().seal(test_engine, vec![]).unwrap(); diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index cc4bb096d..e426eeae4 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -159,7 +159,7 @@ fn can_trace_block_and_uncle_reward() { action: Action::Create, data: vec![], value: U256::zero(), - }.sign(kp.secret(), Some(spec.network_id())), None).unwrap(); + }.sign(kp.secret(), Some(spec.network_id()))).unwrap(); n += 1; } diff --git a/parity/cache.rs b/parity/cache.rs index 5b1ee048c..e91efd663 100644 --- a/parity/cache.rs +++ b/parity/cache.rs @@ -52,7 +52,9 @@ impl Default for CacheConfig { } impl CacheConfig { - /// Creates new cache config with cumulative size equal `total`. + /// Creates new cache config with cumulative size equal to `total`, distributed as follows: 70% + /// to rocksdb, 10% to the blockchain cache and 20% to the state cache. The transaction queue + /// cache size is set to 40Mb and the trace cache to 20Mb. pub fn new_with_total_cache_size(total: u32) -> Self { CacheConfig { db: total * 7 / 10, @@ -63,14 +65,14 @@ impl CacheConfig { } } - /// Creates new cache config with gitven details. + /// Creates new cache config with given details. pub fn new(db: u32, blockchain: u32, queue: u32, state: u32) -> Self { CacheConfig { - db: db, - blockchain: blockchain, - queue: queue, + db, + blockchain, + queue, traces: DEFAULT_TRACE_CACHE_SIZE, - state: state, + state, } }