From 91d09de4401fbf1d0b14b31ea2145d7212345779 Mon Sep 17 00:00:00 2001 From: Akase Haruka Date: Sat, 4 Jan 2025 17:49:06 +0800 Subject: [PATCH] fix: no_std case hashmap imports (#13617) --- .../evm/execution-types/src/execution_outcome.rs | 3 +-- crates/optimism/evm/src/lib.rs | 11 ++++++----- crates/storage/db-common/src/init.rs | 14 ++++++++------ .../storage/provider/src/providers/consistent.rs | 14 ++++++++------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index 43c78a5d9c4f..f8401a6decb9 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -1,6 +1,6 @@ use crate::BlockExecutionOutput; use alloy_eips::eip7685::Requests; -use alloy_primitives::{logs_bloom, Address, BlockNumber, Bloom, Log, B256, U256}; +use alloy_primitives::{logs_bloom, map::HashMap, Address, BlockNumber, Bloom, Log, B256, U256}; use reth_primitives::Receipts; use reth_primitives_traits::{Account, Bytecode, Receipt, StorageEntry}; use reth_trie::{HashedPostState, KeyHasher}; @@ -8,7 +8,6 @@ use revm::{ db::{states::BundleState, BundleAccount}, primitives::AccountInfo, }; -use std::collections::HashMap; /// Represents a changed account #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index 9fc7ee528697..37c3fd548be6 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -194,7 +194,11 @@ mod tests { use alloy_consensus::{constants::KECCAK_EMPTY, Header, Receipt}; use alloy_eips::eip7685::Requests; use alloy_genesis::Genesis; - use alloy_primitives::{bytes, Address, LogData, B256, U256}; + use alloy_primitives::{ + bytes, + map::{HashMap, HashSet}, + Address, LogData, B256, U256, + }; use reth_chainspec::ChainSpec; use reth_evm::execute::ProviderError; use reth_execution_types::{ @@ -210,10 +214,7 @@ mod tests { JournaledState, }; use revm_primitives::{EnvWithHandlerCfg, HandlerCfg}; - use std::{ - collections::{HashMap, HashSet}, - sync::Arc, - }; + use std::sync::Arc; fn test_evm_config() -> OpEvmConfig { OpEvmConfig::new(BASE_MAINNET.clone()) diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 1c5ce30ce97f..0801164e61fa 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -2,7 +2,7 @@ use alloy_consensus::BlockHeader; use alloy_genesis::GenesisAccount; -use alloy_primitives::{Address, B256, U256}; +use alloy_primitives::{map::HashMap, Address, B256, U256}; use reth_chainspec::EthChainSpec; use reth_codecs::Compact; use reth_config::config::EtlConfig; @@ -23,7 +23,7 @@ use reth_stages_types::{StageCheckpoint, StageId}; use reth_trie::{IntermediateStateRootState, StateRoot as StateRootComputer, StateRootProgress}; use reth_trie_db::DatabaseStateRoot; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, io::BufRead}; +use std::io::BufRead; use tracing::{debug, error, info, trace}; /// Default soft limit for number of bytes to read from state dump file, before inserting into @@ -186,9 +186,11 @@ where + AsRef, { let capacity = alloc.size_hint().1.unwrap_or(0); - let mut state_init: BundleStateInit = HashMap::with_capacity(capacity); - let mut reverts_init = HashMap::with_capacity(capacity); - let mut contracts: HashMap = HashMap::with_capacity(capacity); + let mut state_init: BundleStateInit = + HashMap::with_capacity_and_hasher(capacity, Default::default()); + let mut reverts_init = HashMap::with_capacity_and_hasher(capacity, Default::default()); + let mut contracts: HashMap = + HashMap::with_capacity_and_hasher(capacity, Default::default()); for (address, account) in alloc { let bytecode_hash = if let Some(code) = &account.code { @@ -239,7 +241,7 @@ where ), ); } - let all_reverts_init: RevertsInit = HashMap::from([(block, reverts_init)]); + let all_reverts_init: RevertsInit = std::iter::once((block, reverts_init)).collect(); let execution_outcome = ExecutionOutcome::new_init( state_init, diff --git a/crates/storage/provider/src/providers/consistent.rs b/crates/storage/provider/src/providers/consistent.rs index c12324c541c4..46f7d7a9c49e 100644 --- a/crates/storage/provider/src/providers/consistent.rs +++ b/crates/storage/provider/src/providers/consistent.rs @@ -12,7 +12,10 @@ use alloy_eips::{ eip4895::{Withdrawal, Withdrawals}, BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, HashOrNumber, }; -use alloy_primitives::{Address, BlockHash, BlockNumber, TxHash, TxNumber, B256, U256}; +use alloy_primitives::{ + map::{hash_map, HashMap}, + Address, BlockHash, BlockNumber, TxHash, TxNumber, B256, U256, +}; use reth_chain_state::{BlockState, CanonicalInMemoryState, MemoryOverlayStateProviderRef}; use reth_chainspec::{ChainInfo, EthereumHardforks}; use reth_db::models::BlockNumberAddress; @@ -32,7 +35,6 @@ use reth_storage_api::{ use reth_storage_errors::provider::ProviderResult; use revm::db::states::PlainStorageRevert; use std::{ - collections::{hash_map, HashMap}, ops::{Add, Bound, RangeBounds, RangeInclusive, Sub}, sync::Arc, }; @@ -224,8 +226,8 @@ impl ConsistentProvider { storage_changeset: Vec<(BlockNumberAddress, StorageEntry)>, block_range_end: BlockNumber, ) -> ProviderResult<(BundleStateInit, RevertsInit)> { - let mut state: BundleStateInit = HashMap::new(); - let mut reverts: RevertsInit = HashMap::new(); + let mut state: BundleStateInit = HashMap::default(); + let mut reverts: RevertsInit = HashMap::default(); let state_provider = self.state_by_block_number_ref(block_range_end)?; // add account changeset changes @@ -234,7 +236,7 @@ impl ConsistentProvider { match state.entry(address) { hash_map::Entry::Vacant(entry) => { let new_info = state_provider.basic_account(&address)?; - entry.insert((old_info, new_info, HashMap::new())); + entry.insert((old_info, new_info, HashMap::default())); } hash_map::Entry::Occupied(mut entry) => { // overwrite old account state. @@ -252,7 +254,7 @@ impl ConsistentProvider { let account_state = match state.entry(address) { hash_map::Entry::Vacant(entry) => { let present_info = state_provider.basic_account(&address)?; - entry.insert((present_info, present_info, HashMap::new())) + entry.insert((present_info, present_info, HashMap::default())) } hash_map::Entry::Occupied(entry) => entry.into_mut(), };