fix: no_std case hashmap imports (#13617)

This commit is contained in:
Akase Haruka
2025-01-04 17:49:06 +08:00
committed by GitHub
parent 8befda56b0
commit 91d09de440
4 changed files with 23 additions and 19 deletions

View File

@ -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)]

View File

@ -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())

View File

@ -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<Provider>,
{
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<B256, Bytecode> = 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<B256, Bytecode> =
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,

View File

@ -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<N: ProviderNodeTypes> ConsistentProvider<N> {
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<N: ProviderNodeTypes> ConsistentProvider<N> {
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<N: ProviderNodeTypes> ConsistentProvider<N> {
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(),
};