From 26621042b39398eb22a81e8b7dd1d69f4428393c Mon Sep 17 00:00:00 2001 From: frisitano Date: Mon, 2 Dec 2024 14:20:56 +0800 Subject: [PATCH] add KeyHasher generic to DatabaseHashedStorage::from_reverts trait --- .../provider/src/providers/state/historical.rs | 8 +++++++- crates/trie/db/src/storage.rs | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index bbbf4b949ed0..cba511aad03b 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -156,7 +156,13 @@ impl<'b, Provider: DBProvider + BlockNumReader + StateCommitmentProvider> ); } - Ok(HashedStorage::from_reverts(self.tx(), address, self.block_number)?) + Ok( + HashedStorage::from_reverts::<::KeyHasher>( + self.tx(), + address, + self.block_number, + )?, + ) } fn history_info( diff --git a/crates/trie/db/src/storage.rs b/crates/trie/db/src/storage.rs index 6a3bbe1b9651..c2aa04ee98ad 100644 --- a/crates/trie/db/src/storage.rs +++ b/crates/trie/db/src/storage.rs @@ -6,7 +6,8 @@ use reth_db::{cursor::DbCursorRO, models::BlockNumberAddress, tables, DatabaseEr use reth_db_api::transaction::DbTx; use reth_execution_errors::StorageRootError; use reth_trie::{ - hashed_cursor::HashedPostStateCursorFactory, HashedPostState, HashedStorage, StorageRoot, + hashed_cursor::HashedPostStateCursorFactory, HashedPostState, HashedStorage, KeyHasher, + StorageRoot, }; #[cfg(feature = "metrics")] @@ -32,7 +33,11 @@ pub trait DatabaseStorageRoot<'a, TX> { pub trait DatabaseHashedStorage: Sized { /// Initializes [`HashedStorage`] from reverts. Iterates over storage reverts from the specified /// block up to the current tip and aggregates them into hashed storage in reverse. - fn from_reverts(tx: &TX, address: Address, from: BlockNumber) -> Result; + fn from_reverts( + tx: &TX, + address: Address, + from: BlockNumber, + ) -> Result; } impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX> @@ -79,13 +84,17 @@ impl<'a, TX: DbTx> DatabaseStorageRoot<'a, TX> } impl DatabaseHashedStorage for HashedStorage { - fn from_reverts(tx: &TX, address: Address, from: BlockNumber) -> Result { + fn from_reverts( + tx: &TX, + address: Address, + from: BlockNumber, + ) -> Result { let mut storage = Self::new(false); let mut storage_changesets_cursor = tx.cursor_read::()?; for entry in storage_changesets_cursor.walk_range(BlockNumberAddress((from, address))..)? { let (BlockNumberAddress((_, storage_address)), storage_change) = entry?; if storage_address == address { - let hashed_slot = keccak256(storage_change.key); + let hashed_slot = KH::hash_key(storage_change.key); if let hash_map::Entry::Vacant(entry) = storage.storage.entry(hashed_slot) { entry.insert(storage_change.value); }