Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Jun 25, 2024
1 parent 638bf25 commit 206c794
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/trie/trie/src/hashed_cursor/post_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct HashedPostStateAccountCursor<'b, C> {
/// The database cursor.
cursor: C,
/// The reference to the in-memory [`HashedAccountsSorted`].
post_state: &'b HashedAccountsSorted,
post_state_accounts: &'b HashedAccountsSorted,
/// The post state account index where the cursor is currently at.
post_state_account_index: usize,
/// The last hashed account that was returned by the cursor.
Expand All @@ -52,7 +52,12 @@ pub struct HashedPostStateAccountCursor<'b, C> {
impl<'b, C> HashedPostStateAccountCursor<'b, C> {
/// Create new instance of [`HashedPostStateAccountCursor`].
pub const fn new(cursor: C, post_state: &'b HashedAccountsSorted) -> Self {
Self { cursor, post_state, last_account: None, post_state_account_index: 0 }
Self {
cursor,
post_state_accounts: post_state,
last_account: None,
post_state_account_index: 0,
}
}

/// Returns `true` if the account has been destroyed.
Expand All @@ -61,7 +66,7 @@ impl<'b, C> HashedPostStateAccountCursor<'b, C> {
/// This function only checks the post state, not the database, because the latter does not
/// store destroyed accounts.
fn is_account_cleared(&self, account: &B256) -> bool {
self.post_state.destroyed_accounts.contains(account)
self.post_state_accounts.destroyed_accounts.contains(account)
}

/// Return the account with the lowest hashed account key.
Expand Down Expand Up @@ -107,10 +112,11 @@ where

// Take the next account from the post state with the key greater than or equal to the
// sought key.
let mut post_state_entry = self.post_state.accounts.get(self.post_state_account_index);
let mut post_state_entry =
self.post_state_accounts.accounts.get(self.post_state_account_index);
while post_state_entry.map(|(k, _)| k < &key).unwrap_or_default() {
self.post_state_account_index += 1;
post_state_entry = self.post_state.accounts.get(self.post_state_account_index);
post_state_entry = self.post_state_accounts.accounts.get(self.post_state_account_index);
}

// It's an exact match, return the account from post state without looking up in the
Expand Down Expand Up @@ -163,10 +169,11 @@ where
}

// Take the next account from the post state with the key greater than the last sought key.
let mut post_state_entry = self.post_state.accounts.get(self.post_state_account_index);
let mut post_state_entry =
self.post_state_accounts.accounts.get(self.post_state_account_index);
while post_state_entry.map(|(k, _)| k <= last_account).unwrap_or_default() {
self.post_state_account_index += 1;
post_state_entry = self.post_state.accounts.get(self.post_state_account_index);
post_state_entry = self.post_state_accounts.accounts.get(self.post_state_account_index);
}

// Compare two entries and return the lowest.
Expand Down

0 comments on commit 206c794

Please sign in to comment.