Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Style and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Sep 27, 2016
1 parent ca997e5 commit 7e34afa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
9 changes: 3 additions & 6 deletions ethcore/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,15 @@ impl Account {
entry.insert(value);
self.filth = Filth::Dirty;
},
_ => (),
_ => {},
}
}

/// Get (and cache) the contents of the trie's storage at `key`.
/// Takes modifed storage into account.
pub fn storage_at(&self, db: &AccountDB, key: &H256) -> H256 {
if let Some(value) = self.storage_changes.get(key) {
return value.clone()
}
if let Some(value) = self.storage_cache.borrow_mut().get_mut(key) {
return value.clone()
if let Some(value) = self.cached_storage_at(key) {
return value;
}
let db = SecTrieDB::new(db, &self.storage_root)
.expect("Account storage_root initially set to zero (valid) and only altered by SecTrieDBMut. \
Expand Down
21 changes: 18 additions & 3 deletions ethcore/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl AccountEntry {
}

/// Clone account entry data that needs to be saved in the snapshot.
/// This includes basic account information and dirty storage keys
/// This includes basic account information and all locally cached storage keys
fn clone_for_snapshot(&self) -> AccountEntry {
match *self {
AccountEntry::Cached(ref acc) => AccountEntry::Cached(acc.clone_all()),
Expand All @@ -81,9 +81,24 @@ impl AccountEntry {
/// Representation of the entire state of all accounts in the system.
///
/// `State` can work together with `StateDB` to share account cache.
///
/// Local cache contains changes made locally and changes accumulated
/// locally from previous commits. Global cache reflects the database
/// state and never contains any changes.
///
/// Account data can be in the following cache states:
/// * In global but not local - something that was queried from the database,
/// but never modified
/// * In local but not global - something that was just added (e.g. new account)
/// * In both with the same value - something that was changed to a new value,
/// but changed back to a previous block in the same block (same State instance)
/// * In both with different values - something that was overwritten with a
/// new value.
///
/// All read-only state queries check local cache/modifications first,
/// then global state cache. If data is not found in any of the caches
/// it is loaded from the DB to the local cache.
///
/// Upon destruction all the local cache data merged into the global cache.
/// The merge might be rejected if current state is non-canonical.
pub struct State {
Expand Down Expand Up @@ -411,7 +426,7 @@ impl State {
},
AccountEntry::Missing => {
self.db.cache_account(address, None);
}
},
_ => {},
}
}
Expand Down Expand Up @@ -474,7 +489,7 @@ impl State {

fn update_account_cache(require: RequireCache, account: &mut Account, address: &Address, db: &HashDB) {
match require {
RequireCache::None => (),
RequireCache::None => {},
RequireCache::Code => {
let address_hash = account.address_hash(address);
account.cache_code(&AccountDB::from_hash(db, address_hash));
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use account::Account;
const STATE_CACHE_ITEMS: usize = 65536;

struct AccountCache {
/// DB Account cache. `None` indicates that account is known to be missing.
accounts: LruCache<Address, Option<Account>>,
}

Expand Down

0 comments on commit 7e34afa

Please sign in to comment.