Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(primitives): replace HashMap re-exports with alloy_primitives::map #1805

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
617 changes: 328 additions & 289 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ inspector = { workspace = true, features = ["std", "serde-json"] }
bytecode = { workspace = true, features = ["std", "parse"] }

hash-db = "0.15"
hex = "0.4"
hashbrown = "0.14"
indicatif = "0.17"
microbench = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion bins/revme/src/cmd/bench/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use database::{BenchmarkDB, EthereumBenchmarkWiring};
use revm::{
bytecode::Bytecode,
primitives::{address, bytes, Bytes, TxKind},
primitives::{address, bytes, hex, Bytes, TxKind},
Evm,
};
use std::time::Instant;
Expand Down
2 changes: 1 addition & 1 deletion bins/revme/src/cmd/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use revm::{
bytecode::eof::{self, validate_eof_inner, CodeType, Eof, EofError},
primitives::{Bytes, MAX_INITCODE_SIZE},
primitives::{hex, Bytes, MAX_INITCODE_SIZE},
};
use std::io;

Expand Down
2 changes: 1 addition & 1 deletion bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use database::BenchmarkDB;
use inspector::{inspector_handle_register, inspectors::TracerEip3155};
use revm::{
bytecode::{Bytecode, BytecodeDecodeError},
primitives::{address, Address, TxKind},
primitives::{address, hex, Address, TxKind},
wiring::EthereumWiring,
Database, Evm,
};
Expand Down
10 changes: 5 additions & 5 deletions crates/database/src/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ impl<ExtDB: Default> Default for CacheDB<ExtDB> {

impl<ExtDB> CacheDB<ExtDB> {
pub fn new(db: ExtDB) -> Self {
let mut contracts = HashMap::new();
let mut contracts = HashMap::default();
contracts.insert(KECCAK_EMPTY, Bytecode::default());
contracts.insert(B256::ZERO, Bytecode::default());
Self {
accounts: HashMap::new(),
accounts: HashMap::default(),
contracts,
logs: Vec::default(),
block_hashes: HashMap::new(),
block_hashes: HashMap::default(),
db,
}
}
Expand Down Expand Up @@ -413,7 +413,7 @@ impl Database for BenchmarkDB {
mod tests {
use super::{CacheDB, EmptyDB};
use database_interface::Database;
use primitives::{Address, U256};
use primitives::{Address, HashMap, U256};
use state::AccountInfo;

#[test]
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {

let mut new_state = CacheDB::new(init_state);
new_state
.replace_account_storage(account, [(key1, value1)].into())
.replace_account_storage(account, HashMap::from_iter([(key1, value1)]))
.unwrap();

assert_eq!(new_state.basic(account).unwrap().unwrap().nonce, nonce);
Expand Down
2 changes: 1 addition & 1 deletion crates/database/src/states/bundle_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl BundleAccount {
AccountInfoRevert::DeleteIt => {
self.info = None;
if self.original_info.is_none() {
self.storage = HashMap::new();
self.storage = HashMap::default();
return true;
} else {
// set all storage to zero but preserve original values.
Expand Down
30 changes: 15 additions & 15 deletions crates/database/src/states/bundle_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ impl OriginalValuesKnown {
impl Default for BundleBuilder {
fn default() -> Self {
BundleBuilder {
states: HashSet::new(),
state_original: HashMap::new(),
state_present: HashMap::new(),
state_storage: HashMap::new(),
states: HashSet::default(),
state_original: HashMap::default(),
state_present: HashMap::default(),
state_storage: HashMap::default(),
reverts: BTreeSet::new(),
revert_range: 0..=0,
revert_account: HashMap::new(),
revert_storage: HashMap::new(),
contracts: HashMap::new(),
revert_account: HashMap::default(),
revert_storage: HashMap::default(),
contracts: HashMap::default(),
}
}
}
Expand Down Expand Up @@ -805,7 +805,7 @@ impl BundleState {
let mut account = BundleAccount::new(
None,
None,
HashMap::new(),
HashMap::default(),
AccountStatus::LoadedNotExisting,
);
if !account.revert(revert_account) {
Expand Down Expand Up @@ -920,7 +920,7 @@ mod tests {
code_hash: KECCAK_EMPTY,
code: None,
}),
HashMap::from([
HashMap::from_iter([
(slot1(), (U256::from(0), U256::from(10))),
(slot2(), (U256::from(0), U256::from(15))),
]),
Expand All @@ -934,7 +934,7 @@ mod tests {
code_hash: KECCAK_EMPTY,
code: None,
}),
HashMap::from([]),
HashMap::default(),
),
],
vec![vec![
Expand Down Expand Up @@ -962,7 +962,7 @@ mod tests {
code_hash: KECCAK_EMPTY,
code: None,
}),
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
)],
vec![vec![(
account1(),
Expand Down Expand Up @@ -992,7 +992,7 @@ mod tests {
)
.state_storage(
account1(),
HashMap::from([(slot1(), (U256::from(0), U256::from(10)))]),
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(10)))]),
)
.state_address(account2())
.state_present_account_info(
Expand Down Expand Up @@ -1025,7 +1025,7 @@ mod tests {
)
.state_storage(
account1(),
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
)
.revert_address(0, account1())
.revert_account_info(
Expand Down Expand Up @@ -1155,7 +1155,7 @@ mod tests {
Some(&BundleAccount::new(
None,
Some(AccountInfo::default()),
HashMap::new(),
HashMap::default(),
AccountStatus::Changed
))
);
Expand Down Expand Up @@ -1290,7 +1290,7 @@ mod tests {
assert!(builder.get_state_storage_mut().is_empty());
builder
.get_state_storage_mut()
.insert(account1(), HashMap::new());
.insert(account1(), HashMap::default());
assert!(builder.get_state_storage_mut().contains_key(&account1()));

// Test get_reverts_mut
Expand Down
4 changes: 2 additions & 2 deletions crates/database/src/states/cache_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl CacheAccount {
status: self.status,
previous_info,
previous_status,
storage: HashMap::new(),
storage: HashMap::default(),
storage_was_destroyed: true,
})
}
Expand Down Expand Up @@ -259,7 +259,7 @@ impl CacheAccount {
status: self.status,
previous_info,
previous_status,
storage: HashMap::new(),
storage: HashMap::default(),
storage_was_destroyed: false,
},
)
Expand Down
2 changes: 1 addition & 1 deletion crates/database/src/states/plain_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl From<AccountInfo> for PlainAccount {
fn from(info: AccountInfo) -> Self {
Self {
info,
storage: HashMap::new(),
storage: HashMap::default(),
}
}
}
34 changes: 17 additions & 17 deletions crates/database/src/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ impl<DB: Database> State<DB> {
let account = match info {
None => CacheAccount::new_loaded_not_existing(),
Some(acc) if acc.is_empty() => {
CacheAccount::new_loaded_empty_eip161(HashMap::new())
CacheAccount::new_loaded_empty_eip161(HashMap::default())
}
Some(acc) => CacheAccount::new_loaded(acc, HashMap::new()),
Some(acc) => CacheAccount::new_loaded(acc, HashMap::default()),
};
Ok(entry.insert(account))
}
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
nonce: 1,
..Default::default()
};
let existing_account_initial_storage = HashMap::<U256, U256>::from([
let existing_account_initial_storage = HashMap::<U256, U256>::from_iter([
(slot1, U256::from(100)), // 0x01 => 100
(slot2, U256::from(200)), // 0x02 => 200
]);
Expand Down Expand Up @@ -395,7 +395,7 @@ mod tests {
info: Some(existing_account_changed_info.clone()),
previous_status: AccountStatus::Loaded,
previous_info: Some(existing_account_initial_info.clone()),
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot1,
StorageSlot::new_changed(
*existing_account_initial_storage.get(&slot1).unwrap(),
Expand Down Expand Up @@ -428,7 +428,7 @@ mod tests {
info: Some(new_account_changed_info2.clone()),
previous_status: AccountStatus::InMemoryChange,
previous_info: Some(new_account_changed_info),
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot1,
StorageSlot::new_changed(U256::ZERO, U256::from(1)),
)]),
Expand All @@ -442,7 +442,7 @@ mod tests {
info: Some(existing_account_changed_info.clone()),
previous_status: AccountStatus::InMemoryChange,
previous_info: Some(existing_account_changed_info.clone()),
storage: HashMap::from([
storage: HashMap::from_iter([
(
slot1,
StorageSlot::new_changed(U256::from(100), U256::from(1_000)),
Expand Down Expand Up @@ -479,7 +479,7 @@ mod tests {
AccountRevert {
account: AccountInfoRevert::DeleteIt,
previous_status: AccountStatus::LoadedNotExisting,
storage: HashMap::from([(slot1, RevertToSlot::Some(U256::ZERO))]),
storage: HashMap::from_iter([(slot1, RevertToSlot::Some(U256::ZERO))]),
wipe_storage: false,
}
),
Expand All @@ -488,7 +488,7 @@ mod tests {
AccountRevert {
account: AccountInfoRevert::RevertTo(existing_account_initial_info.clone()),
previous_status: AccountStatus::Loaded,
storage: HashMap::from([
storage: HashMap::from_iter([
(
slot1,
RevertToSlot::Some(
Expand Down Expand Up @@ -518,7 +518,7 @@ mod tests {
info: Some(new_account_changed_info2),
original_info: None,
status: AccountStatus::InMemoryChange,
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot1,
StorageSlot::new_changed(U256::ZERO, U256::from(1))
)]),
Expand All @@ -534,7 +534,7 @@ mod tests {
info: Some(existing_account_changed_info),
original_info: Some(existing_account_initial_info),
status: AccountStatus::InMemoryChange,
storage: HashMap::from([
storage: HashMap::from_iter([
(
slot1,
StorageSlot::new_changed(
Expand Down Expand Up @@ -622,7 +622,7 @@ mod tests {
info: Some(existing_account_with_storage_info.clone()),
previous_status: AccountStatus::Loaded,
previous_info: Some(existing_account_with_storage_info.clone()),
storage: HashMap::from([
storage: HashMap::from_iter([
(
slot1,
StorageSlot::new_changed(U256::from(1), U256::from(10)),
Expand Down Expand Up @@ -663,7 +663,7 @@ mod tests {
info: Some(existing_account_with_storage_info.clone()),
previous_status: AccountStatus::Changed,
previous_info: Some(existing_account_with_storage_info.clone()),
storage: HashMap::from([
storage: HashMap::from_iter([
(
slot1,
StorageSlot::new_changed(U256::from(10), U256::from(1)),
Expand Down Expand Up @@ -720,7 +720,7 @@ mod tests {
info: Some(existing_account_info.clone()),
previous_status: AccountStatus::Destroyed,
previous_info: None,
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot1,
StorageSlot::new_changed(U256::ZERO, U256::from(1)),
)]),
Expand Down Expand Up @@ -750,7 +750,7 @@ mod tests {
info: Some(existing_account_info.clone()),
previous_status: AccountStatus::DestroyedAgain,
previous_info: None,
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot2,
StorageSlot::new_changed(U256::ZERO, U256::from(2)),
)]),
Expand All @@ -764,12 +764,12 @@ mod tests {

assert_eq!(
bundle_state.state,
HashMap::from([(
HashMap::from_iter([(
existing_account_address,
BundleAccount {
info: Some(existing_account_info.clone()),
original_info: Some(existing_account_info.clone()),
storage: HashMap::from([(
storage: HashMap::from_iter([(
slot2,
StorageSlot::new_changed(U256::ZERO, U256::from(2))
)]),
Expand All @@ -785,7 +785,7 @@ mod tests {
AccountRevert {
account: AccountInfoRevert::DoNothing,
previous_status: AccountStatus::Loaded,
storage: HashMap::from([(slot2, RevertToSlot::Destroyed)]),
storage: HashMap::from_iter([(slot2, RevertToSlot::Destroyed)]),
wipe_storage: true,
}
)])])
Expand Down
2 changes: 1 addition & 1 deletion crates/database/src/states/transition_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl TransitionAccount {
BundleAccount {
info: self.previous_info.clone(),
original_info: self.previous_info.clone(),
storage: StorageWithOriginalValues::new(),
storage: StorageWithOriginalValues::default(),
status: self.previous_status,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/database/src/states/transition_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct TransitionState {
impl TransitionState {
/// Create new transition state containing one [`TransitionAccount`].
pub fn single(address: Address, transition: TransitionAccount) -> Self {
let mut transitions = HashMap::new();
let mut transitions = HashMap::default();
transitions.insert(address, transition);
TransitionState { transitions }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/host/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ where
pub fn new(env: EnvWiring<EvmWiringT>) -> Self {
Self {
env,
storage: HashMap::new(),
transient_storage: HashMap::new(),
storage: HashMap::default(),
transient_storage: HashMap::default(),
log: Vec::new(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/src/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ pub fn end<EvmWiringT: OptimismWiring, SPEC: OptimismSpec>(
acc.mark_touch();
acc
};
let state = HashMap::from([(caller, account)]);
let state = HashMap::from_iter([(caller, account)]);

// The gas used of a failed deposit post-regolith is the gas
// limit of the transaction. pre-regolith, it is the gas limit
Expand Down
Loading
Loading