Skip to content

Commit

Permalink
fix: no_std case hashmap imports (#13617)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing authored Jan 4, 2025
1 parent 8befda5 commit 91d09de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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};
use revm::{
db::{states::BundleState, BundleAccount},
primitives::AccountInfo,
};
use std::collections::HashMap;

/// Represents a changed account
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
11 changes: 6 additions & 5 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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())
Expand Down
14 changes: 8 additions & 6 deletions crates/storage/db-common/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions crates/storage/provider/src/providers/consistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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(),
};
Expand Down

0 comments on commit 91d09de

Please sign in to comment.