Random cleanups / improvements to a state (#6472)
This commit is contained in:
parent
9196c7268a
commit
f38d34919b
@ -450,22 +450,19 @@ impl<B: Backend> State<B> {
|
|||||||
//
|
//
|
||||||
// In all other cases account is read as clean first, and after that made
|
// In all other cases account is read as clean first, and after that made
|
||||||
// dirty in and added to the checkpoint with `note_cache`.
|
// 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 let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
|
||||||
if !checkpoint.contains_key(address) {
|
checkpoint.entry(*address).or_insert(old_value);
|
||||||
checkpoint.insert(address.clone(), self.cache.borrow_mut().insert(address.clone(), account));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.cache.borrow_mut().insert(address.clone(), account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note_cache(&self, address: &Address) {
|
fn note_cache(&self, address: &Address) {
|
||||||
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
|
if let Some(ref mut checkpoint) = self.checkpoints.borrow_mut().last_mut() {
|
||||||
if !checkpoint.contains_key(address) {
|
checkpoint.entry(*address)
|
||||||
checkpoint.insert(address.clone(), self.cache.borrow().get(address).map(AccountEntry::clone_dirty));
|
.or_insert_with(|| self.cache.borrow().get(address).map(AccountEntry::clone_dirty));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,9 +556,8 @@ impl<B: Backend> State<B> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
match trie_res {
|
if let Some(res) = trie_res {
|
||||||
None => {}
|
return res;
|
||||||
Some(res) => return res,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise cache the account localy and cache storage key there.
|
// 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.
|
// load required account data from the databases.
|
||||||
fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &B, db: &HashDB) {
|
fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &B, db: &HashDB) {
|
||||||
match (account.is_cached(), require) {
|
if let RequireCache::None = require {
|
||||||
(true, _) | (false, RequireCache::None) => {}
|
return;
|
||||||
(false, require) => {
|
}
|
||||||
// if there's already code in the global cache, always cache it
|
|
||||||
// locally.
|
if account.is_cached() {
|
||||||
let hash = account.code_hash();
|
return;
|
||||||
match state_db.get_cached_code(&hash) {
|
}
|
||||||
Some(code) => account.cache_given_code(code),
|
|
||||||
None => match require {
|
// if there's already code in the global cache, always cache it localy
|
||||||
RequireCache::None => {},
|
let hash = account.code_hash();
|
||||||
RequireCache::Code => {
|
match state_db.get_cached_code(&hash) {
|
||||||
if let Some(code) = account.cache_code(db) {
|
Some(code) => account.cache_given_code(code),
|
||||||
// propagate code loaded from the database to
|
None => match require {
|
||||||
// the global code cache.
|
RequireCache::None => {},
|
||||||
state_db.cache_code(hash, code)
|
RequireCache::Code => {
|
||||||
}
|
if let Some(code) = account.cache_code(db) {
|
||||||
}
|
// propagate code loaded from the database to
|
||||||
RequireCache::CodeSize => {
|
// the global code cache.
|
||||||
account.cache_code_size(db);
|
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.
|
/// 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>> {
|
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.
|
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
|
||||||
|
@ -50,11 +50,11 @@ impl Substate {
|
|||||||
|
|
||||||
/// Merge secondary substate `s` into self, accruing each element correspondingly.
|
/// Merge secondary substate `s` into self, accruing each element correspondingly.
|
||||||
pub fn accrue(&mut self, s: Substate) {
|
pub fn accrue(&mut self, s: Substate) {
|
||||||
self.suicides.extend(s.suicides.into_iter());
|
self.suicides.extend(s.suicides);
|
||||||
self.touched.extend(s.touched.into_iter());
|
self.touched.extend(s.touched);
|
||||||
self.logs.extend(s.logs.into_iter());
|
self.logs.extend(s.logs);
|
||||||
self.sstore_clears_count = self.sstore_clears_count + s.sstore_clears_count;
|
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.
|
/// Get the cleanup mode object from this.
|
||||||
|
Loading…
Reference in New Issue
Block a user