diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 268f5c6d3..3782171ef 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -130,7 +130,7 @@ impl<'b, TX: DbTx> HistoricalStateProviderRef<'b, TX> { ); } - Ok(HashedPostState::from_revert_range(self.tx, self.block_number..=tip)?) + Ok(HashedPostState::from_reverts(self.tx, self.block_number)?) } fn history_info( diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index 6a37475eb..3d8616c97 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -17,10 +17,7 @@ use reth_execution_errors::StateRootError; use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256}; use reth_trie_common::AccountProof; use revm::db::BundleAccount; -use std::{ - collections::{hash_map, HashMap, HashSet}, - ops::RangeInclusive, -}; +use std::collections::{hash_map, HashMap, HashSet}; /// Representation of in-memory hashed state. #[derive(PartialEq, Eq, Clone, Default, Debug)] @@ -62,20 +59,13 @@ impl HashedPostState { Self { accounts, storages } } - /// Initialize [`HashedPostState`] from revert range. - /// Iterate over state reverts in the specified block range and - /// apply them to hashed state in reverse. - /// - /// NOTE: In order to have the resulting [`HashedPostState`] be a correct - /// overlay of the plain state, the end of the range must be the current tip. - pub fn from_revert_range( - tx: &TX, - range: RangeInclusive, - ) -> Result { + /// Initializes [`HashedPostState`] from reverts. Iterates over state reverts from the specified + /// block up to the current tip and aggregates them into hashed state in reverse. + pub fn from_reverts(tx: &TX, from: BlockNumber) -> Result { // Iterate over account changesets and record value before first occurring account change. let mut accounts = HashMap::>::default(); let mut account_changesets_cursor = tx.cursor_read::()?; - for entry in account_changesets_cursor.walk_range(range.clone())? { + 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); @@ -85,7 +75,9 @@ impl HashedPostState { // Iterate over storage changesets and record value before first occurring storage change. let mut storages = HashMap::>::default(); let mut storage_changesets_cursor = tx.cursor_read::()?; - for entry in storage_changesets_cursor.walk_range(BlockNumberAddress::range(range))? { + for entry in + storage_changesets_cursor.walk_range(BlockNumberAddress((from, Address::ZERO))..)? + { 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) {