Random cleanups / improvements to a state (#6472)

This commit is contained in:
Marek Kotewicz 2017-09-19 11:34:13 +02:00 committed by Gav Wood
parent 9196c7268a
commit f38d34919b
2 changed files with 35 additions and 37 deletions

View File

@ -450,22 +450,19 @@ impl<B: Backend> State<B> {
//
// In all other cases account is read as clean first, and after that made
// dirty in and added to the checkpoint with `note_cache`.
if account.is_dirty() {
let is_dirty = account.is_dirty();
let old_value = self.cache.borrow_mut().insert(*address, account);
if is_dirty {
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
if !checkpoint.contains_key(address) {
checkpoint.insert(address.clone(), self.cache.borrow_mut().insert(address.clone(), account));
return;
}
checkpoint.entry(*address).or_insert(old_value);
}
}
self.cache.borrow_mut().insert(address.clone(), account);
}
fn note_cache(&self, address: &Address) {
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
if !checkpoint.contains_key(address) {
checkpoint.insert(address.clone(), self.cache.borrow().get(address).map(AccountEntry::clone_dirty));
}
checkpoint.entry(*address)
.or_insert_with(|| self.cache.borrow().get(address).map(AccountEntry::clone_dirty));
}
}
@ -559,9 +556,8 @@ impl<B: Backend> State<B> {
}
});
match trie_res {
None => {}
Some(res) => return res,
if let Some(res) = trie_res {
return res;
}
// otherwise cache the account localy and cache storage key there.
@ -868,27 +864,29 @@ impl<B: Backend> State<B> {
// load required account data from the databases.
fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &B, db: &HashDB) {
match (account.is_cached(), require) {
(true, _) | (false, RequireCache::None) => {}
(false, require) => {
// if there's already code in the global cache, always cache it
// locally.
let hash = account.code_hash();
match state_db.get_cached_code(&hash) {
Some(code) => account.cache_given_code(code),
None => match require {
RequireCache::None => {},
RequireCache::Code => {
if let Some(code) = account.cache_code(db) {
// propagate code loaded from the database to
// the global code cache.
state_db.cache_code(hash, code)
}
}
RequireCache::CodeSize => {
account.cache_code_size(db);
}
if let RequireCache::None = require {
return;
}
if account.is_cached() {
return;
}
// if there's already code in the global cache, always cache it localy
let hash = account.code_hash();
match state_db.get_cached_code(&hash) {
Some(code) => account.cache_given_code(code),
None => match require {
RequireCache::None => {},
RequireCache::Code => {
if let Some(code) = account.cache_code(db) {
// propagate code loaded from the database to
// the global code cache.
state_db.cache_code(hash, code)
}
},
RequireCache::CodeSize => {
account.cache_code_size(db);
}
}
}
@ -938,7 +936,7 @@ impl<B: Backend> State<B> {
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
fn require<'a>(&'a self, a: &Address, require_code: bool) -> trie::Result<RefMut<'a, Account>> {
self.require_or_from(a, require_code, || Account::new_basic(U256::from(0u8), self.account_start_nonce), |_|{})
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.

View File

@ -50,11 +50,11 @@ impl Substate {
/// Merge secondary substate `s` into self, accruing each element correspondingly.
pub fn accrue(&mut self, s: Substate) {
self.suicides.extend(s.suicides.into_iter());
self.touched.extend(s.touched.into_iter());
self.logs.extend(s.logs.into_iter());
self.suicides.extend(s.suicides);
self.touched.extend(s.touched);
self.logs.extend(s.logs);
self.sstore_clears_count = self.sstore_clears_count + s.sstore_clears_count;
self.contracts_created.extend(s.contracts_created.into_iter());
self.contracts_created.extend(s.contracts_created);
}
/// Get the cleanup mode object from this.