Skip to content

Commit 892da81

Browse files
authored
feat(primitives): implement map module #743 for v45 (#1806)
1 parent fc1556f commit 892da81

17 files changed

+96
-81
lines changed

Cargo.lock

+23-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/primitives/Cargo.toml

+16-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ rust_2018_idioms = "deny"
2222
all = "warn"
2323

2424
[dependencies]
25-
alloy-eips = { version = "0.3", default-features = false, features = ["k256"] }
26-
alloy-primitives = { version = "0.8.2", default-features = false, features = [
25+
# alloy
26+
alloy-eip2930 = { version = "0.1", default-features = false }
27+
alloy-eip7702 = { version = "0.1", default-features = false, features = [
28+
"k256",
29+
] }
30+
alloy-primitives = { version = "0.8.5", default-features = false, features = [
2731
"rlp",
32+
"map",
2833
] }
29-
hashbrown = "0.14"
34+
35+
# mics
3036
auto_impl = "1.2"
3137
bitvec = { version = "1", default-features = false, features = ["alloc"] }
3238
bitflags = { version = "2.6.0", default-features = false }
@@ -57,28 +63,30 @@ hex = { version = "0.4", default-features = false }
5763
default = ["std", "c-kzg", "portable"]
5864
std = [
5965
"serde?/std",
60-
"alloy-eips/std",
6166
"alloy-primitives/std",
6267
"hex/std",
6368
"bitvec/std",
6469
"bitflags/std",
70+
"alloy-eip7702/std",
71+
"alloy-eip2930/std",
6572
]
66-
hashbrown = []
73+
hashbrown = ["alloy-primitives/map-hashbrown"]
6774
serde = [
6875
"dep:serde",
69-
"alloy-eips/serde",
7076
"alloy-primitives/serde",
7177
"hex/serde",
72-
"hashbrown/serde",
7378
"bitvec/serde",
7479
"bitflags/serde",
7580
"c-kzg?/serde",
81+
"alloy-eip7702/serde",
82+
"alloy-eip2930/serde",
7683
]
7784
arbitrary = [
7885
"std",
79-
"alloy-eips/arbitrary",
8086
"alloy-primitives/arbitrary",
8187
"bitflags/arbitrary",
88+
"alloy-eip7702/arbitrary",
89+
"alloy-eip2930/arbitrary",
8290
]
8391
asm-keccak = ["alloy-primitives/asm-keccak"]
8492
portable = ["c-kzg?/portable"]

crates/primitives/src/eip7702/authorization_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use alloy_eips::eip7702::{Authorization, SignedAuthorization};
1+
pub use alloy_eip7702::{Authorization, SignedAuthorization};
22
pub use alloy_primitives::{Parity, Signature};
33

44
use super::SECP256K1N_HALF;

crates/primitives/src/lib.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ pub mod result;
2020
pub mod specification;
2121
pub mod state;
2222
pub mod utilities;
23-
pub use alloy_eips::eip2930::{AccessList, AccessListItem};
23+
pub use alloy_eip2930::{AccessList, AccessListItem};
2424
pub use alloy_primitives::{
25-
self, address, b256, bytes, fixed_bytes, hex, hex_literal, ruint, uint, Address, Bytes,
26-
FixedBytes, Log, LogData, TxKind, B256, I256, U256,
25+
self, address, b256, bytes, fixed_bytes, hex, hex_literal,
26+
map::{self, hash_map, hash_set, HashMap, HashSet},
27+
ruint, uint, Address, Bytes, FixedBytes, Log, LogData, TxKind, B256, I256, U256,
2728
};
2829
pub use bitvec;
2930
pub use bytecode::*;
@@ -34,15 +35,6 @@ pub use eip7702::{
3435
};
3536
pub use env::*;
3637

37-
cfg_if::cfg_if! {
38-
if #[cfg(all(not(feature = "hashbrown"), feature = "std"))] {
39-
pub use std::collections::{hash_map, hash_set, HashMap, HashSet};
40-
use hashbrown as _;
41-
} else {
42-
pub use hashbrown::{hash_map, hash_set, HashMap, HashSet};
43-
}
44-
}
45-
4638
#[cfg(any(feature = "c-kzg", feature = "kzg-rs"))]
4739
pub use kzg::{EnvKzgSettings, KzgSettings};
4840
pub use precompile::*;

crates/primitives/src/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Account {
5757
pub fn new_not_existing() -> Self {
5858
Self {
5959
info: AccountInfo::default(),
60-
storage: HashMap::new(),
60+
storage: HashMap::default(),
6161
status: AccountStatus::LoadedAsNotExisting,
6262
}
6363
}
@@ -158,7 +158,7 @@ impl From<AccountInfo> for Account {
158158
fn from(info: AccountInfo) -> Self {
159159
Self {
160160
info,
161-
storage: HashMap::new(),
161+
storage: HashMap::default(),
162162
status: AccountStatus::Loaded,
163163
}
164164
}

crates/revm/src/context/evm_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ pub(crate) mod test_utils {
526526
EvmContext {
527527
inner: InnerEvmContext {
528528
env,
529-
journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::new()),
529+
journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::default()),
530530
db,
531531
error: Ok(()),
532532
#[cfg(feature = "optimism")]
@@ -541,7 +541,7 @@ pub(crate) mod test_utils {
541541
EvmContext {
542542
inner: InnerEvmContext {
543543
env,
544-
journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::new()),
544+
journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::default()),
545545
db,
546546
error: Ok(()),
547547
#[cfg(feature = "optimism")]

crates/revm/src/context/inner_evm_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<DB: Database> InnerEvmContext<DB> {
5252
pub fn new(db: DB) -> Self {
5353
Self {
5454
env: Box::default(),
55-
journaled_state: JournaledState::new(SpecId::LATEST, HashSet::new()),
55+
journaled_state: JournaledState::new(SpecId::LATEST, HashSet::default()),
5656
db,
5757
error: Ok(()),
5858
#[cfg(feature = "optimism")]
@@ -65,7 +65,7 @@ impl<DB: Database> InnerEvmContext<DB> {
6565
pub fn new_with_env(db: DB, env: Box<Env>) -> Self {
6666
Self {
6767
env,
68-
journaled_state: JournaledState::new(SpecId::LATEST, HashSet::new()),
68+
journaled_state: JournaledState::new(SpecId::LATEST, HashSet::default()),
6969
db,
7070
error: Ok(()),
7171
#[cfg(feature = "optimism")]

crates/revm/src/db/in_memory_db.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ impl<ExtDB: Default> Default for CacheDB<ExtDB> {
4343

4444
impl<ExtDB> CacheDB<ExtDB> {
4545
pub fn new(db: ExtDB) -> Self {
46-
let mut contracts = HashMap::new();
46+
let mut contracts = HashMap::default();
4747
contracts.insert(KECCAK_EMPTY, Bytecode::default());
4848
contracts.insert(B256::ZERO, Bytecode::default());
4949
Self {
50-
accounts: HashMap::new(),
50+
accounts: HashMap::default(),
5151
contracts,
5252
logs: Vec::default(),
53-
block_hashes: HashMap::new(),
53+
block_hashes: HashMap::default(),
5454
db,
5555
}
5656
}
@@ -411,7 +411,7 @@ impl Database for BenchmarkDB {
411411
#[cfg(test)]
412412
mod tests {
413413
use super::{CacheDB, EmptyDB};
414-
use crate::primitives::{db::Database, AccountInfo, Address, U256};
414+
use crate::primitives::{db::Database, AccountInfo, Address, HashMap, U256};
415415

416416
#[test]
417417
fn test_insert_account_storage() {
@@ -457,7 +457,7 @@ mod tests {
457457

458458
let mut new_state = CacheDB::new(init_state);
459459
new_state
460-
.replace_account_storage(account, [(key1, value1)].into())
460+
.replace_account_storage(account, HashMap::from_iter([(key1, value1)]))
461461
.unwrap();
462462

463463
assert_eq!(new_state.basic(account).unwrap().unwrap().nonce, nonce);

crates/revm/src/db/states/bundle_account.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl BundleAccount {
9494
AccountInfoRevert::DeleteIt => {
9595
self.info = None;
9696
if self.original_info.is_none() {
97-
self.storage = HashMap::new();
97+
self.storage = HashMap::default();
9898
return true;
9999
} else {
100100
// set all storage to zero but preserve original values.

crates/revm/src/db/states/bundle_state.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ impl OriginalValuesKnown {
5555
impl Default for BundleBuilder {
5656
fn default() -> Self {
5757
BundleBuilder {
58-
states: HashSet::new(),
59-
state_original: HashMap::new(),
60-
state_present: HashMap::new(),
61-
state_storage: HashMap::new(),
58+
states: HashSet::default(),
59+
state_original: HashMap::default(),
60+
state_present: HashMap::default(),
61+
state_storage: HashMap::default(),
6262
reverts: BTreeSet::new(),
6363
revert_range: 0..=0,
64-
revert_account: HashMap::new(),
65-
revert_storage: HashMap::new(),
66-
contracts: HashMap::new(),
64+
revert_account: HashMap::default(),
65+
revert_storage: HashMap::default(),
66+
contracts: HashMap::default(),
6767
}
6868
}
6969
}
@@ -782,7 +782,7 @@ impl BundleState {
782782
let mut account = BundleAccount::new(
783783
None,
784784
None,
785-
HashMap::new(),
785+
HashMap::default(),
786786
AccountStatus::LoadedNotExisting,
787787
);
788788
if !account.revert(revert_account) {
@@ -897,7 +897,7 @@ mod tests {
897897
code_hash: KECCAK_EMPTY,
898898
code: None,
899899
}),
900-
HashMap::from([
900+
HashMap::from_iter([
901901
(slot1(), (U256::from(0), U256::from(10))),
902902
(slot2(), (U256::from(0), U256::from(15))),
903903
]),
@@ -911,7 +911,7 @@ mod tests {
911911
code_hash: KECCAK_EMPTY,
912912
code: None,
913913
}),
914-
HashMap::from([]),
914+
HashMap::default(),
915915
),
916916
],
917917
vec![vec![
@@ -939,7 +939,7 @@ mod tests {
939939
code_hash: KECCAK_EMPTY,
940940
code: None,
941941
}),
942-
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
942+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
943943
)],
944944
vec![vec![(
945945
account1(),
@@ -969,7 +969,7 @@ mod tests {
969969
)
970970
.state_storage(
971971
account1(),
972-
HashMap::from([(slot1(), (U256::from(0), U256::from(10)))]),
972+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(10)))]),
973973
)
974974
.state_address(account2())
975975
.state_present_account_info(
@@ -1002,7 +1002,7 @@ mod tests {
10021002
)
10031003
.state_storage(
10041004
account1(),
1005-
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
1005+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
10061006
)
10071007
.revert_address(0, account1())
10081008
.revert_account_info(
@@ -1132,7 +1132,7 @@ mod tests {
11321132
Some(&BundleAccount::new(
11331133
None,
11341134
Some(AccountInfo::default()),
1135-
HashMap::new(),
1135+
HashMap::default(),
11361136
AccountStatus::Changed
11371137
))
11381138
);
@@ -1267,7 +1267,7 @@ mod tests {
12671267
assert!(builder.get_state_storage_mut().is_empty());
12681268
builder
12691269
.get_state_storage_mut()
1270-
.insert(account1(), HashMap::new());
1270+
.insert(account1(), HashMap::default());
12711271
assert!(builder.get_state_storage_mut().contains_key(&account1()));
12721272

12731273
// Test get_reverts_mut

0 commit comments

Comments
 (0)