diff --git a/Cargo.toml b/Cargo.toml index e834963e9109..3ae4dbe44ab6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -433,11 +433,11 @@ revm-inspectors = "0.15.0" # eth alloy-chains = { version = "0.1.32", default-features = false } -alloy-dyn-abi = "0.8.15" +alloy-dyn-abi = "0.8.20" alloy-eip2124 = { version = "0.1.0", default-features = false } -alloy-primitives = { version = "0.8.15", default-features = false, features = ["map-foldhash"] } +alloy-primitives = { version = "0.8.20", default-features = false, features = ["map-foldhash"] } alloy-rlp = { version = "0.3.10", default-features = false } -alloy-sol-types = "0.8.15" +alloy-sol-types = "0.8.20" alloy-trie = { version = "0.7", default-features = false } alloy-consensus = { version = "0.11.1", default-features = false } diff --git a/book/sources/exex/tracking-state/Cargo.toml b/book/sources/exex/tracking-state/Cargo.toml index 85f360d9d74b..1fc940214c1c 100644 --- a/book/sources/exex/tracking-state/Cargo.toml +++ b/book/sources/exex/tracking-state/Cargo.toml @@ -11,4 +11,4 @@ reth-tracing = { git = "https://github.com/paradigmxyz/reth.git" } eyre = "0.6" # Easy error handling futures-util = "0.3" # Stream utilities for consuming notifications -alloy-primitives = "0.8.7" +alloy-primitives = "0.8.20" diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index ae32d65f85d7..90be2c0659fd 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -944,9 +944,7 @@ mod tests { use super::*; use crate::test_utils::TestBlockBuilder; use alloy_eips::eip7685::Requests; - use alloy_primitives::{ - map::B256HashMap, Address, BlockNumber, Bytes, StorageKey, StorageValue, - }; + use alloy_primitives::{map::B256Map, Address, BlockNumber, Bytes, StorageKey, StorageValue}; use rand::Rng; use reth_errors::ProviderResult; use reth_primitives::{Account, Bytecode, EthPrimitives, Receipt}; @@ -1106,7 +1104,7 @@ mod tests { &self, _input: TrieInput, _target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { Ok(HashMap::default()) } } diff --git a/crates/chain-state/src/memory_overlay.rs b/crates/chain-state/src/memory_overlay.rs index 38c384dcdb5c..01b4c0e2339c 100644 --- a/crates/chain-state/src/memory_overlay.rs +++ b/crates/chain-state/src/memory_overlay.rs @@ -1,7 +1,7 @@ use super::ExecutedBlockWithTrieUpdates; use alloy_consensus::BlockHeader; use alloy_primitives::{ - keccak256, map::B256HashMap, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256, + keccak256, map::B256Map, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256, }; use reth_errors::ProviderResult; use reth_primitives::{Account, Bytecode, NodePrimitives}; @@ -203,7 +203,7 @@ impl StateProofProvider for MemoryOverlayStateProviderRef<'_, &self, mut input: TrieInput, target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { let MemoryOverlayTrieState { nodes, state } = self.trie_state().clone(); input.prepend_cached(nodes, state); self.historical.witness(input, target) diff --git a/crates/engine/tree/src/tree/cached_state.rs b/crates/engine/tree/src/tree/cached_state.rs index 6e524e4ec8f1..525f163cd199 100644 --- a/crates/engine/tree/src/tree/cached_state.rs +++ b/crates/engine/tree/src/tree/cached_state.rs @@ -1,5 +1,5 @@ //! Implements a state provider that has a shared cache in front of it. -use alloy_primitives::{map::B256HashMap, Address, StorageKey, StorageValue, B256}; +use alloy_primitives::{map::B256Map, Address, StorageKey, StorageValue, B256}; use metrics::Gauge; use mini_moka::sync::CacheBuilder; use reth_errors::ProviderResult; @@ -273,7 +273,7 @@ impl StateProofProvider for CachedStateProvider { &self, input: TrieInput, target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { self.state_provider.witness(input, target) } } diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index b40fbd0d7f48..de4b3509303c 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -1,7 +1,7 @@ use alloc::vec::Vec; use alloy_primitives::{ keccak256, - map::{B256HashMap, HashMap}, + map::{B256Map, HashMap}, Address, BlockNumber, Bytes, StorageKey, B256, U256, }; use reth_primitives_traits::{Account, Bytecode}; @@ -145,7 +145,7 @@ impl StateProofProvider for StateProviderTest { &self, _input: TrieInput, _target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { unimplemented!("witness generation is not supported") } } diff --git a/crates/revm/src/witness.rs b/crates/revm/src/witness.rs index 6140de9d48ad..0df5751eedd6 100644 --- a/crates/revm/src/witness.rs +++ b/crates/revm/src/witness.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{keccak256, map::B256HashMap, Bytes, B256}; +use alloy_primitives::{keccak256, map::B256Map, Bytes, B256}; use reth_trie::{HashedPostState, HashedStorage}; use revm::State; @@ -11,13 +11,13 @@ pub struct ExecutionWitnessRecord { /// the execution of the block, including during state root recomputation. /// /// `keccak(bytecodes) => bytecodes` - pub codes: B256HashMap, + pub codes: B256Map, /// Map of all hashed account and storage keys (addresses and slots) to their preimages /// (unhashed account addresses and storage slots, respectively) that were required during /// the execution of the block. during the execution of the block. /// /// `keccak(address|slot) => address|slot` - pub keys: B256HashMap, + pub keys: B256Map, } impl ExecutionWitnessRecord { diff --git a/crates/rpc/rpc-eth-types/src/cache/db.rs b/crates/rpc/rpc-eth-types/src/cache/db.rs index dd15f7602179..e61e69eac368 100644 --- a/crates/rpc/rpc-eth-types/src/cache/db.rs +++ b/crates/rpc/rpc-eth-types/src/cache/db.rs @@ -97,8 +97,7 @@ impl reth_storage_api::StateProofProvider for StateProviderTraitObjWrapper<'_> { &self, input: reth_trie::TrieInput, target: reth_trie::HashedPostState, - ) -> reth_errors::ProviderResult> - { + ) -> reth_errors::ProviderResult> { self.0.witness(input, target) } } diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 316e6f64a326..36a1f2fbe8d7 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -1,7 +1,7 @@ use crate::{ AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider, }; -use alloy_primitives::{map::B256HashMap, Address, BlockNumber, Bytes, B256}; +use alloy_primitives::{map::B256Map, Address, BlockNumber, Bytes, B256}; use reth_primitives::{Account, Bytecode}; use reth_storage_api::{HashedPostStateProvider, StateProofProvider, StorageRootProvider}; use reth_storage_errors::provider::ProviderResult; @@ -177,7 +177,7 @@ impl StateProofProvider &self, mut input: TrieInput, target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { let bundle_state = self.block_execution_data_provider.execution_outcome().state(); input.prepend(self.hashed_post_state(bundle_state)); self.state_provider.witness(input, target) diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index ac3ea42e1091..ce2b29eba9bb 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -23,7 +23,7 @@ use alloy_consensus::{transaction::TransactionMeta, BlockHeader, Header, TxRecei use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals, BlockHashOrNumber}; use alloy_primitives::{ keccak256, - map::{hash_map, B256HashMap, HashMap, HashSet}, + map::{hash_map, B256Map, HashMap, HashSet}, Address, BlockHash, BlockNumber, TxHash, TxNumber, B256, U256, }; use itertools::Itertools; @@ -291,7 +291,7 @@ impl DatabaseProvider::default(); + let mut storage_prefix_sets = B256Map::::default(); let storage_entries = self.unwind_storage_hashing(changed_storages.iter().copied())?; for (hashed_address, hashed_slots) in storage_entries { account_prefix_set.insert(Nibbles::unpack(hashed_address)); @@ -2351,7 +2351,7 @@ impl StorageTrieWriter for DatabaseP /// updates by the hashed address, writing in sorted order. fn write_storage_trie_updates( &self, - storage_tries: &B256HashMap, + storage_tries: &B256Map, ) -> ProviderResult { let mut num_entries = 0; let mut storage_tries = Vec::from_iter(storage_tries); diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 64a8570499c7..6a7a49288839 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -3,9 +3,7 @@ use crate::{ HashedPostStateProvider, ProviderError, StateProvider, StateRootProvider, }; use alloy_eips::merge::EPOCH_SLOTS; -use alloy_primitives::{ - map::B256HashMap, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256, -}; +use alloy_primitives::{map::B256Map, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256}; use reth_db::{tables, BlockNumberList}; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRO}, @@ -388,7 +386,7 @@ impl StateProof &self, mut input: TrieInput, target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { input.prepend(self.revert_state()?); TrieWitness::overlay_witness(self.tx(), input, target).map_err(ProviderError::from) } diff --git a/crates/storage/provider/src/providers/state/latest.rs b/crates/storage/provider/src/providers/state/latest.rs index 46bd8db426fe..6a2857e50347 100644 --- a/crates/storage/provider/src/providers/state/latest.rs +++ b/crates/storage/provider/src/providers/state/latest.rs @@ -2,9 +2,7 @@ use crate::{ providers::state::macros::delegate_provider_impls, AccountReader, BlockHashReader, HashedPostStateProvider, StateProvider, StateRootProvider, }; -use alloy_primitives::{ - map::B256HashMap, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256, -}; +use alloy_primitives::{map::B256Map, Address, BlockNumber, Bytes, StorageKey, StorageValue, B256}; use reth_db::tables; use reth_db_api::{cursor::DbDupCursorRO, transaction::DbTx}; use reth_primitives::{Account, Bytecode}; @@ -146,11 +144,7 @@ impl StateProofProvider Proof::overlay_multiproof(self.tx(), input, targets).map_err(ProviderError::from) } - fn witness( - &self, - input: TrieInput, - target: HashedPostState, - ) -> ProviderResult> { + fn witness(&self, input: TrieInput, target: HashedPostState) -> ProviderResult> { TrieWitness::overlay_witness(self.tx(), input, target).map_err(ProviderError::from) } } diff --git a/crates/storage/provider/src/providers/state/macros.rs b/crates/storage/provider/src/providers/state/macros.rs index d97a5fa7b9d0..bc96f3ad02ae 100644 --- a/crates/storage/provider/src/providers/state/macros.rs +++ b/crates/storage/provider/src/providers/state/macros.rs @@ -55,7 +55,7 @@ macro_rules! delegate_provider_impls { StateProofProvider $(where [$($generics)*])? { fn proof(&self, input: reth_trie::TrieInput, address: alloy_primitives::Address, slots: &[alloy_primitives::B256]) -> reth_storage_errors::provider::ProviderResult; fn multiproof(&self, input: reth_trie::TrieInput, targets: reth_trie::MultiProofTargets) -> reth_storage_errors::provider::ProviderResult; - fn witness(&self, input: reth_trie::TrieInput, target: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult>; + fn witness(&self, input: reth_trie::TrieInput, target: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult>; } HashedPostStateProvider $(where [$($generics)*])? { fn hashed_post_state(&self, bundle_state: &revm::db::BundleState) -> reth_trie::HashedPostState; diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 47e54dfcaf15..c7130706da37 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -11,7 +11,7 @@ use alloy_consensus::{ use alloy_eips::{eip4895::Withdrawals, BlockHashOrNumber, BlockId, BlockNumberOrTag}; use alloy_primitives::{ keccak256, - map::{B256HashMap, HashMap}, + map::{B256Map, HashMap}, Address, BlockHash, BlockNumber, Bytes, StorageKey, StorageValue, TxHash, TxNumber, B256, U256, }; use parking_lot::Mutex; @@ -724,7 +724,7 @@ impl StateProofProvider for MockEthProv &self, _input: TrieInput, _target: HashedPostState, - ) -> ProviderResult> { + ) -> ProviderResult> { Ok(HashMap::default()) } } diff --git a/crates/storage/storage-api/src/noop.rs b/crates/storage/storage-api/src/noop.rs index a16b49e73a64..e3321dfb4a6b 100644 --- a/crates/storage/storage-api/src/noop.rs +++ b/crates/storage/storage-api/src/noop.rs @@ -12,7 +12,7 @@ use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; use alloy_consensus::transaction::TransactionMeta; use alloy_eips::{eip4895::Withdrawals, BlockHashOrNumber, BlockId, BlockNumberOrTag}; use alloy_primitives::{ - map::{B256HashMap, HashMap}, + map::{B256Map, HashMap}, Address, BlockHash, BlockNumber, Bytes, StorageKey, StorageValue, TxHash, TxNumber, B256, U256, }; use core::{ @@ -439,7 +439,7 @@ impl StateProofProvider for NoopProvider ProviderResult> { + ) -> ProviderResult> { Ok(HashMap::default()) } } diff --git a/crates/storage/storage-api/src/trie.rs b/crates/storage/storage-api/src/trie.rs index fbd57a97e46e..5378beffd4af 100644 --- a/crates/storage/storage-api/src/trie.rs +++ b/crates/storage/storage-api/src/trie.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{map::B256HashMap, Address, Bytes, B256}; +use alloy_primitives::{map::B256Map, Address, Bytes, B256}; use reth_storage_errors::provider::ProviderResult; use reth_trie::{ updates::{StorageTrieUpdates, TrieUpdates}, @@ -85,11 +85,7 @@ pub trait StateProofProvider: Send + Sync { ) -> ProviderResult; /// Get trie witness for provided state. - fn witness( - &self, - input: TrieInput, - target: HashedPostState, - ) -> ProviderResult>; + fn witness(&self, input: TrieInput, target: HashedPostState) -> ProviderResult>; } /// Trie Writer @@ -111,7 +107,7 @@ pub trait StorageTrieWriter: Send + Sync { /// Returns the number of entries modified. fn write_storage_trie_updates( &self, - storage_tries: &B256HashMap, + storage_tries: &B256Map, ) -> ProviderResult; /// Writes storage trie updates for the given hashed address. diff --git a/crates/trie/common/src/hashedstate.rs b/crates/trie/common/src/hashedstate.rs index 120bfdbbafe0..38feb0dd3b1b 100644 --- a/crates/trie/common/src/hashedstate.rs +++ b/crates/trie/common/src/hashedstate.rs @@ -5,7 +5,7 @@ use crate::{ use alloc::{borrow::Cow, vec::Vec}; use alloy_primitives::{ keccak256, - map::{hash_map, B256HashMap, B256HashSet, HashMap, HashSet}, + map::{hash_map, B256Map, B256Set, HashMap, HashSet}, Address, B256, U256, }; use itertools::Itertools; @@ -22,9 +22,9 @@ use rayon::prelude::{IntoParallelIterator, ParallelIterator}; #[derive(PartialEq, Eq, Clone, Default, Debug)] pub struct HashedPostState { /// Mapping of hashed address to account info, `None` if destroyed. - pub accounts: B256HashMap>, + pub accounts: B256Map>, /// Mapping of hashed address to hashed storage. - pub storages: B256HashMap, + pub storages: B256Map, } impl HashedPostState { @@ -222,7 +222,7 @@ pub struct HashedStorage { /// Flag indicating whether the storage was wiped or not. pub wiped: bool, /// Mapping of hashed storage slot to storage value. - pub storage: B256HashMap, + pub storage: B256Map, } impl HashedStorage { @@ -298,14 +298,14 @@ pub struct HashedPostStateSorted { /// Updated state of accounts. pub accounts: HashedAccountsSorted, /// Map of hashed addresses to hashed storage. - pub storages: B256HashMap, + pub storages: B256Map, } impl HashedPostStateSorted { /// Create new instance of [`HashedPostStateSorted`] pub const fn new( accounts: HashedAccountsSorted, - storages: B256HashMap, + storages: B256Map, ) -> Self { Self { accounts, storages } } @@ -316,7 +316,7 @@ impl HashedPostStateSorted { } /// Returns reference to hashed account storages. - pub const fn account_storages(&self) -> &B256HashMap { + pub const fn account_storages(&self) -> &B256Map { &self.storages } } @@ -327,7 +327,7 @@ pub struct HashedAccountsSorted { /// Sorted collection of hashed addresses and their account info. pub accounts: Vec<(B256, Account)>, /// Set of destroyed account keys. - pub destroyed_accounts: B256HashSet, + pub destroyed_accounts: B256Set, } impl HashedAccountsSorted { @@ -347,7 +347,7 @@ pub struct HashedStorageSorted { /// Sorted hashed storage slots with non-zero value. pub non_zero_valued_slots: Vec<(B256, U256)>, /// Slots that have been zero valued. - pub zero_valued_slots: B256HashSet, + pub zero_valued_slots: B256Set, /// Flag indicating whether the storage was wiped or not. pub wiped: bool, } diff --git a/crates/trie/common/src/prefix_set.rs b/crates/trie/common/src/prefix_set.rs index 7c6a2c3a717e..e4f97dafdb1d 100644 --- a/crates/trie/common/src/prefix_set.rs +++ b/crates/trie/common/src/prefix_set.rs @@ -1,6 +1,6 @@ use crate::Nibbles; use alloc::{sync::Arc, vec::Vec}; -use alloy_primitives::map::{B256HashMap, B256HashSet}; +use alloy_primitives::map::{B256Map, B256Set}; /// Collection of mutable prefix sets. #[derive(Clone, Default, Debug)] @@ -9,9 +9,9 @@ pub struct TriePrefixSetsMut { pub account_prefix_set: PrefixSetMut, /// A map containing storage changes with the hashed address as key and a set of storage key /// prefixes as the value. - pub storage_prefix_sets: B256HashMap, + pub storage_prefix_sets: B256Map, /// A set of hashed addresses of destroyed accounts. - pub destroyed_accounts: B256HashSet, + pub destroyed_accounts: B256Set, } impl TriePrefixSetsMut { @@ -47,9 +47,9 @@ pub struct TriePrefixSets { pub account_prefix_set: PrefixSet, /// A map containing storage changes with the hashed address as key and a set of storage key /// prefixes as the value. - pub storage_prefix_sets: B256HashMap, + pub storage_prefix_sets: B256Map, /// A set of hashed addresses of destroyed accounts. - pub destroyed_accounts: B256HashSet, + pub destroyed_accounts: B256Set, } /// A container for efficiently storing and checking for the presence of key prefixes. diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index 9fae40beaa0c..62d76debdee5 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -5,7 +5,7 @@ use alloc::vec::Vec; use alloy_consensus::constants::KECCAK_EMPTY; use alloy_primitives::{ keccak256, - map::{hash_map, B256HashMap, B256HashSet, HashMap}, + map::{hash_map, B256Map, B256Set, HashMap}, Address, Bytes, B256, U256, }; use alloy_rlp::{encode_fixed_size, Decodable, EMPTY_STRING_CODE}; @@ -18,7 +18,7 @@ use itertools::Itertools; use reth_primitives_traits::Account; /// Proof targets map. -pub type MultiProofTargets = B256HashMap; +pub type MultiProofTargets = B256Map; /// The state multiproof of target accounts and multiproofs of their storage tries. /// Multiproof is effectively a state subtrie that only contains the nodes @@ -32,7 +32,7 @@ pub struct MultiProof { /// The tree masks of the branch nodes in the account proof. pub branch_node_tree_masks: HashMap, /// Storage trie multiproofs. - pub storages: B256HashMap, + pub storages: B256Map, } impl MultiProof { diff --git a/crates/trie/common/src/updates.rs b/crates/trie/common/src/updates.rs index c98d26f60ce8..f7506df9a295 100644 --- a/crates/trie/common/src/updates.rs +++ b/crates/trie/common/src/updates.rs @@ -1,7 +1,7 @@ use crate::{BranchNodeCompact, HashBuilder, Nibbles}; use alloc::vec::Vec; use alloy_primitives::{ - map::{B256HashMap, B256HashSet, HashMap, HashSet}, + map::{B256Map, B256Set, HashMap, HashSet}, B256, }; @@ -16,7 +16,7 @@ pub struct TrieUpdates { #[cfg_attr(any(test, feature = "serde"), serde(with = "serde_nibbles_set"))] pub removed_nodes: HashSet, /// Collection of updated storage tries indexed by the hashed address. - pub storage_tries: B256HashMap, + pub storage_tries: B256Map, } impl TrieUpdates { @@ -38,7 +38,7 @@ impl TrieUpdates { } /// Returns a reference to updated storage tries. - pub const fn storage_tries_ref(&self) -> &B256HashMap { + pub const fn storage_tries_ref(&self) -> &B256Map { &self.storage_tries } @@ -88,7 +88,7 @@ impl TrieUpdates { &mut self, hash_builder: HashBuilder, removed_keys: HashSet, - destroyed_accounts: B256HashSet, + destroyed_accounts: B256Set, ) { // Retrieve updated nodes from hash builder. let (_, updated_nodes) = hash_builder.split(); @@ -359,7 +359,7 @@ pub struct TrieUpdatesSorted { pub removed_nodes: HashSet, /// Storage tries storage stored by hashed address of the account /// the trie belongs to. - pub storage_tries: B256HashMap, + pub storage_tries: B256Map, } impl TrieUpdatesSorted { @@ -374,7 +374,7 @@ impl TrieUpdatesSorted { } /// Returns reference to updated storage tries. - pub const fn storage_tries_ref(&self) -> &B256HashMap { + pub const fn storage_tries_ref(&self) -> &B256Map { &self.storage_tries } } @@ -424,7 +424,7 @@ fn exclude_empty_from_pair( pub mod serde_bincode_compat { use crate::{BranchNodeCompact, Nibbles}; use alloc::borrow::Cow; - use alloy_primitives::map::{B256HashMap, HashMap, HashSet}; + use alloy_primitives::map::{B256Map, HashMap, HashSet}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; @@ -447,7 +447,7 @@ pub mod serde_bincode_compat { pub struct TrieUpdates<'a> { account_nodes: Cow<'a, HashMap>, removed_nodes: Cow<'a, HashSet>, - storage_tries: B256HashMap>, + storage_tries: B256Map>, } impl<'a> From<&'a super::TrieUpdates> for TrieUpdates<'a> { diff --git a/crates/trie/db/src/state.rs b/crates/trie/db/src/state.rs index d9691d702d83..8d9bf029a1e7 100644 --- a/crates/trie/db/src/state.rs +++ b/crates/trie/db/src/state.rs @@ -1,6 +1,6 @@ use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory, PrefixSetLoader}; use alloy_primitives::{ - map::{AddressHashMap, B256HashMap}, + map::{AddressMap, B256Map}, Address, BlockNumber, B256, U256, }; use reth_db::tables; @@ -230,7 +230,7 @@ impl DatabaseHashedPostState for HashedPostState { } // Iterate over storage changesets and record value before first occurring storage change. - let mut storages = AddressHashMap::>::default(); + let mut storages = AddressMap::>::default(); let mut storage_changesets_cursor = tx.cursor_read::()?; for entry in storage_changesets_cursor.walk_range(BlockNumberAddress((from, Address::ZERO))..)? diff --git a/crates/trie/db/src/witness.rs b/crates/trie/db/src/witness.rs index c796933b90ed..a240734f8ce3 100644 --- a/crates/trie/db/src/witness.rs +++ b/crates/trie/db/src/witness.rs @@ -1,5 +1,5 @@ use crate::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory}; -use alloy_primitives::{map::B256HashMap, Bytes}; +use alloy_primitives::{map::B256Map, Bytes}; use reth_db_api::transaction::DbTx; use reth_execution_errors::TrieWitnessError; use reth_trie::{ @@ -17,7 +17,7 @@ pub trait DatabaseTrieWitness<'a, TX> { tx: &'a TX, input: TrieInput, target: HashedPostState, - ) -> Result, TrieWitnessError>; + ) -> Result, TrieWitnessError>; } impl<'a, TX: DbTx> DatabaseTrieWitness<'a, TX> @@ -31,7 +31,7 @@ impl<'a, TX: DbTx> DatabaseTrieWitness<'a, TX> tx: &'a TX, input: TrieInput, target: HashedPostState, - ) -> Result, TrieWitnessError> { + ) -> Result, TrieWitnessError> { let nodes_sorted = input.nodes.into_sorted(); let state_sorted = input.state.into_sorted(); Self::from_tx(tx) diff --git a/crates/trie/parallel/src/proof.rs b/crates/trie/parallel/src/proof.rs index 580cdf05bb76..29cc15f0a2f8 100644 --- a/crates/trie/parallel/src/proof.rs +++ b/crates/trie/parallel/src/proof.rs @@ -1,6 +1,6 @@ use crate::{root::ParallelStateRootError, stats::ParallelTrieTracker, StorageRootTargets}; use alloy_primitives::{ - map::{B256HashMap, HashMap}, + map::{B256Map, HashMap}, B256, }; use alloy_rlp::{BufMut, Encodable}; @@ -119,7 +119,7 @@ where tracker.set_precomputed_storage_roots(storage_root_targets_len as u64); let mut storage_proofs = - B256HashMap::with_capacity_and_hasher(storage_root_targets.len(), Default::default()); + B256Map::with_capacity_and_hasher(storage_root_targets.len(), Default::default()); for (hashed_address, prefix_set) in storage_root_targets.into_iter().sorted_unstable_by_key(|(address, _)| *address) @@ -231,7 +231,7 @@ where // Initialize all storage multiproofs as empty. // Storage multiproofs for non empty tries will be overwritten if necessary. - let mut storages: B256HashMap<_> = + let mut storages: B256Map<_> = targets.keys().map(|key| (*key, StorageMultiProof::empty())).collect(); let mut account_rlp = Vec::with_capacity(TRIE_ACCOUNT_RLP_MAX_SIZE); let mut account_node_iter = TrieNodeIter::new( @@ -317,7 +317,7 @@ mod tests { use super::*; use alloy_primitives::{ keccak256, - map::{B256HashSet, DefaultHashBuilder}, + map::{B256Set, DefaultHashBuilder}, Address, U256, }; use rand::Rng; @@ -373,7 +373,7 @@ mod tests { let mut targets = MultiProofTargets::default(); for (address, (_, storage)) in state.iter().take(10) { let hashed_address = keccak256(*address); - let mut target_slots = B256HashSet::default(); + let mut target_slots = B256Set::default(); for (slot, _) in storage.iter().take(5) { target_slots.insert(*slot); diff --git a/crates/trie/parallel/src/storage_root_targets.rs b/crates/trie/parallel/src/storage_root_targets.rs index b02467b94a00..f844b70fca54 100644 --- a/crates/trie/parallel/src/storage_root_targets.rs +++ b/crates/trie/parallel/src/storage_root_targets.rs @@ -1,10 +1,10 @@ -use alloy_primitives::{map::B256HashMap, B256}; +use alloy_primitives::{map::B256Map, B256}; use derive_more::{Deref, DerefMut}; use reth_trie::prefix_set::PrefixSet; /// Target accounts with corresponding prefix sets for storage root calculation. #[derive(Deref, DerefMut, Debug)] -pub struct StorageRootTargets(B256HashMap); +pub struct StorageRootTargets(B256Map); impl StorageRootTargets { /// Create new storage root targets from updated post state accounts diff --git a/crates/trie/sparse/benches/root.rs b/crates/trie/sparse/benches/root.rs index e01f9825d8ee..95e401630a1d 100644 --- a/crates/trie/sparse/benches/root.rs +++ b/crates/trie/sparse/benches/root.rs @@ -1,6 +1,6 @@ #![allow(missing_docs)] -use alloy_primitives::{map::B256HashMap, B256, U256}; +use alloy_primitives::{map::B256Map, B256, U256}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use itertools::Itertools; use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner}; @@ -215,7 +215,7 @@ fn calculate_root_from_leaves_repeated(c: &mut Criterion) { } } -fn generate_test_data(size: usize) -> B256HashMap { +fn generate_test_data(size: usize) -> B256Map { let mut runner = TestRunner::deterministic(); proptest::collection::hash_map(any::(), any::(), size) .new_tree(&mut runner) diff --git a/crates/trie/sparse/src/state.rs b/crates/trie/sparse/src/state.rs index cec4c04bb386..ff2d4c553dce 100644 --- a/crates/trie/sparse/src/state.rs +++ b/crates/trie/sparse/src/state.rs @@ -4,7 +4,7 @@ use crate::{ }; use alloy_primitives::{ hex, - map::{B256HashMap, HashSet}, + map::{B256Map, HashSet}, Bytes, B256, }; use alloy_rlp::{Decodable, Encodable}; @@ -25,11 +25,11 @@ pub struct SparseStateTrie, /// Sparse storage tries. - storages: B256HashMap>, + storages: B256Map>, /// Collection of revealed account trie paths. revealed_account_paths: HashSet, /// Collection of revealed storage trie paths, per account. - revealed_storage_paths: B256HashMap>, + revealed_storage_paths: B256Map>, /// Flag indicating whether trie updates should be retained. retain_updates: bool, /// Reusable buffer for RLP encoding of trie accounts. @@ -331,7 +331,7 @@ impl SparseStateTrie { pub fn reveal_witness( &mut self, state_root: B256, - witness: &B256HashMap, + witness: &B256Map, ) -> SparseStateTrieResult<()> { // Create a `(hash, path, maybe_account)` queue for traversing witness trie nodes // starting from the root node. @@ -498,7 +498,7 @@ impl SparseStateTrie { /// Returns storage trie updates for tries that have been revealed. /// /// Panics if any of the storage tries are not revealed. - pub fn storage_trie_updates(&mut self) -> B256HashMap { + pub fn storage_trie_updates(&mut self) -> B256Map { self.storages .iter_mut() .map(|(address, trie)| { diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index 948eebb61359..4636c15c9d86 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -1507,7 +1507,7 @@ impl SparseTrieUpdates { #[cfg(test)] mod tests { use super::*; - use alloy_primitives::{map::B256HashSet, U256}; + use alloy_primitives::{map::B256Set, U256}; use alloy_rlp::Encodable; use assert_matches::assert_matches; use itertools::Itertools; @@ -1553,7 +1553,7 @@ mod tests { fn run_hash_builder( state: impl IntoIterator + Clone, trie_cursor: impl TrieCursor, - destroyed_accounts: B256HashSet, + destroyed_accounts: B256Set, proof_targets: impl IntoIterator, ) -> (B256, TrieUpdates, ProofNodes, HashMap, HashMap) { diff --git a/crates/trie/trie/src/hashed_cursor/post_state.rs b/crates/trie/trie/src/hashed_cursor/post_state.rs index 18e58fdba40c..31e760e8c03c 100644 --- a/crates/trie/trie/src/hashed_cursor/post_state.rs +++ b/crates/trie/trie/src/hashed_cursor/post_state.rs @@ -1,6 +1,6 @@ use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor}; use crate::forward_cursor::ForwardInMemoryCursor; -use alloy_primitives::{map::B256HashSet, B256, U256}; +use alloy_primitives::{map::B256Set, B256, U256}; use reth_primitives_traits::Account; use reth_storage_errors::db::DatabaseError; use reth_trie_common::{HashedAccountsSorted, HashedPostStateSorted, HashedStorageSorted}; @@ -46,7 +46,7 @@ pub struct HashedPostStateAccountCursor<'a, C> { /// Forward-only in-memory cursor over accounts. post_state_cursor: ForwardInMemoryCursor<'a, B256, Account>, /// Reference to the collection of account keys that were destroyed. - destroyed_accounts: &'a B256HashSet, + destroyed_accounts: &'a B256Set, /// The last hashed account that was returned by the cursor. /// De facto, this is a current cursor position. last_account: Option, @@ -180,7 +180,7 @@ pub struct HashedPostStateStorageCursor<'a, C> { /// Forward-only in-memory cursor over non zero-valued account storage slots. post_state_cursor: Option>, /// Reference to the collection of storage slot keys that were cleared. - cleared_slots: Option<&'a B256HashSet>, + cleared_slots: Option<&'a B256Set>, /// Flag indicating whether database storage was wiped. storage_wiped: bool, /// The last slot that has been returned by the cursor. diff --git a/crates/trie/trie/src/proof/mod.rs b/crates/trie/trie/src/proof/mod.rs index 5c632b5cecaa..6ffcf67cd204 100644 --- a/crates/trie/trie/src/proof/mod.rs +++ b/crates/trie/trie/src/proof/mod.rs @@ -8,7 +8,7 @@ use crate::{ }; use alloy_primitives::{ keccak256, - map::{B256HashMap, B256HashSet, HashMap, HashSet}, + map::{B256Map, B256Set, HashMap, HashSet}, Address, B256, }; use alloy_rlp::{BufMut, Encodable}; @@ -121,7 +121,7 @@ where // Initialize all storage multiproofs as empty. // Storage multiproofs for non empty tries will be overwritten if necessary. - let mut storages: B256HashMap<_> = + let mut storages: B256Map<_> = targets.keys().map(|key| (*key, StorageMultiProof::empty())).collect(); let mut account_rlp = Vec::with_capacity(TRIE_ACCOUNT_RLP_MAX_SIZE); let mut account_node_iter = TrieNodeIter::new(walker, hashed_account_cursor); @@ -268,7 +268,7 @@ where /// Generate storage proof. pub fn storage_multiproof( mut self, - targets: B256HashSet, + targets: B256Set, ) -> Result { let mut hashed_storage_cursor = self.hashed_cursor_factory.hashed_storage_cursor(self.hashed_address)?; diff --git a/crates/trie/trie/src/witness.rs b/crates/trie/trie/src/witness.rs index 5b72747b8018..ebdd5ac562f2 100644 --- a/crates/trie/trie/src/witness.rs +++ b/crates/trie/trie/src/witness.rs @@ -8,7 +8,7 @@ use reth_trie_common::HashedPostState; use alloy_primitives::{ keccak256, - map::{B256HashMap, B256HashSet, Entry, HashMap}, + map::{B256Map, B256Set, Entry, HashMap}, Bytes, B256, }; use itertools::Itertools; @@ -33,7 +33,7 @@ pub struct TrieWitness { /// A set of prefix sets that have changes. prefix_sets: TriePrefixSetsMut, /// Recorded witness. - witness: B256HashMap, + witness: B256Map, } impl TrieWitness { @@ -85,10 +85,7 @@ where /// # Arguments /// /// `state` - state transition containing both modified and touched accounts and storage slots. - pub fn compute( - mut self, - state: HashedPostState, - ) -> Result, TrieWitnessError> { + pub fn compute(mut self, state: HashedPostState) -> Result, TrieWitnessError> { if state.is_empty() { return Ok(self.witness) } @@ -178,10 +175,10 @@ where ) -> Result { let mut proof_targets = MultiProofTargets::default(); for hashed_address in state.accounts.keys() { - proof_targets.insert(*hashed_address, B256HashSet::default()); + proof_targets.insert(*hashed_address, B256Set::default()); } for (hashed_address, storage) in &state.storages { - let mut storage_keys = storage.storage.keys().copied().collect::(); + let mut storage_keys = storage.storage.keys().copied().collect::(); if storage.wiped { // storage for this account was destroyed, gather all slots from the current state let mut storage_cursor =