From 6c120a111f1a7b460519dcf5a764915734a83a16 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Tue, 19 Nov 2024 11:09:30 +0100 Subject: [PATCH] fix lints + feature check Signed-off-by: Gregory Edison --- Cargo.lock | 9 ++- crates/ethereum/evm/Cargo.toml | 3 + crates/ethereum/evm/src/execute.rs | 26 +++++--- crates/primitives-traits/Cargo.toml | 3 +- crates/primitives-traits/src/account.rs | 37 ++++++++--- crates/primitives/Cargo.toml | 9 ++- crates/scroll/execution/Cargo.toml | 5 +- crates/scroll/primitives/Cargo.toml | 6 +- crates/scroll/revm/Cargo.toml | 12 +++- crates/scroll/revm/src/lib.rs | 6 +- crates/stages/stages/Cargo.toml | 6 ++ crates/stages/stages/src/stages/execution.rs | 62 ++++++++++++------- .../stages/src/stages/hashing_account.rs | 10 +-- crates/stages/stages/src/stages/mod.rs | 9 +-- crates/storage/db-common/Cargo.toml | 6 ++ crates/storage/db-common/src/init.rs | 8 ++- crates/storage/db/Cargo.toml | 1 + .../storage/db/src/implementation/mdbx/mod.rs | 4 +- crates/storage/provider/Cargo.toml | 3 + .../src/providers/state/historical.rs | 57 ++++++++++++----- .../storage/provider/src/test_utils/mock.rs | 14 ++++- crates/storage/provider/src/writer/mod.rs | 7 ++- crates/trie/common/Cargo.toml | 3 + crates/trie/common/src/account.rs | 6 +- crates/trie/common/src/proofs.rs | 7 ++- crates/trie/db/Cargo.toml | 3 + crates/trie/db/tests/proof.rs | 5 +- crates/trie/db/tests/trie.rs | 37 ++++++----- testing/ef-tests/Cargo.toml | 3 + testing/ef-tests/src/models.rs | 6 +- testing/testing-utils/Cargo.toml | 3 + testing/testing-utils/src/generators.rs | 12 +++- 32 files changed, 278 insertions(+), 110 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbbb87f5cc773..4b3f1c5dec08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2636,6 +2636,7 @@ dependencies = [ "reth-primitives", "reth-provider", "reth-revm", + "reth-scroll-primitives", "reth-stages", "revm", "serde", @@ -6960,6 +6961,7 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "reth-provider", + "reth-scroll-primitives", "reth-stages-types", "reth-trie", "reth-trie-db", @@ -7551,6 +7553,7 @@ dependencies = [ "reth-execution-types", "reth-primitives", "reth-revm", + "reth-scroll-primitives", "reth-testing-utils", "revm-primitives", "secp256k1", @@ -8583,10 +8586,10 @@ dependencies = [ "reth-codecs", "reth-ethereum-forks", "reth-primitives-traits", + "reth-scroll-revm", "reth-static-file-types", "reth-testing-utils", "reth-trie-common", - "revm-primitives", "rstest", "secp256k1", "serde", @@ -8661,6 +8664,7 @@ dependencies = [ "reth-optimism-primitives", "reth-primitives", "reth-prune-types", + "reth-scroll-primitives", "reth-stages-types", "reth-storage-api", "reth-storage-errors", @@ -9166,6 +9170,7 @@ dependencies = [ "reth-prune", "reth-prune-types", "reth-revm", + "reth-scroll-primitives", "reth-stages-api", "reth-static-file", "reth-storage-errors", @@ -9439,6 +9444,7 @@ dependencies = [ "proptest-arbitrary-interop", "reth-codecs", "reth-primitives-traits", + "reth-scroll-primitives", "revm-primitives", "serde", ] @@ -9461,6 +9467,7 @@ dependencies = [ "reth-metrics", "reth-primitives", "reth-provider", + "reth-scroll-primitives", "reth-storage-errors", "reth-trie", "reth-trie-common", diff --git a/crates/ethereum/evm/Cargo.toml b/crates/ethereum/evm/Cargo.toml index 17e870e611134..0dd0ab5a02ab2 100644 --- a/crates/ethereum/evm/Cargo.toml +++ b/crates/ethereum/evm/Cargo.toml @@ -39,6 +39,8 @@ secp256k1.workspace = true serde_json.workspace = true alloy-genesis.workspace = true +reth-scroll-primitives.workspace = true + [features] default = ["std"] std = [ @@ -52,3 +54,4 @@ std = [ "revm-primitives/std", "secp256k1/std" ] +scroll = [] diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 29bf5f0912ee7..b5e5aecf730c9 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -325,8 +325,10 @@ mod tests { balance: U256::ZERO, bytecode_hash: Some(keccak256(BEACON_ROOTS_CODE.clone())), nonce: 1, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &BEACON_ROOTS_CODE, + )), }; db.insert_account( @@ -346,8 +348,10 @@ mod tests { nonce: 1, balance: U256::ZERO, bytecode_hash: Some(keccak256(WITHDRAWAL_REQUEST_PREDEPLOY_CODE.clone())), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &WITHDRAWAL_REQUEST_PREDEPLOY_CODE, + )), }; db.insert_account( @@ -711,8 +715,10 @@ mod tests { balance: U256::ZERO, bytecode_hash: Some(keccak256(HISTORY_STORAGE_CODE.clone())), nonce: 1, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &HISTORY_STORAGE_CODE, + )), }; db.insert_account( @@ -1069,8 +1075,8 @@ mod tests { nonce: 1, balance: U256::from(ETH_TO_WEI), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, None, HashMap::default(), @@ -1157,8 +1163,8 @@ mod tests { nonce: 1, balance: U256::from(ETH_TO_WEI), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, None, HashMap::default(), diff --git a/crates/primitives-traits/Cargo.toml b/crates/primitives-traits/Cargo.toml index 19dd17c96d83d..e4dfda375483c 100644 --- a/crates/primitives-traits/Cargo.toml +++ b/crates/primitives-traits/Cargo.toml @@ -64,7 +64,8 @@ std = [ ] test-utils = [ "arbitrary", - "reth-codecs/test-utils" + "reth-codecs/test-utils", + "revm-primitives/test-utils" ] arbitrary = [ "std", diff --git a/crates/primitives-traits/src/account.rs b/crates/primitives-traits/src/account.rs index 802afc650a75a..ffdd4d2988776 100644 --- a/crates/primitives-traits/src/account.rs +++ b/crates/primitives-traits/src/account.rs @@ -256,8 +256,13 @@ mod tests { #[test] fn test_empty_account() { - let mut acc = - Account { nonce: 0, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; + let mut acc = Account { + nonce: 0, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), + }; // Nonce 0, balance 0, and bytecode hash set to None is considered empty. assert!(acc.is_empty()); @@ -313,7 +318,8 @@ mod tests { nonce: 1, balance: U256::from(1000), bytecode_hash: None, - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), }; assert!(!acc_no_bytecode.has_bytecode(), "Account should not have bytecode"); @@ -322,7 +328,8 @@ mod tests { nonce: 1, balance: U256::from(1000), bytecode_hash: Some(KECCAK_EMPTY), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), }; assert!(acc_empty_bytecode.has_bytecode(), "Account should have bytecode"); @@ -331,7 +338,10 @@ mod tests { nonce: 1, balance: U256::from(1000), bytecode_hash: Some(B256::from_slice(&[0x11u8; 32])), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &[0x11u8; 32], + )), }; assert!(acc_with_bytecode.has_bytecode(), "Account should have bytecode"); } @@ -339,8 +349,13 @@ mod tests { #[test] fn test_account_get_bytecode_hash() { // Account with no bytecode (should return KECCAK_EMPTY) - let acc_no_bytecode = - Account { nonce: 0, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; + let acc_no_bytecode = Account { + nonce: 0, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), + }; assert_eq!(acc_no_bytecode.get_bytecode_hash(), KECCAK_EMPTY, "Should return KECCAK_EMPTY"); // Account with bytecode hash set to KECCAK_EMPTY @@ -348,7 +363,8 @@ mod tests { nonce: 1, balance: U256::from(1000), bytecode_hash: Some(KECCAK_EMPTY), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), }; assert_eq!( acc_empty_bytecode.get_bytecode_hash(), @@ -362,7 +378,10 @@ mod tests { nonce: 1, balance: U256::from(1000), bytecode_hash: Some(bytecode_hash), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &[0x11u8; 32], + )), }; assert_eq!( acc_with_bytecode.get_bytecode_hash(), diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 34d04c94edcda..3507952699f56 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -16,7 +16,6 @@ workspace = true reth-primitives-traits.workspace = true reth-ethereum-forks.workspace = true reth-static-file-types.workspace = true -revm-primitives = { workspace = true, features = ["serde"] } reth-codecs = { workspace = true, optional = true } # ethereum @@ -29,6 +28,9 @@ alloy-serde = { workspace = true, optional = true } alloy-eips = { workspace = true, features = ["serde"] } alloy-trie = { workspace = true, features = ["serde"] } +# scroll +revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["serde"] } + # optimism op-alloy-rpc-types = { workspace = true, optional = true } op-alloy-consensus = { workspace = true, features = [ @@ -67,7 +69,7 @@ reth-codecs = { workspace = true, features = ["test-utils"] } reth-primitives-traits = { workspace = true, features = ["arbitrary"] } reth-testing-utils.workspace = true reth-trie-common.workspace = true -revm-primitives = { workspace = true, features = ["arbitrary"] } +revm-primitives = { package = "reth-scroll-revm", path = "../scroll/revm", features = ["arbitrary"] } alloy-eips = { workspace = true, features = ["arbitrary"] } alloy-genesis.workspace = true @@ -143,7 +145,7 @@ alloy-compat = [ "dep:alloy-rpc-types", "dep:alloy-serde", "dep:op-alloy-rpc-types", - "dep:alloy-network", + "dep:alloy-network", ] test-utils = [ "reth-primitives-traits/test-utils", @@ -151,6 +153,7 @@ test-utils = [ "reth-codecs?/test-utils", "reth-trie-common/test-utils", "arbitrary", + "revm-primitives/test-utils" ] serde-bincode-compat = [ "alloy-consensus/serde-bincode-compat", diff --git a/crates/scroll/execution/Cargo.toml b/crates/scroll/execution/Cargo.toml index 78c204b1ea657..7900e82e258cf 100644 --- a/crates/scroll/execution/Cargo.toml +++ b/crates/scroll/execution/Cargo.toml @@ -16,15 +16,16 @@ workspace = true reth-revm.workspace = true # scroll -reth-scroll-primitives.workspace = true +reth-scroll-primitives = { workspace = true, optional = true } reth-scroll-revm.workspace = true -reth-scroll-storage.workspace = true +reth-scroll-storage = { workspace = true, optional = true } # misc auto_impl.workspace = true [features] scroll = [ + "reth-scroll-primitives", "reth-scroll-revm/scroll", "reth-scroll-storage/scroll", ] diff --git a/crates/scroll/primitives/Cargo.toml b/crates/scroll/primitives/Cargo.toml index 6ea077f358f4a..cb33547ff775f 100644 --- a/crates/scroll/primitives/Cargo.toml +++ b/crates/scroll/primitives/Cargo.toml @@ -37,9 +37,11 @@ test-fuzz.workspace = true [features] default = ["std"] std = [ - "serde/std" + "serde/std", + "alloy-primitives/std" ] arbitrary = [ "dep:arbitrary", - "alloy-primitives/arbitrary" + "alloy-primitives/arbitrary", + "reth-codecs/arbitrary" ] diff --git a/crates/scroll/revm/Cargo.toml b/crates/scroll/revm/Cargo.toml index 307e05b013734..44956d812b1e7 100644 --- a/crates/scroll/revm/Cargo.toml +++ b/crates/scroll/revm/Cargo.toml @@ -23,7 +23,12 @@ serde = { workspace = true, optional = true } [features] default = ["std"] -arbitrary = ["revm/arbitrary"] +arbitrary = [ + "revm/arbitrary", + "reth-scroll-primitives/arbitrary" +] +asm-keccak = ["revm/asm-keccak"] +c-kzg = ["revm/c-kzg"] optimism = ["revm/optimism"] serde = [ "revm/serde", @@ -31,4 +36,7 @@ serde = [ ] scroll = [] test-utils = ["revm/test-utils"] -std = ["revm/std"] +std = [ + "revm/std", + "serde/std" +] diff --git a/crates/scroll/revm/src/lib.rs b/crates/scroll/revm/src/lib.rs index df63e47738be0..3ace4cd19bdc7 100644 --- a/crates/scroll/revm/src/lib.rs +++ b/crates/scroll/revm/src/lib.rs @@ -5,11 +5,15 @@ pub mod states; +#[cfg(feature = "optimism")] +pub use revm::primitives::OptimismFields; + pub use revm::{ db::*, inspector_handle_register, primitives::{ - keccak256, Bytecode, BytecodeDecodeError, JumpTable, LegacyAnalyzedBytecode, TxEnv, + keccak256, AuthorizationList, Bytecode, BytecodeDecodeError, JumpTable, + LegacyAnalyzedBytecode, TxEnv, TxKind, }, Evm, EvmBuilder, GetInspector, }; diff --git a/crates/stages/stages/Cargo.toml b/crates/stages/stages/Cargo.toml index eedd5f9ca41e9..74ad23fbc7aaa 100644 --- a/crates/stages/stages/Cargo.toml +++ b/crates/stages/stages/Cargo.toml @@ -39,6 +39,9 @@ reth-trie-db = { workspace = true, features = ["metrics"] } reth-testing-utils = { workspace = true, optional = true } +# scroll +reth-scroll-primitives = { workspace = true, optional = true } + alloy-primitives.workspace = true alloy-consensus.workspace = true @@ -74,6 +77,8 @@ reth-trie = { workspace = true, features = ["test-utils"] } reth-provider = { workspace = true, features = ["test-utils"] } reth-network-peers.workspace = true +reth-scroll-primitives.workspace = true + alloy-rlp.workspace = true itertools.workspace = true tokio = { workspace = true, features = ["rt", "sync", "macros"] } @@ -114,6 +119,7 @@ test-utils = [ "reth-trie/test-utils", "reth-prune-types/test-utils", ] +scroll = ["reth-scroll-primitives"] [[bench]] name = "criterion" diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 16ba8bfb6bd3d..a62d947e722be 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -884,16 +884,22 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): use `from_bytecode` + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, ) .unwrap(); db_tx .put::( acc2, - // TODO (scroll): remove at last Scroll `Account` related PR. - Account { nonce: 0, balance, bytecode_hash: None, ..Default::default() }, + Account { + nonce: 0, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }, ) .unwrap(); db_tx.put::(code_hash, Bytecode::new_raw(code.to_vec().into())).unwrap(); @@ -947,24 +953,25 @@ mod tests { balance: U256::ZERO, nonce: 0x00, bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): use `from_bytecode`. + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; let account2 = address!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"); let account2_info = Account { balance: U256::from(0x1bc16d674ece94bau128), nonce: 0x00, bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; let account3 = address!("a94f5374fce5edbc8e2a8697c15331677e6ebf0b"); let account3_info = Account { balance: U256::from(0x3635c9adc5de996b46u128), nonce: 0x01, bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; // assert accounts @@ -1044,12 +1051,18 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): use `from_bytecode`. + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; let acc2 = address!("a94f5374fce5edbc8e2a8697c15331677e6ebf0b"); - // TODO (scroll): remove at last Scroll `Account` related PR. - let acc2_info = Account { nonce: 0, balance, bytecode_hash: None, ..Default::default() }; + let acc2_info = Account { + nonce: 0, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; db_tx.put::(acc1, acc1_info).unwrap(); db_tx.put::(acc2, acc2_info).unwrap(); @@ -1166,13 +1179,20 @@ mod tests { let code_hash = keccak256(code); // pre state - let caller_info = Account { nonce: 0, balance, bytecode_hash: None, ..Default::default() }; + let caller_info = Account { + nonce: 0, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; let destroyed_info = Account { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): use `from_bytecode`. + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; // set account @@ -1233,8 +1253,8 @@ mod tests { nonce: 0, balance: U256::from(0x1bc16d674eca30a0u64), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), } ), ( @@ -1243,8 +1263,8 @@ mod tests { nonce: 1, balance: U256::from(0xde0b6b3a761cf60u64), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), } ) ] diff --git a/crates/stages/stages/src/stages/hashing_account.rs b/crates/stages/stages/src/stages/hashing_account.rs index 9318eee915e9e..8bdaf6ce5571c 100644 --- a/crates/stages/stages/src/stages/hashing_account.rs +++ b/crates/stages/stages/src/stages/hashing_account.rs @@ -105,8 +105,8 @@ impl AccountHashingStage { nonce: nonce - 1, balance: balance - U256::from(1), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; let acc_before_tx = AccountBeforeTx { address: *addr, info: Some(prev_acc) }; acc_changeset_cursor.append(t, acc_before_tx)?; @@ -401,8 +401,10 @@ mod tests { nonce: nonce - 1, balance: balance - U256::from(1), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::empty(), + ), }; let hashed_addr = keccak256(address); if let Some((_, acc)) = hashed_acc_cursor.seek_exact(hashed_addr)? { diff --git a/crates/stages/stages/src/stages/mod.rs b/crates/stages/stages/src/stages/mod.rs index e62531e64bc05..7f351efc60e14 100644 --- a/crates/stages/stages/src/stages/mod.rs +++ b/crates/stages/stages/src/stages/mod.rs @@ -121,8 +121,9 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): use `from_bytecode`. + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, ) .unwrap(); @@ -134,8 +135,8 @@ mod tests { nonce: 0, balance: U256::from(0x3635c9adc5dea00000u128), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, ) .unwrap(); diff --git a/crates/storage/db-common/Cargo.toml b/crates/storage/db-common/Cargo.toml index 9e4954357f84e..662d1fdb0295b 100644 --- a/crates/storage/db-common/Cargo.toml +++ b/crates/storage/db-common/Cargo.toml @@ -27,6 +27,9 @@ reth-node-types.workspace = true alloy-genesis.workspace = true alloy-primitives.workspace = true +# scroll +reth-scroll-primitives = { workspace = true, optional = true } + # misc eyre.workspace = true thiserror.workspace = true @@ -46,3 +49,6 @@ alloy-consensus.workspace = true [lints] workspace = true + +[features] +scroll = ["reth-scroll-primitives"] diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 369082adaf6cf..48fb946a111c0 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -214,8 +214,12 @@ where nonce: account.nonce.unwrap_or_default(), balance: account.balance, bytecode_hash, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode( + account.code.as_ref().unwrap_or_default(), + ), + ), }), storage, ), diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 6042b5faa8158..7400d94a89c51 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -115,6 +115,7 @@ arbitrary = [ ] optimism = ["reth-primitives/optimism", "reth-db-api/optimism"] disable-lock = [] +scroll = [] [[bench]] name = "hash_keys" diff --git a/crates/storage/db/src/implementation/mdbx/mod.rs b/crates/storage/db/src/implementation/mdbx/mod.rs index 8f9baa7d2f4e3..1d0be7574663d 100644 --- a/crates/storage/db/src/implementation/mdbx/mod.rs +++ b/crates/storage/db/src/implementation/mdbx/mod.rs @@ -1172,8 +1172,8 @@ mod tests { nonce: 18446744073709551615, bytecode_hash: Some(B256::random()), balance: U256::MAX, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some((10u64, B256::random()).into()), }; let key = Address::from_str("0xa2c122be93b0074270ebee7f6b7292c7deb45047") .expect(ERROR_ETH_ADDRESS); diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index 399e3e000b992..1755489ab1ce3 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -78,6 +78,8 @@ reth-trie = { workspace = true, features = ["test-utils"] } reth-testing-utils.workspace = true reth-ethereum-engine-primitives.workspace = true +reth-scroll-primitives.workspace = true + parking_lot.workspace = true tempfile.workspace = true assert_matches.workspace = true @@ -128,3 +130,4 @@ test-utils = [ "reth-prune-types/test-utils", "reth-stages-types/test-utils", ] +scroll = [] diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 28cfc2969fc40..39a71b924431f 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -542,20 +542,49 @@ mod tests { ) .unwrap(); - // TODO (scroll): remove at last Scroll `Account` related PR. - let acc_plain = - Account { nonce: 100, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; - let acc_at15 = - Account { nonce: 15, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; - let acc_at10 = - Account { nonce: 10, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; - let acc_at7 = - Account { nonce: 7, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; - let acc_at3 = - Account { nonce: 3, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; - - let higher_acc_plain = - Account { nonce: 4, balance: U256::ZERO, bytecode_hash: None, ..Default::default() }; + let acc_plain = Account { + nonce: 100, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + let acc_at15 = Account { + nonce: 15, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + let acc_at10 = Account { + nonce: 10, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + let acc_at7 = Account { + nonce: 7, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + let acc_at3 = Account { + nonce: 3, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + + let higher_acc_plain = Account { + nonce: 4, + balance: U256::ZERO, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; // setup tx.put::(1, AccountBeforeTx { address: ADDRESS, info: None }) diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 0008544c86714..772e7a32967cc 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -83,8 +83,13 @@ impl ExtendedAccount { /// Create new instance of extended account pub fn new(nonce: u64, balance: U256) -> Self { Self { - // TODO (scroll): remove at last Scroll `Account` related PR. - account: Account { nonce, balance, bytecode_hash: None, ..Default::default() }, + account: Account { + nonce, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }, bytecode: None, storage: Default::default(), } @@ -92,6 +97,11 @@ impl ExtendedAccount { /// Set bytecode and bytecode hash on the extended account pub fn with_bytecode(mut self, bytecode: Bytes) -> Self { + #[cfg(feature = "scroll")] + { + self.account.account_extension = + Some(reth_scroll_primitives::AccountExtension::from_bytecode(&bytecode)); + } let hash = keccak256(&bytecode); self.account.bytecode_hash = Some(hash); self.bytecode = Some(Bytecode::new_raw(bytecode)); diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index 73abb4b0e3eb0..e329e44bb5bb9 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -1417,8 +1417,8 @@ mod tests { nonce: 1, balance: U256::from(key), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; let storage = (1..11).map(|key| (B256::with_last_byte(key), U256::from(key))).collect(); @@ -1554,7 +1554,8 @@ mod tests { nonce: 56, balance: U256::from(123), bytecode_hash: Some(B256::random()), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some((10, B256::random()).into()), }; prestate.insert(address1, (account1_new, BTreeMap::default())); state.commit(HashMap::from_iter([( diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index 0616e2597109d..af5e2e8472a47 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -40,6 +40,8 @@ proptest-arbitrary-interop.workspace = true hash-db = "=0.15.2" plain_hasher = "0.2" +reth-scroll-primitives.workspace = true + [features] test-utils = [ "dep:plain_hasher", @@ -58,3 +60,4 @@ arbitrary = [ "revm-primitives/arbitrary", "reth-codecs/arbitrary" ] +scroll = [] diff --git a/crates/trie/common/src/account.rs b/crates/trie/common/src/account.rs index 6b50ee1d7a941..b6666cfb7d463 100644 --- a/crates/trie/common/src/account.rs +++ b/crates/trie/common/src/account.rs @@ -136,8 +136,10 @@ mod tests { nonce: 10, balance: U256::from(1000), bytecode_hash: Some(keccak256([0x60, 0x61])), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode(&[0x60, 0x61]) + ) }, expected_storage_root )), diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index 159f5a72110d2..67c04e0cb75d5 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -55,8 +55,11 @@ impl MultiProof { nonce: account.nonce, bytecode_hash: (account.code_hash != KECCAK_EMPTY) .then_some(account.code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + // TODO (scroll): set the extension to the correct value. + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::empty(), + ), }) } } diff --git a/crates/trie/db/Cargo.toml b/crates/trie/db/Cargo.toml index 55fa9a851b177..370ee6a33ea26 100644 --- a/crates/trie/db/Cargo.toml +++ b/crates/trie/db/Cargo.toml @@ -55,6 +55,8 @@ reth-trie = { workspace = true, features = ["test-utils"] } alloy-consensus.workspace = true +reth-scroll-primitives.workspace = true + # trie triehash = "0.8" @@ -86,3 +88,4 @@ test-utils = [ "reth-trie/test-utils", "revm/test-utils" ] +scroll = [] diff --git a/crates/trie/db/tests/proof.rs b/crates/trie/db/tests/proof.rs index 2ad2668fae294..e03be1167479e 100644 --- a/crates/trie/db/tests/proof.rs +++ b/crates/trie/db/tests/proof.rs @@ -200,8 +200,9 @@ fn holesky_deposit_contract_proof() { balance: U256::ZERO, nonce: 0, bytecode_hash: Some(B256::from_str("0x2034f79e0e33b0ae6bef948532021baceb116adf2616478703bec6b17329f1cc").unwrap()), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()) + }), storage_root: B256::from_str("0x556a482068355939c95a3412bdb21213a301483edb1b64402fb66ac9f3583599").unwrap(), proof: convert_to_proof([ diff --git a/crates/trie/db/tests/trie.rs b/crates/trie/db/tests/trie.rs index 78eee9c94d429..133dd4556a38d 100644 --- a/crates/trie/db/tests/trie.rs +++ b/crates/trie/db/tests/trie.rs @@ -150,8 +150,8 @@ fn test_empty_account() { nonce: 0, balance: U256::from(0), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, BTreeMap::from([(B256::with_last_byte(0x4), U256::from(12))]), ), @@ -163,8 +163,8 @@ fn test_empty_account() { nonce: 0, balance: U256::from(0), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }, BTreeMap::default(), ), @@ -176,8 +176,10 @@ fn test_empty_account() { nonce: 155, balance: U256::from(414241124u32), bytecode_hash: Some(keccak256("test")), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode(b"test"), + ), }, BTreeMap::from([ (B256::ZERO, U256::from(3)), @@ -201,8 +203,8 @@ fn test_empty_storage_root() { nonce: 155, balance: U256::from(414241124u32), bytecode_hash: Some(keccak256(code)), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode(&code)), }; insert_account(tx.tx_ref(), address, account, &Default::default()); tx.commit().unwrap(); @@ -227,7 +229,8 @@ fn test_storage_root() { nonce: 155, balance: U256::from(414241124u32), bytecode_hash: Some(keccak256(code)), - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode(&code)), }; insert_account(tx.tx_ref(), address, account, &storage); @@ -378,8 +381,8 @@ fn account_and_storage_trie() { nonce: 0, balance: U256::from(3).mul(ether), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; hashed_account_cursor.upsert(key1, account1).unwrap(); hash_builder.add_leaf(Nibbles::unpack(key1), &encode_account(account1, None)); @@ -404,8 +407,8 @@ fn account_and_storage_trie() { nonce: 0, balance: U256::from(2).mul(ether), bytecode_hash: Some(code_hash), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some((10, B256::random()).into()), }; hashed_account_cursor.upsert(key3, account3).unwrap(); for (hashed_slot, value) in storage { @@ -492,8 +495,8 @@ fn account_and_storage_trie() { nonce: 0, balance: U256::from(5).mul(ether), bytecode_hash: None, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), }; hashed_account_cursor.upsert(key4b, account4b).unwrap(); @@ -763,8 +766,8 @@ fn extension_node_trie( nonce: 0, balance: U256::from(1u64), bytecode_hash: Some(B256::random()), - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some((10, B256::random()).into()), }; let val = encode_account(a, None); diff --git a/testing/ef-tests/Cargo.toml b/testing/ef-tests/Cargo.toml index 2fc0c75124416..eb754cba77948 100644 --- a/testing/ef-tests/Cargo.toml +++ b/testing/ef-tests/Cargo.toml @@ -18,6 +18,7 @@ asm-keccak = [ "alloy-primitives/asm-keccak", "revm/asm-keccak", ] +scroll = [] [dependencies] reth-chainspec.workspace = true @@ -35,6 +36,8 @@ reth-revm = { workspace = true, features = ["std"] } revm = { workspace = true, features = ["secp256k1", "blst", "c-kzg"] } +reth-scroll-primitives = { workspace = true, optional = true } + alloy-rlp.workspace = true alloy-primitives.workspace = true alloy-eips.workspace = true diff --git a/testing/ef-tests/src/models.rs b/testing/ef-tests/src/models.rs index 452f4a2e22fe6..3e3a25e45a167 100644 --- a/testing/ef-tests/src/models.rs +++ b/testing/ef-tests/src/models.rs @@ -162,8 +162,10 @@ impl State { balance: account.balance, nonce: account.nonce.to::(), bytecode_hash: code_hash, - // TODO (scroll): remove at last Scroll `Account` related PR. - ..Default::default() + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &account.code, + )), }; tx.put::(address, reth_account)?; tx.put::(hashed_address, reth_account)?; diff --git a/testing/testing-utils/Cargo.toml b/testing/testing-utils/Cargo.toml index 3e0f58a7bd084..6d07043adc3f5 100644 --- a/testing/testing-utils/Cargo.toml +++ b/testing/testing-utils/Cargo.toml @@ -24,3 +24,6 @@ secp256k1 = { workspace = true, features = ["rand"] } [dev-dependencies] alloy-eips.workspace = true + +[features] +scroll = [] diff --git a/testing/testing-utils/src/generators.rs b/testing/testing-utils/src/generators.rs index 850c3aa9b48cc..32a12b044535c 100644 --- a/testing/testing-utils/src/generators.rs +++ b/testing/testing-utils/src/generators.rs @@ -386,8 +386,16 @@ pub fn random_eoa_account(rng: &mut R) -> (Address, Account) { let balance = U256::from(rng.gen::()); let addr = rng.gen(); - // TODO (scroll): remove at last Scroll `Account` related PR. - (addr, Account { nonce, balance, bytecode_hash: None, ..Default::default() }) + ( + addr, + Account { + nonce, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(Default::default()), + }, + ) } /// Generate random Externally Owned Accounts