Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(trie): small refactor in HashedPostState::from_reverts #12319

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions crates/trie/db/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ use reth_db_api::{
transaction::DbTx,
};
use reth_execution_errors::StateRootError;
use reth_primitives::Account;
use reth_storage_errors::db::DatabaseError;
use reth_trie::{
hashed_cursor::HashedPostStateCursorFactory, trie_cursor::InMemoryTrieCursorFactory,
updates::TrieUpdates, HashedPostState, HashedStorage, StateRoot, StateRootProgress, TrieInput,
};
use std::{
collections::{hash_map, HashMap},
ops::RangeInclusive,
};
use std::{collections::HashMap, ops::RangeInclusive};
use tracing::debug;

/// Extends [`StateRoot`] with operations specific for working with a database transaction.
Expand Down Expand Up @@ -222,13 +218,11 @@ impl<'a, TX: DbTx> DatabaseStateRoot<'a, TX>
impl<TX: DbTx> DatabaseHashedPostState<TX> for HashedPostState {
fn from_reverts(tx: &TX, from: BlockNumber) -> Result<Self, DatabaseError> {
// Iterate over account changesets and record value before first occurring account change.
let mut accounts = HashMap::<Address, Option<Account>>::default();
let mut accounts = HashMap::new();
mattsse marked this conversation as resolved.
Show resolved Hide resolved
let mut account_changesets_cursor = tx.cursor_read::<tables::AccountChangeSets>()?;
for entry in account_changesets_cursor.walk_range(from..)? {
let (_, AccountBeforeTx { address, info }) = entry?;
if let hash_map::Entry::Vacant(entry) = accounts.entry(address) {
entry.insert(info);
}
accounts.entry(address).or_insert(info);
}

// Iterate over storage changesets and record value before first occurring storage change.
Expand All @@ -239,9 +233,7 @@ impl<TX: DbTx> DatabaseHashedPostState<TX> for HashedPostState {
{
let (BlockNumberAddress((_, address)), storage) = entry?;
let account_storage = storages.entry(address).or_default();
if let hash_map::Entry::Vacant(entry) = account_storage.entry(storage.key) {
entry.insert(storage.value);
}
account_storage.entry(storage.key).or_insert(storage.value);
}

let hashed_accounts =
Expand Down
Loading