From e833606232aa72b8d37a3d11dde4511476a0507f Mon Sep 17 00:00:00 2001 From: lihuafeng Date: Tue, 20 Mar 2018 17:48:47 +0800 Subject: [PATCH 1/3] Some tiny modifications. 1. fix some typo in the comment. 2. sort the order of methods in 'impl state::Backend for StateDB` --- ethcore/src/state/account.rs | 4 ++-- ethcore/src/state/mod.rs | 4 ++-- ethcore/src/state_db.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) mode change 100644 => 100755 ethcore/src/state/account.rs mode change 100644 => 100755 ethcore/src/state/mod.rs mode change 100644 => 100755 ethcore/src/state_db.rs diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs old mode 100644 new mode 100755 index da490245406..f70b3eb6a81 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -62,7 +62,7 @@ pub struct Account { storage_changes: HashMap, // Code hash of the account. code_hash: H256, - // Size of the accoun code. + // Size of the account code. code_size: Option, // Code cache of the account. code_cache: Arc, @@ -186,7 +186,7 @@ impl Account { } /// Get (and cache) the contents of the trie's storage at `key`. - /// Takes modifed storage into account. + /// Takes modified storage into account. pub fn storage_at(&self, db: &HashDB, key: &H256) -> trie::Result { if let Some(value) = self.cached_storage_at(key) { return Ok(value); diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs old mode 100644 new mode 100755 index fa8ca009b12..1fe4dd4d6d9 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -365,7 +365,7 @@ impl State { pub fn new(mut db: B, account_start_nonce: U256, factories: Factories) -> State { let mut root = H256::new(); { - // init trie and reset root too null + // init trie and reset root to null let _ = factories.trie.create(db.as_hashdb_mut(), &mut root); } @@ -553,8 +553,8 @@ impl State { // 2. If there's an entry for the account in the global cache check for the key or load it into that account. // 3. If account is missing in the global cache load it into the local cache and cache the key there. - // check local cache first without updating { + // check local cache first without updating let local_cache = self.cache.borrow_mut(); let mut local_account = None; if let Some(maybe_acc) = local_cache.get(address) { diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs old mode 100644 new mode 100755 index 647ec38491f..346ad9cc2a6 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -440,12 +440,6 @@ impl state::Backend for StateDB { cache.accounts.get_mut(addr).map(|a| a.as_ref().map(|a| a.clone_basic())) } - fn get_cached_code(&self, hash: &H256) -> Option>> { - let mut cache = self.code_cache.lock(); - - cache.get_mut(hash).map(|code| code.clone()) - } - fn get_cached(&self, a: &Address, f: F) -> Option where F: FnOnce(Option<&mut Account>) -> U { let mut cache = self.account_cache.lock(); @@ -455,6 +449,12 @@ impl state::Backend for StateDB { cache.accounts.get_mut(a).map(|c| f(c.as_mut())) } + fn get_cached_code(&self, hash: &H256) -> Option>> { + let mut cache = self.code_cache.lock(); + + cache.get_mut(hash).map(|code| code.clone()) + } + fn note_non_null_account(&self, address: &Address) { trace!(target: "account_bloom", "Note account bloom: {:?}", address); let mut bloom = self.account_bloom.lock(); From 23947c3ac2ff493bf5caa36acc478f46ca276b95 Mon Sep 17 00:00:00 2001 From: lihuafeng Date: Mon, 9 Apr 2018 10:34:27 +0800 Subject: [PATCH 2/3] Remove the clone of code_cache, as it has been done in clone_basic. --- ethcore/src/state/account.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index e08ad7b1854..9d72ed158cf 100755 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -424,7 +424,6 @@ impl Account { pub fn clone_dirty(&self) -> Account { let mut account = self.clone_basic(); account.storage_changes = self.storage_changes.clone(); - account.code_cache = self.code_cache.clone(); account } From 84778b1e4fa39294707a42fd7b8f830004b2aad3 Mon Sep 17 00:00:00 2001 From: lihuafeng Date: Fri, 13 Apr 2018 10:52:37 +0800 Subject: [PATCH 3/3] remove From::from. It seems not necessary. --- ethcore/src/executive.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) mode change 100644 => 100755 ethcore/src/executive.rs diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs old mode 100644 new mode 100755 index a97ee37081a..142086beb92 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -237,27 +237,27 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { let base_gas_required = U256::from(t.gas_required(&schedule)); if t.gas < base_gas_required { - return Err(From::from(ExecutionError::NotEnoughBaseGas { required: base_gas_required, got: t.gas })); + return Err(ExecutionError::NotEnoughBaseGas { required: base_gas_required, got: t.gas }); } if !t.is_unsigned() && check_nonce && schedule.kill_dust != CleanDustMode::Off && !self.state.exists(&sender)? { - return Err(From::from(ExecutionError::SenderMustExist)); + return Err(ExecutionError::SenderMustExist); } let init_gas = t.gas - base_gas_required; // validate transaction nonce if check_nonce && t.nonce != nonce { - return Err(From::from(ExecutionError::InvalidNonce { expected: nonce, got: t.nonce })); + return Err(ExecutionError::InvalidNonce { expected: nonce, got: t.nonce }); } // validate if transaction fits into given block if self.info.gas_used + t.gas > self.info.gas_limit { - return Err(From::from(ExecutionError::BlockGasLimitReached { + return Err(ExecutionError::BlockGasLimitReached { gas_limit: self.info.gas_limit, gas_used: self.info.gas_used, gas: t.gas - })); + }); } // TODO: we might need bigints here, or at least check overflows. @@ -268,7 +268,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { // avoid unaffordable transactions let balance512 = U512::from(balance); if balance512 < total_cost { - return Err(From::from(ExecutionError::NotEnoughCash { required: total_cost, got: balance512 })); + return Err(ExecutionError::NotEnoughCash { required: total_cost, got: balance512 }); } let mut substate = Substate::new();