diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 118dcf777fb4..384761ee5bf6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -152,7 +152,13 @@ jobs: with: cache-on-failure: true - uses: taiki-e/install-action@cargo-udeps - - run: cargo udeps --workspace --lib --examples --tests --benches --all-features --locked --exclude "reth-optimism-*" --exclude op-reth + # due to the scroll feature flag, we need to exclude some crates that were annotated with + # #![cfg(not(feature = "scroll))]. + - run: | + cargo udeps --workspace --lib --examples --tests --benches --all-features --locked \ + --exclude "reth-optimism-*" --exclude op-reth --exclude "example-*" --exclude reth \ + --exclude reth-e2e-test-utils --exclude reth-ethereum-payload-builder --exclude reth-exex-test-utils \ + --exclude reth-node-ethereum book: name: book diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index f9f925c686fc..c4df17279205 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -62,7 +62,8 @@ jobs: - name: Run tests run: | cargo nextest run \ - ${{ matrix.args }} --workspace --exclude ef-tests \ + ${{ matrix.args }} --workspace \ + --exclude ef-tests --no-tests=warn \ --partition hash:${{ matrix.partition }}/2 \ -E "!kind(test)" diff --git a/Cargo.lock b/Cargo.lock index 60321029b739..5c858dfa0b25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2634,8 +2634,8 @@ dependencies = [ "reth-provider", "reth-revm", "reth-scroll-primitives", + "reth-scroll-revm", "reth-stages", - "revm", "serde", "serde_json", "thiserror 1.0.69", @@ -2844,6 +2844,7 @@ dependencies = [ "reth-evm-ethereum", "reth-node-ethereum", "reth-primitives", + "reth-scroll-execution", ] [[package]] @@ -4616,7 +4617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -6469,9 +6470,9 @@ dependencies = [ "reth-primitives-traits", "reth-provider", "reth-revm", + "reth-scroll-revm", "reth-tasks", "reth-transaction-pool", - "revm", "tokio", "tracing", ] @@ -6595,6 +6596,8 @@ dependencies = [ "reth-primitives", "reth-provider", "reth-revm", + "reth-scroll-revm", + "reth-scroll-storage", "reth-stages-api", "reth-storage-errors", "reth-testing-utils", @@ -6638,10 +6641,10 @@ dependencies = [ "reth-execution-types", "reth-metrics", "reth-primitives", + "reth-scroll-revm", "reth-storage-api", "reth-testing-utils", "reth-trie", - "revm", "tokio", "tokio-stream", "tracing", @@ -6904,6 +6907,7 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "reth-prune-types", + "reth-scroll-primitives", "reth-stages-types", "reth-storage-errors", "reth-tracing", @@ -7333,6 +7337,8 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc-types-compat", + "reth-scroll-execution", + "reth-scroll-storage", "reth-trie", "revm-primitives", "serde", @@ -7500,9 +7506,9 @@ dependencies = [ "reth-primitives", "reth-provider", "reth-revm", + "reth-scroll-revm", "reth-transaction-pool", "reth-trie", - "revm", "tracing", ] @@ -7539,8 +7545,9 @@ dependencies = [ "reth-primitives-traits", "reth-prune-types", "reth-revm", + "reth-scroll-execution", + "reth-scroll-revm", "reth-storage-errors", - "revm", "revm-primitives", ] @@ -7561,6 +7568,7 @@ dependencies = [ "reth-execution-types", "reth-primitives", "reth-revm", + "reth-scroll-execution", "reth-scroll-primitives", "reth-testing-utils", "revm-primitives", @@ -7595,8 +7603,8 @@ dependencies = [ "reth-execution-errors", "reth-primitives", "reth-primitives-traits", + "reth-scroll-revm", "reth-trie", - "revm", "serde", "serde_with", ] @@ -7632,6 +7640,7 @@ dependencies = [ "reth-provider", "reth-prune-types", "reth-revm", + "reth-scroll-storage", "reth-stages-api", "reth-tasks", "reth-testing-utils", @@ -7722,6 +7731,9 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc-api", + "reth-scroll-execution", + "reth-scroll-revm", + "reth-scroll-storage", "reth-tracing", "reth-trie", "serde", @@ -8137,11 +8149,11 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc", + "reth-scroll-revm", "reth-tasks", "reth-tracing", "reth-transaction-pool", "reth-trie-db", - "revm", "serde_json", "tokio", ] @@ -8313,7 +8325,8 @@ dependencies = [ "reth-primitives", "reth-prune-types", "reth-revm", - "revm", + "reth-scroll-execution", + "reth-scroll-revm", "revm-primitives", "tracing", ] @@ -8372,10 +8385,10 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc-server-types", + "reth-scroll-revm", "reth-tracing", "reth-transaction-pool", "reth-trie-db", - "revm", "serde", "serde_json", "tokio", @@ -8410,9 +8423,9 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc-types-compat", + "reth-scroll-revm", "reth-transaction-pool", "reth-trie", - "revm", "sha2 0.10.8", "thiserror 1.0.69", "tracing", @@ -8473,9 +8486,9 @@ dependencies = [ "reth-rpc-eth-api", "reth-rpc-eth-types", "reth-rpc-server-types", + "reth-scroll-revm", "reth-tasks", "reth-transaction-pool", - "revm", "serde_json", "thiserror 1.0.69", "tokio", @@ -8509,7 +8522,7 @@ dependencies = [ "reth-payload-builder-primitives", "reth-payload-primitives", "reth-primitives", - "revm", + "reth-scroll-revm", "tokio", "tokio-stream", "tracing", @@ -8679,13 +8692,13 @@ dependencies = [ "reth-primitives-traits", "reth-prune-types", "reth-scroll-primitives", + "reth-scroll-revm", "reth-stages-types", "reth-storage-api", "reth-storage-errors", "reth-testing-utils", "reth-trie", "reth-trie-db", - "revm", "strum", "tempfile", "tokio", @@ -8755,10 +8768,11 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "reth-prune-types", + "reth-scroll-primitives", + "reth-scroll-revm", "reth-storage-api", "reth-storage-errors", "reth-trie", - "revm", ] [[package]] @@ -8816,11 +8830,12 @@ dependencies = [ "reth-rpc-eth-types", "reth-rpc-server-types", "reth-rpc-types-compat", + "reth-scroll-revm", + "reth-scroll-storage", "reth-tasks", "reth-testing-utils", "reth-transaction-pool", "reth-trie", - "revm", "revm-inspectors", "revm-primitives", "serde", @@ -8997,10 +9012,12 @@ dependencies = [ "reth-rpc-eth-types", "reth-rpc-server-types", "reth-rpc-types-compat", + "reth-scroll-execution", + "reth-scroll-revm", + "reth-scroll-storage", "reth-tasks", "reth-transaction-pool", "reth-trie", - "revm", "revm-inspectors", "revm-primitives", "tokio", @@ -9034,11 +9051,12 @@ dependencies = [ "reth-revm", "reth-rpc-server-types", "reth-rpc-types-compat", + "reth-scroll-revm", + "reth-scroll-storage", "reth-storage-api", "reth-tasks", "reth-transaction-pool", "reth-trie", - "revm", "revm-inspectors", "revm-primitives", "schnellru", @@ -9104,10 +9122,7 @@ dependencies = [ name = "reth-scroll-execution" version = "1.1.2" dependencies = [ - "auto_impl", "reth-revm", - "reth-scroll-primitives", - "reth-scroll-revm", "reth-scroll-storage", ] @@ -9188,6 +9203,7 @@ dependencies = [ "reth-prune-types", "reth-revm", "reth-scroll-primitives", + "reth-scroll-storage", "reth-stages-api", "reth-static-file", "reth-storage-errors", @@ -9398,10 +9414,10 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "reth-provider", + "reth-scroll-revm", "reth-storage-api", "reth-tasks", "reth-tracing", - "revm", "rustc-hash 2.0.0", "schnellru", "serde", @@ -9433,10 +9449,11 @@ dependencies = [ "reth-execution-errors", "reth-metrics", "reth-primitives", + "reth-primitives-traits", + "reth-scroll-revm", "reth-stages-types", "reth-storage-errors", "reth-trie-common", - "revm", "serde", "serde_json", "serde_with", @@ -9465,7 +9482,7 @@ dependencies = [ "reth-codecs", "reth-primitives-traits", "reth-scroll-primitives", - "revm-primitives", + "reth-scroll-revm", "serde", ] @@ -9488,10 +9505,10 @@ dependencies = [ "reth-primitives", "reth-provider", "reth-scroll-primitives", + "reth-scroll-revm", "reth-storage-errors", "reth-trie", "reth-trie-common", - "revm", "serde", "serde_json", "similar-asserts", @@ -11299,7 +11316,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3637e734239e12ab152cd269302500bd063f37624ee210cd04b4936ed671f3b1" dependencies = [ "cc", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 74762824cbee..a9a188ec2c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -429,7 +429,7 @@ reth-trie-db = { path = "crates/trie/db" } reth-trie-parallel = { path = "crates/trie/parallel" } # revm -revm = { version = "18.0.0", features = ["std"], default-features = false } +revm = { package = "reth-scroll-revm", path = "crates/scroll/revm", default-features = false } revm-inspectors = "0.11.0" revm-primitives = { version = "14.0.0", features = [ "std", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index a152bea2681e..437d11b5ad02 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -120,6 +120,7 @@ jemalloc-prof = [ "reth-cli-util/jemalloc-prof" ] tracy-allocator = ["reth-cli-util/tracy-allocator"] +scroll = [] min-error-logs = ["tracing/release_max_level_error"] min-warn-logs = ["tracing/release_max_level_warn"] diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 53c592063eca..dba3ff77c8fa 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -26,6 +26,9 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] pub mod cli; pub mod commands; diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index e146912c06f9..19053b8a2073 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -1,4 +1,7 @@ #![allow(missing_docs)] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] #[global_allocator] static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator(); diff --git a/crates/blockchain-tree/Cargo.toml b/crates/blockchain-tree/Cargo.toml index 3fa6de2b402c..1fa7854aee59 100644 --- a/crates/blockchain-tree/Cargo.toml +++ b/crates/blockchain-tree/Cargo.toml @@ -34,6 +34,9 @@ reth-node-types.workspace = true alloy-primitives.workspace = true alloy-eips.workspace = true +# scroll +reth-scroll-storage = { workspace = true, optional = true } + # common parking_lot.workspace = true tracing.workspace = true @@ -62,6 +65,7 @@ parking_lot.workspace = true assert_matches.workspace = true alloy-genesis.workspace = true alloy-consensus.workspace = true +revm.workspace = true [features] test-utils = [ @@ -76,12 +80,27 @@ test-utils = [ "reth-db-api/test-utils", "reth-provider/test-utils", "reth-trie-db/test-utils", - "reth-trie/test-utils" + "reth-trie/test-utils", + "revm/test-utils" ] optimism = [ "reth-primitives/optimism", "reth-provider/optimism", "reth-execution-types/optimism", "reth-db/optimism", - "reth-db-api/optimism" + "reth-db-api/optimism", + "revm/optimism" +] +scroll = [ + "reth-evm/scroll", + "reth-primitives/scroll", + "reth-revm/scroll", + "reth-execution-types/scroll", + "reth-db/scroll", + "reth-provider/scroll", + "reth-trie-db/scroll", + "reth-testing-utils/scroll", + "reth-trie/scroll", + "revm/scroll", + "reth-scroll-storage/scroll" ] diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index d2ff0f5c8445..f74361320d1a 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1400,9 +1400,9 @@ mod tests { }, ProviderFactory, StorageLocation, }; - use reth_revm::primitives::AccountInfo; use reth_stages_api::StageCheckpoint; use reth_trie::{root::state_root_unhashed, StateRoot}; + use revm::AccountInfo; use std::collections::HashMap; fn setup_externals( diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 6ac39c316702..80f8c7a4b80b 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -21,7 +21,6 @@ use reth_provider::{ DBProvider, FullExecutionDataProvider, ProviderError, StateRootProvider, TryIntoHistoricalStateProvider, }; -use reth_revm::database::StateProviderDatabase; use reth_trie::{updates::TrieUpdates, HashedPostState, TrieInput}; use reth_trie_parallel::root::ParallelStateRoot; use std::{ @@ -204,7 +203,10 @@ impl AppendableChain { let provider = BundleStateProvider::new(state_provider, bundle_state_data_provider); - let db = StateProviderDatabase::new(&provider); + #[cfg(not(feature = "scroll"))] + let db = reth_revm::database::StateProviderDatabase::new(&provider); + #[cfg(feature = "scroll")] + let db = reth_scroll_storage::ScrollStateProviderDatabase::new(&provider); let executor = externals.executor_factory.executor(db); let block_hash = block.hash(); let block = block.unseal(); diff --git a/crates/blockchain-tree/src/lib.rs b/crates/blockchain-tree/src/lib.rs index 3f501bead071..29e747a40a87 100644 --- a/crates/blockchain-tree/src/lib.rs +++ b/crates/blockchain-tree/src/lib.rs @@ -18,6 +18,8 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use reth_revm as _; + /// Re-export of the blockchain tree API. pub use reth_blockchain_tree_api::*; diff --git a/crates/e2e-test-utils/Cargo.toml b/crates/e2e-test-utils/Cargo.toml index 9c40e2ba99d2..e33690d45861 100644 --- a/crates/e2e-test-utils/Cargo.toml +++ b/crates/e2e-test-utils/Cargo.toml @@ -50,3 +50,6 @@ alloy-network.workspace = true alloy-consensus = { workspace = true, features = ["kzg"] } tracing.workspace = true derive_more.workspace = true + +[features] +scroll = [] diff --git a/crates/e2e-test-utils/src/lib.rs b/crates/e2e-test-utils/src/lib.rs index 73a7e39f1a49..2c41e30ce793 100644 --- a/crates/e2e-test-utils/src/lib.rs +++ b/crates/e2e-test-utils/src/lib.rs @@ -1,5 +1,9 @@ //! Utilities for end-to-end tests. +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + use std::sync::Arc; use node::NodeTestContext; diff --git a/crates/engine/invalid-block-hooks/Cargo.toml b/crates/engine/invalid-block-hooks/Cargo.toml index 462f0762a9e4..35afad8a4d8e 100644 --- a/crates/engine/invalid-block-hooks/Cargo.toml +++ b/crates/engine/invalid-block-hooks/Cargo.toml @@ -28,6 +28,11 @@ alloy-rlp.workspace = true alloy-rpc-types-debug.workspace = true alloy-consensus.workspace = true +# scroll +reth-scroll-execution.workspace = true +reth-scroll-storage = { workspace = true, optional = true } +reth-scroll-revm = { workspace = true, optional = true } + # async futures.workspace = true @@ -37,3 +42,14 @@ jsonrpsee.workspace = true pretty_assertions = "1.4" serde.workspace = true serde_json.workspace = true + +[features] +scroll = [ + "reth-evm/scroll", + "reth-primitives/scroll", + "reth-revm/scroll", + "reth-provider/scroll", + "reth-trie/scroll", + "reth-scroll-storage", + "reth-scroll-revm" +] diff --git a/crates/engine/invalid-block-hooks/src/witness.rs b/crates/engine/invalid-block-hooks/src/witness.rs index 4e92411ea128..a1affdeda349 100644 --- a/crates/engine/invalid-block-hooks/src/witness.rs +++ b/crates/engine/invalid-block-hooks/src/witness.rs @@ -13,12 +13,12 @@ use reth_evm::{ use reth_primitives::{Receipt, SealedBlockWithSenders, SealedHeader}; use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory}; use reth_revm::{ - database::StateProviderDatabase, db::states::bundle_state::BundleRetention, primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg}, DatabaseCommit, StateBuilder, }; use reth_rpc_api::DebugApiClient; +use reth_scroll_execution::FinalizeExecution; use reth_tracing::tracing::warn; use reth_trie::{updates::TrieUpdates, HashedPostState, HashedStorage}; use serde::Serialize; @@ -68,12 +68,12 @@ where // TODO(alexey): unify with `DebugApi::debug_execution_witness` // Setup database. - let mut db = StateBuilder::new() - .with_database(StateProviderDatabase::new( - self.provider.state_by_block_hash(parent_header.hash())?, - )) - .with_bundle_update() - .build(); + let provider = self.provider.state_by_block_hash(parent_header.hash())?; + #[cfg(not(feature = "scroll"))] + let state = reth_revm::database::StateProviderDatabase::new(provider); + #[cfg(feature = "scroll")] + let state = reth_scroll_storage::ScrollStateProviderDatabase::new(provider); + let mut db = StateBuilder::new().with_database(state).with_bundle_update().build(); // Setup environment for the execution. let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default()); @@ -121,7 +121,7 @@ where db.merge_transitions(BundleRetention::Reverts); // Take the bundle state - let mut bundle_state = db.take_bundle(); + let mut bundle_state = db.finalize(); // Initialize a map of preimages. let mut state_preimages = HashMap::default(); @@ -133,9 +133,17 @@ where let mut hashed_state = HashedPostState::from_bundle_state(&bundle_state.state); for (address, account) in db.cache.accounts { let hashed_address = keccak256(address); - hashed_state - .accounts - .insert(hashed_address, account.account.as_ref().map(|a| a.info.clone().into())); + #[cfg(feature = "scroll")] + let hashed_account = account.account.as_ref().map(|a| { + Into::::into(( + a.info.clone(), + &db.database.post_execution_context, + )) + .into() + }); + #[cfg(not(feature = "scroll"))] + let hashed_account = account.account.as_ref().map(|a| a.info.clone().into()); + hashed_state.accounts.insert(hashed_address, hashed_account); let storage = hashed_state .storages diff --git a/crates/engine/primitives/Cargo.toml b/crates/engine/primitives/Cargo.toml index 42cbd932d45b..94f97e308f41 100644 --- a/crates/engine/primitives/Cargo.toml +++ b/crates/engine/primitives/Cargo.toml @@ -30,3 +30,10 @@ futures.workspace = true # misc serde.workspace = true thiserror.workspace = true + +[features] +scroll = [ + "reth-execution-types/scroll", + "reth-primitives/scroll", + "reth-trie/scroll" +] diff --git a/crates/engine/util/Cargo.toml b/crates/engine/util/Cargo.toml index 6eb22340ec10..310838a43cec 100644 --- a/crates/engine/util/Cargo.toml +++ b/crates/engine/util/Cargo.toml @@ -31,6 +31,10 @@ alloy-primitives.workspace = true alloy-rpc-types-engine.workspace = true alloy-consensus.workspace = true +# scroll +reth-scroll-execution.workspace = true +reth-scroll-storage = { workspace = true, optional = true } + # async tokio = { workspace = true, default-features = false } tokio-util.workspace = true @@ -54,3 +58,4 @@ optimism = [ "reth-provider/optimism", "revm-primitives/optimism", ] +scroll = ["reth-scroll-storage"] diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index fd80fa9e1658..8467bba3fd2c 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -21,11 +21,11 @@ use reth_payload_validator::ExecutionPayloadValidator; use reth_primitives::{proofs, Block, BlockBody, Receipt, Receipts}; use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory}; use reth_revm::{ - database::StateProviderDatabase, db::{states::bundle_state::BundleRetention, State}, DatabaseCommit, }; use reth_rpc_types_compat::engine::payload::block_to_payload; +use reth_scroll_execution::FinalizeExecution; use reth_trie::HashedPostState; use revm_primitives::{ calc_excess_blob_gas, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, @@ -292,10 +292,11 @@ where // Configure state let state_provider = provider.state_by_block_hash(reorg_target.parent_hash)?; - let mut state = State::builder() - .with_database_ref(StateProviderDatabase::new(&state_provider)) - .with_bundle_update() - .build(); + #[cfg(not(feature = "scroll"))] + let mut db = reth_revm::database::StateProviderDatabase::new(&state_provider); + #[cfg(feature = "scroll")] + let mut db = reth_scroll_storage::ScrollStateProviderDatabase::new(&state_provider); + let mut state = State::builder().with_database(&mut db).with_bundle_update().build(); // Configure environments let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default()); @@ -377,9 +378,9 @@ where // and 4788 contract call state.merge_transitions(BundleRetention::PlainState); - let outcome: ExecutionOutcome = ExecutionOutcome::new( - state.take_bundle(), - Receipts::from(vec![receipts]), + let outcome = ExecutionOutcome::new( + state.finalize(), + Receipts::::from(vec![receipts]), reorg_target.number, Default::default(), ); diff --git a/crates/ethereum/evm/Cargo.toml b/crates/ethereum/evm/Cargo.toml index 0dd0ab5a02ab..52555b23abe3 100644 --- a/crates/ethereum/evm/Cargo.toml +++ b/crates/ethereum/evm/Cargo.toml @@ -23,6 +23,9 @@ reth-consensus.workspace = true # Ethereum revm-primitives.workspace = true +# scroll +reth-scroll-execution.workspace = true + # Alloy alloy-primitives.workspace = true alloy-eips.workspace = true @@ -54,4 +57,7 @@ std = [ "revm-primitives/std", "secp256k1/std" ] -scroll = [] +scroll = [ + "reth-primitives/scroll", + "reth-testing-utils/scroll", +] diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 6aa7b2ccca6a..fe2f51380114 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -21,7 +21,8 @@ use reth_evm::{ ConfigureEvm, TxEnvOverrides, }; use reth_primitives::{BlockWithSenders, Receipt}; -use reth_revm::db::State; +use reth_revm::db::{BundleState, State}; +use reth_scroll_execution::FinalizeExecution; use revm_primitives::{ db::{Database, DatabaseCommit}, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, U256, @@ -60,12 +61,15 @@ where EvmConfig: Clone + Unpin + Sync + Send + 'static + ConfigureEvm
, { - type Strategy + Display>> = - EthExecutionStrategy; + type Strategy + Display>> + = EthExecutionStrategy + where + State: FinalizeExecution; fn create_strategy(&self, db: DB) -> Self::Strategy where DB: Database + Display>, + State: FinalizeExecution, { let state = State::builder().with_database(db).with_bundle_update().without_state_clear().build(); @@ -128,6 +132,7 @@ where impl BlockExecutionStrategy for EthExecutionStrategy where DB: Database + Display>, + State: FinalizeExecution, EvmConfig: ConfigureEvm
, { type Error = BlockExecutionError; diff --git a/crates/ethereum/node/Cargo.toml b/crates/ethereum/node/Cargo.toml index 6ecd5437bfb0..830c648f9b96 100644 --- a/crates/ethereum/node/Cargo.toml +++ b/crates/ethereum/node/Cargo.toml @@ -79,3 +79,4 @@ test-utils = [ "revm/test-utils", "reth-evm/test-utils", ] +scroll = [] diff --git a/crates/ethereum/node/src/lib.rs b/crates/ethereum/node/src/lib.rs index 421cee37fb03..e86240a74334 100644 --- a/crates/ethereum/node/src/lib.rs +++ b/crates/ethereum/node/src/lib.rs @@ -7,6 +7,9 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use reth_revm as _; use revm as _; diff --git a/crates/ethereum/node/tests/e2e/main.rs b/crates/ethereum/node/tests/e2e/main.rs index 4ed8ac5fcb63..3459db247654 100644 --- a/crates/ethereum/node/tests/e2e/main.rs +++ b/crates/ethereum/node/tests/e2e/main.rs @@ -1,4 +1,7 @@ #![allow(missing_docs)] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] mod blobs; mod dev; diff --git a/crates/ethereum/node/tests/it/main.rs b/crates/ethereum/node/tests/it/main.rs index 0f85adda31d0..18240081f1e4 100644 --- a/crates/ethereum/node/tests/it/main.rs +++ b/crates/ethereum/node/tests/it/main.rs @@ -1,4 +1,7 @@ #![allow(missing_docs)] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] mod builder; mod exex; diff --git a/crates/ethereum/payload/Cargo.toml b/crates/ethereum/payload/Cargo.toml index 4e0880d1d153..2d8d25c3c22d 100644 --- a/crates/ethereum/payload/Cargo.toml +++ b/crates/ethereum/payload/Cargo.toml @@ -39,3 +39,6 @@ alloy-primitives.workspace = true # misc tracing.workspace = true + +[features] +scroll = [] diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index b2f78da6de97..ee99057f3d53 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -8,6 +8,9 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![allow(clippy::useless_let_if_seq)] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH}; use alloy_eips::{eip4844::MAX_DATA_GAS_PER_BLOCK, eip7685::Requests, merge::BEACON_NONCE}; diff --git a/crates/evm/Cargo.toml b/crates/evm/Cargo.toml index 9d6a616af983..155e54fa90d7 100644 --- a/crates/evm/Cargo.toml +++ b/crates/evm/Cargo.toml @@ -24,9 +24,12 @@ reth-prune-types.workspace = true reth-revm.workspace = true reth-storage-errors.workspace = true -revm.workspace = true revm-primitives.workspace = true +# scroll +revm.workspace = true +reth-scroll-execution.workspace = true + # alloy alloy-primitives.workspace = true alloy-eips.workspace = true @@ -66,5 +69,14 @@ test-utils = [ "reth-primitives-traits/test-utils", "reth-revm/test-utils", "revm/test-utils", - "reth-prune-types/test-utils" + "reth-prune-types/test-utils", + "reth-scroll-execution/test-utils" +] +scroll = [ + "revm/scroll", + "reth-primitives-traits/scroll", + "reth-primitives/scroll", + "reth-revm/scroll", + "reth-execution-types/scroll", + "reth-scroll-execution/scroll" ] diff --git a/crates/evm/execution-types/Cargo.toml b/crates/evm/execution-types/Cargo.toml index 4d2d8214ff98..2a1725642fee 100644 --- a/crates/evm/execution-types/Cargo.toml +++ b/crates/evm/execution-types/Cargo.toml @@ -58,3 +58,7 @@ std = [ "serde?/std", "reth-primitives-traits/std", ] +scroll = [ + "revm/scroll", + "reth-primitives/scroll" +] diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index 412269ace9cd..d6a9ddfd8250 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -774,10 +774,26 @@ mod tests { let address3 = Address::random(); // Set up account info with some changes - let account_info1 = - AccountInfo { nonce: 1, balance: U256::from(100), code_hash: B256::ZERO, code: None }; - let account_info2 = - AccountInfo { nonce: 2, balance: U256::from(200), code_hash: B256::ZERO, code: None }; + let account_info1 = AccountInfo { + nonce: 1, + balance: U256::from(100), + code_hash: B256::ZERO, + code: None, + #[cfg(feature = "scroll")] + code_size: 0, + #[cfg(feature = "scroll")] + poseidon_code_hash: B256::ZERO, + }; + let account_info2 = AccountInfo { + nonce: 2, + balance: U256::from(200), + code_hash: B256::ZERO, + code: None, + #[cfg(feature = "scroll")] + code_size: 0, + #[cfg(feature = "scroll")] + poseidon_code_hash: B256::ZERO, + }; // Set up the bundle state with these accounts let mut bundle_state = BundleState::default(); diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 85bc7e7f9a79..167a89dc42d4 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -12,27 +12,33 @@ use reth_execution_errors::BlockExecutionError; use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome}; use reth_primitives::{BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; +use reth_scroll_execution::FinalizeExecution; use reth_storage_errors::provider::ProviderError; +use revm::{db::BundleState, State}; use revm_primitives::db::Database; // re-export Either pub use futures_util::future::Either; -use revm::State; impl BlockExecutorProvider for Either where A: BlockExecutorProvider, B: BlockExecutorProvider, { - type Executor + Display>> = - Either, B::Executor>; + type Executor + Display>> + = Either, B::Executor> + where + State: FinalizeExecution; - type BatchExecutor + Display>> = - Either, B::BatchExecutor>; + type BatchExecutor + Display>> + = Either, B::BatchExecutor> + where + State: FinalizeExecution; fn executor(&self, db: DB) -> Self::Executor where DB: Database + Display>, + State: FinalizeExecution, { match self { Self::Left(a) => Either::Left(a.executor(db)), @@ -43,6 +49,7 @@ where fn batch_executor(&self, db: DB) -> Self::BatchExecutor where DB: Database + Display>, + State: FinalizeExecution, { match self { Self::Left(a) => Either::Left(a.batch_executor(db)), diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 42c756f4d93f..1e157b83bf1c 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -16,6 +16,7 @@ use reth_consensus::ConsensusError; use reth_primitives::{BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_revm::batch::BlockBatchRecord; +use reth_scroll_execution::FinalizeExecution; use revm::{ db::{states::bundle_state::BundleRetention, BundleState}, State, @@ -146,7 +147,9 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, Output = BlockExecutionOutput, Error = BlockExecutionError, - >; + > + where + State: FinalizeExecution; /// An executor that can execute a batch of blocks given a database. type BatchExecutor + Display>>: for<'a> BatchExecutor< @@ -154,14 +157,17 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, Output = ExecutionOutcome, Error = BlockExecutionError, - >; + > + where + State: FinalizeExecution; /// Creates a new executor for single block execution. /// /// This is used to execute a single block and get the changed state. fn executor(&self, db: DB) -> Self::Executor where - DB: Database + Display>; + DB: Database + Display>, + State: FinalizeExecution; /// Creates a new batch executor with the given database and pruning modes. /// @@ -169,7 +175,8 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { /// during historical sync which involves executing multiple blocks in sequence. fn batch_executor(&self, db: DB) -> Self::BatchExecutor where - DB: Database + Display>; + DB: Database + Display>, + State: FinalizeExecution; } /// Helper type for the output of executing a block. @@ -185,6 +192,7 @@ pub struct ExecuteOutput { pub trait BlockExecutionStrategy where DB: Database, + State: FinalizeExecution, { /// The error type returned by this strategy's methods. type Error: From + core::error::Error; @@ -226,7 +234,7 @@ where /// Returns the final bundle state. fn finish(&mut self) -> BundleState { self.state_mut().merge_transitions(BundleRetention::Reverts); - self.state_mut().take_bundle() + self.state_mut().finalize() } /// Validate a block with regard to execution results. @@ -246,12 +254,15 @@ pub trait BlockExecutionStrategyFactory: Send + Sync + Clone + Unpin + 'static { type Strategy + Display>>: BlockExecutionStrategy< DB, Error = BlockExecutionError, - >; + > + where + State: FinalizeExecution; /// Creates a strategy using the give database. fn create_strategy(&self, db: DB) -> Self::Strategy where - DB: Database + Display>; + DB: Database + Display>, + State: FinalizeExecution; } impl Clone for BasicBlockExecutorProvider @@ -280,15 +291,20 @@ impl BlockExecutorProvider for BasicBlockExecutorProvider where F: BlockExecutionStrategyFactory, { - type Executor + Display>> = - BasicBlockExecutor, DB>; + type Executor + Display>> + = BasicBlockExecutor, DB> + where + State: FinalizeExecution; - type BatchExecutor + Display>> = - BasicBatchExecutor, DB>; + type BatchExecutor + Display>> + = BasicBatchExecutor, DB> + where + State: FinalizeExecution; fn executor(&self, db: DB) -> Self::Executor where DB: Database + Display>, + State: FinalizeExecution, { let strategy = self.strategy_factory.create_strategy(db); BasicBlockExecutor::new(strategy) @@ -297,6 +313,7 @@ where fn batch_executor(&self, db: DB) -> Self::BatchExecutor where DB: Database + Display>, + State: FinalizeExecution, { let strategy = self.strategy_factory.create_strategy(db); let batch_record = BlockBatchRecord::default(); @@ -311,6 +328,7 @@ pub struct BasicBlockExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Block execution strategy. pub(crate) strategy: S, @@ -321,6 +339,7 @@ impl BasicBlockExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Creates a new `BasicBlockExecutor` with the given strategy. pub const fn new(strategy: S) -> Self { @@ -332,6 +351,7 @@ impl Executor for BasicBlockExecutor where S: BlockExecutionStrategy, DB: Database + Display>, + State: FinalizeExecution, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = BlockExecutionOutput; @@ -408,6 +428,7 @@ pub struct BasicBatchExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Batch execution strategy. pub(crate) strategy: S, @@ -420,6 +441,7 @@ impl BasicBatchExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Creates a new `BasicBatchExecutor` with the given strategy. pub const fn new(strategy: S, batch_record: BlockBatchRecord) -> Self { @@ -431,6 +453,7 @@ impl BatchExecutor for BasicBatchExecutor where S: BlockExecutionStrategy, DB: Database + Display>, + State: FinalizeExecution, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = ExecutionOutcome; @@ -466,7 +489,7 @@ where fn finalize(mut self) -> Self::Output { ExecutionOutcome::new( - self.strategy.state_mut().take_bundle(), + self.strategy.state_mut().finalize(), self.batch_record.take_receipts(), self.batch_record.first_block().unwrap_or_default(), self.batch_record.take_requests(), @@ -499,12 +522,19 @@ mod tests { struct TestExecutorProvider; impl BlockExecutorProvider for TestExecutorProvider { - type Executor + Display>> = TestExecutor; - type BatchExecutor + Display>> = TestExecutor; + type Executor + Display>> + = TestExecutor + where + State: FinalizeExecution; + type BatchExecutor + Display>> + = TestExecutor + where + State: FinalizeExecution; fn executor(&self, _db: DB) -> Self::Executor where DB: Database + Display>, + State: FinalizeExecution, { TestExecutor(PhantomData) } @@ -512,6 +542,7 @@ mod tests { fn batch_executor(&self, _db: DB) -> Self::BatchExecutor where DB: Database + Display>, + State: FinalizeExecution, { TestExecutor(PhantomData) } @@ -596,12 +627,15 @@ mod tests { } impl BlockExecutionStrategyFactory for TestExecutorStrategyFactory { - type Strategy + Display>> = - TestExecutorStrategy; + type Strategy + Display>> + = TestExecutorStrategy + where + State: FinalizeExecution; fn create_strategy(&self, db: DB) -> Self::Strategy where DB: Database + Display>, + State: FinalizeExecution, { let state = State::builder() .with_database(db) @@ -625,6 +659,7 @@ mod tests { impl BlockExecutionStrategy for TestExecutorStrategy where DB: Database, + State: FinalizeExecution, { type Error = BlockExecutionError; diff --git a/crates/evm/src/noop.rs b/crates/evm/src/noop.rs index 4fdc6d367a27..c0ad60b7fc2b 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -6,8 +6,9 @@ use reth_execution_errors::BlockExecutionError; use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome}; use reth_primitives::{BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; +use reth_scroll_execution::FinalizeExecution; use reth_storage_errors::provider::ProviderError; -use revm::State; +use revm::{db::BundleState, State}; use revm_primitives::db::Database; use crate::{ @@ -23,13 +24,20 @@ const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop"; pub struct NoopBlockExecutorProvider; impl BlockExecutorProvider for NoopBlockExecutorProvider { - type Executor + Display>> = Self; + type Executor + Display>> + = Self + where + State: FinalizeExecution; - type BatchExecutor + Display>> = Self; + type BatchExecutor + Display>> + = Self + where + State: FinalizeExecution; fn executor(&self, _: DB) -> Self::Executor where DB: Database + Display>, + State: FinalizeExecution, { Self } @@ -37,6 +45,7 @@ impl BlockExecutorProvider for NoopBlockExecutorProvider { fn batch_executor(&self, _: DB) -> Self::BatchExecutor where DB: Database + Display>, + State: FinalizeExecution, { Self } diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index a4dc906494ce..b3f338fa856e 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -14,8 +14,9 @@ use reth_execution_errors::BlockExecutionError; use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockWithSenders, Receipt, Receipts}; use reth_prune_types::PruneModes; +use reth_scroll_execution::FinalizeExecution; use reth_storage_errors::provider::ProviderError; -use revm::State; +use revm::{db::BundleState, State}; use revm_primitives::db::Database; use std::{fmt::Display, sync::Arc}; @@ -33,13 +34,20 @@ impl MockExecutorProvider { } impl BlockExecutorProvider for MockExecutorProvider { - type Executor + Display>> = Self; + type Executor + Display>> + = Self + where + State: FinalizeExecution; - type BatchExecutor + Display>> = Self; + type BatchExecutor + Display>> + = Self + where + State: FinalizeExecution; fn executor(&self, _: DB) -> Self::Executor where DB: Database + Display>, + State: FinalizeExecution, { self.clone() } @@ -47,6 +55,7 @@ impl BlockExecutorProvider for MockExecutorProvider { fn batch_executor(&self, _: DB) -> Self::BatchExecutor where DB: Database + Display>, + State: FinalizeExecution, { self.clone() } @@ -120,6 +129,7 @@ impl BasicBlockExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Provides safe read access to the state pub fn with_state(&self, f: F) -> R @@ -142,6 +152,7 @@ impl BasicBatchExecutor where S: BlockExecutionStrategy, DB: Database, + State: FinalizeExecution, { /// Provides safe read access to the state pub fn with_state(&self, f: F) -> R diff --git a/crates/exex/exex/Cargo.toml b/crates/exex/exex/Cargo.toml index 3cbeb115b066..be783543f950 100644 --- a/crates/exex/exex/Cargo.toml +++ b/crates/exex/exex/Cargo.toml @@ -34,6 +34,9 @@ reth-stages-api.workspace = true reth-tasks.workspace = true reth-tracing.workspace = true +# scroll +reth-scroll-storage = { workspace = true, optional = true } + # alloy alloy-primitives.workspace = true alloy-eips.workspace = true @@ -81,3 +84,17 @@ serde = [ "secp256k1/serde", "reth-primitives-traits/serde", ] +scroll = [ + "reth-node-core/scroll", + "reth-evm/scroll", + "reth-primitives/scroll", + "reth-provider/scroll", + "reth-evm-ethereum/scroll", + "reth-testing-utils/scroll", + "reth-revm/scroll", + "reth-primitives-traits/scroll", + "reth-node-api/scroll", + "reth-blockchain-tree/scroll", + "reth-db-common/scroll", + "reth-scroll-storage/scroll" +] diff --git a/crates/exex/exex/src/backfill/job.rs b/crates/exex/exex/src/backfill/job.rs index 77a7b50477b0..a4754ac607f8 100644 --- a/crates/exex/exex/src/backfill/job.rs +++ b/crates/exex/exex/src/backfill/job.rs @@ -72,9 +72,15 @@ where "Executing block range" ); - let mut executor = self.executor.batch_executor(StateProviderDatabase::new( + #[cfg(not(feature = "scroll"))] + let db = StateProviderDatabase::new( self.provider.history_by_block_number(self.range.start().saturating_sub(1))?, - )); + ); + #[cfg(feature = "scroll")] + let db = reth_scroll_storage::ScrollStateProviderDatabase::new( + self.provider.history_by_block_number(self.range.start().saturating_sub(1))?, + ); + let mut executor = self.executor.batch_executor(db); executor.set_prune_modes(self.prune_modes.clone()); let mut fetch_block_duration = Duration::default(); diff --git a/crates/exex/test-utils/Cargo.toml b/crates/exex/test-utils/Cargo.toml index 6e5af981b317..56701b7ebb27 100644 --- a/crates/exex/test-utils/Cargo.toml +++ b/crates/exex/test-utils/Cargo.toml @@ -45,3 +45,6 @@ eyre.workspace = true rand.workspace = true tempfile.workspace = true thiserror.workspace = true + +[features] +scroll = [] diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index 5b2267505c57..4e1491c8aa0e 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -7,6 +7,9 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use std::{ fmt::Debug, diff --git a/crates/node/api/Cargo.toml b/crates/node/api/Cargo.toml index ab4595d33624..8279a8325229 100644 --- a/crates/node/api/Cargo.toml +++ b/crates/node/api/Cargo.toml @@ -29,3 +29,11 @@ alloy-rpc-types-engine.workspace = true alloy-consensus.workspace = true eyre.workspace = true + +[features] +scroll = [ + "reth-provider/scroll", + "reth-evm/scroll", + "reth-node-core/scroll", + "reth-engine-primitives/scroll" +] diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index c667a56293c1..b24430982025 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -80,6 +80,11 @@ optimism = ["reth-primitives/optimism", "reth-db/optimism"] # Features for vergen to generate correct env vars jemalloc = ["reth-cli-util/jemalloc"] asm-keccak = ["reth-primitives/asm-keccak", "alloy-primitives/asm-keccak"] +scroll = [ + "reth-primitives/scroll", + "reth-db/scroll", + "reth-rpc-eth-types/scroll", +] [build-dependencies] vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] } diff --git a/crates/optimism/evm/Cargo.toml b/crates/optimism/evm/Cargo.toml index 987b3d3ac4ed..901d9c31534e 100644 --- a/crates/optimism/evm/Cargo.toml +++ b/crates/optimism/evm/Cargo.toml @@ -33,6 +33,9 @@ reth-optimism-consensus.workspace = true reth-optimism-chainspec.workspace = true reth-optimism-forks.workspace = true +# scroll +reth-scroll-execution.workspace = true + # revm revm.workspace = true revm-primitives.workspace = true diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 042b8e291934..24ed78806513 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -22,6 +22,8 @@ use reth_optimism_consensus::validate_block_post_execution; use reth_optimism_forks::OpHardfork; use reth_primitives::{BlockWithSenders, Receipt, TxType}; use reth_revm::{Database, State}; +use reth_scroll_execution::FinalizeExecution; +use revm::db::BundleState; use revm_primitives::{ db::DatabaseCommit, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, U256, }; @@ -55,12 +57,15 @@ where EvmConfig: Clone + Unpin + Sync + Send + 'static + ConfigureEvm
, { - type Strategy + Display>> = - OpExecutionStrategy; + type Strategy + Display>> + = OpExecutionStrategy + where + State: FinalizeExecution; fn create_strategy(&self, db: DB) -> Self::Strategy where DB: Database + Display>, + State: FinalizeExecution, { let state = State::builder().with_database(db).with_bundle_update().without_state_clear().build(); @@ -117,6 +122,7 @@ where impl BlockExecutionStrategy for OpExecutionStrategy where DB: Database + Display>, + State: FinalizeExecution, EvmConfig: ConfigureEvm
, { type Error = BlockExecutionError; diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 0ab411d3e600..c5a39d3a989d 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -204,7 +204,12 @@ where // this only includes changed accounts and storage but is better than nothing let storage = acc.storage.iter().map(|(key, slot)| (*key, slot.present_value)).collect(); - cached.insert_account(addr, info, storage); + cached.insert_account( + addr, + #[allow(clippy::useless_conversion)] + info.into(), + storage, + ); } } diff --git a/crates/primitives-traits/src/account.rs b/crates/primitives-traits/src/account.rs index 900d77fb9769..03790dd982a8 100644 --- a/crates/primitives-traits/src/account.rs +++ b/crates/primitives-traits/src/account.rs @@ -66,6 +66,25 @@ impl Account { pub fn get_bytecode_hash(&self) -> B256 { self.bytecode_hash.unwrap_or(KECCAK_EMPTY) } + + /// Convert an [`revm_primitives::shared::AccountInfo`] into an [`Account`] + pub fn from_account_info(info: revm_primitives::shared::AccountInfo) -> Self { + Self { + balance: info.balance, + nonce: info.nonce, + bytecode_hash: (info.code_hash != KECCAK_EMPTY).then_some(info.code_hash), + #[cfg(feature = "scroll")] + account_extension: Some( + info.code + .map(|code| { + reth_scroll_primitives::AccountExtension::from_bytecode( + &code.original_byte_slice(), + ) + }) + .unwrap_or(reth_scroll_primitives::AccountExtension::empty()), + ), + } + } } /// Bytecode for an account. @@ -233,16 +252,10 @@ impl From for revm_primitives::shared::AccountInfo { } } -// TODO (scroll): remove at last Scroll `Account` related PR. -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", feature = "test-utils"))] impl From for Account { - fn from(revm_acc: revm_primitives::shared::AccountInfo) -> Self { - Self { - balance: revm_acc.balance, - nonce: revm_acc.nonce, - bytecode_hash: (revm_acc.code_hash != KECCAK_EMPTY).then_some(revm_acc.code_hash), - account_extension: None, - } + fn from(info: revm_primitives::shared::AccountInfo) -> Self { + Self::from_account_info(info) } } diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 7e187c6fb00f..12066447ec2c 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -167,6 +167,11 @@ serde-bincode-compat = [ "serde_with", "alloy-eips/serde-bincode-compat", ] +scroll = [ + "reth-trie-common/scroll", + "reth-primitives-traits/scroll", + "reth-testing-utils/scroll" +] [[bench]] name = "recover_ecdsa_crit" diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 4bc78b7b0562..ecccb30475e6 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -21,6 +21,9 @@ reth-storage-api.workspace = true reth-trie = { workspace = true, optional = true } reth-primitives-traits.workspace = true +# scroll +reth-scroll-primitives = { workspace = true, optional = true } + # alloy alloy-eips.workspace = true alloy-primitives.workspace = true @@ -61,3 +64,8 @@ serde = [ "alloy-consensus/serde", "reth-primitives-traits/serde", ] +scroll = [ + "reth-scroll-primitives", + "reth-primitives-traits/scroll", + "reth-trie/scroll" +] diff --git a/crates/revm/src/cached.rs b/crates/revm/src/cached.rs index 5d5262adc5b3..81e44675f75f 100644 --- a/crates/revm/src/cached.rs +++ b/crates/revm/src/cached.rs @@ -4,9 +4,12 @@ use alloy_primitives::{ Address, B256, U256, }; use core::cell::RefCell; -use revm::primitives::{ - db::{Database, DatabaseRef}, - AccountInfo, Bytecode, +use revm::{ + primitives::{ + db::{Database, DatabaseRef}, + Bytecode, + }, + shared::AccountInfo, }; /// A container type that caches reads from an underlying [`DatabaseRef`]. diff --git a/crates/revm/src/database.rs b/crates/revm/src/database.rs index 682aca6cf379..9fd059194cfa 100644 --- a/crates/revm/src/database.rs +++ b/crates/revm/src/database.rs @@ -3,11 +3,7 @@ use alloy_primitives::{Address, B256, U256}; use core::ops::{Deref, DerefMut}; use reth_primitives::Account; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use revm::{ - db::DatabaseRef, - primitives::{AccountInfo, Bytecode}, - Database, -}; +use revm::{db::DatabaseRef, primitives::Bytecode, shared::AccountInfo, Database}; /// A helper trait responsible for providing state necessary for EVM execution. /// diff --git a/crates/revm/src/either.rs b/crates/revm/src/either.rs index e93ba3a8d010..c2521bc4801a 100644 --- a/crates/revm/src/either.rs +++ b/crates/revm/src/either.rs @@ -1,8 +1,5 @@ use alloy_primitives::{Address, B256, U256}; -use revm::{ - primitives::{AccountInfo, Bytecode}, - Database, -}; +use revm::{primitives::Bytecode, shared::AccountInfo, Database}; /// An enum type that can hold either of two different [`Database`] implementations. /// diff --git a/crates/revm/src/witness.rs b/crates/revm/src/witness.rs index c40c87d324b3..ab1ec0f79785 100644 --- a/crates/revm/src/witness.rs +++ b/crates/revm/src/witness.rs @@ -22,7 +22,11 @@ pub struct ExecutionWitnessRecord { impl ExecutionWitnessRecord { /// Records the state after execution. - pub fn record_executed_state(&mut self, statedb: &State) { + pub fn record_executed_state( + &mut self, + statedb: &State, + #[cfg(feature = "scroll")] context: &reth_scroll_primitives::ScrollPostExecutionContext, + ) { self.codes = statedb .cache .contracts @@ -43,9 +47,14 @@ impl ExecutionWitnessRecord { for (address, account) in &statedb.cache.accounts { let hashed_address = keccak256(address); - self.hashed_state - .accounts - .insert(hashed_address, account.account.as_ref().map(|a| a.info.clone().into())); + #[cfg(feature = "scroll")] + let hashed_account = account + .account + .as_ref() + .map(|a| Into::::into((a.info.clone(), context)).into()); + #[cfg(not(feature = "scroll"))] + let hashed_account = account.account.as_ref().map(|a| a.info.clone().into()); + self.hashed_state.accounts.insert(hashed_address, hashed_account); let storage = self .hashed_state @@ -68,9 +77,16 @@ impl ExecutionWitnessRecord { } /// Creates the record from the state after execution. - pub fn from_executed_state(state: &State) -> Self { + pub fn from_executed_state( + state: &State, + #[cfg(feature = "scroll")] context: &reth_scroll_primitives::ScrollPostExecutionContext, + ) -> Self { let mut record = Self::default(); - record.record_executed_state(state); + record.record_executed_state( + state, + #[cfg(feature = "scroll")] + context, + ); record } } diff --git a/crates/rpc/rpc-eth-api/Cargo.toml b/crates/rpc/rpc-eth-api/Cargo.toml index e4b1b28074f0..c21cbaa66ba0 100644 --- a/crates/rpc/rpc-eth-api/Cargo.toml +++ b/crates/rpc/rpc-eth-api/Cargo.toml @@ -43,6 +43,10 @@ alloy-rpc-types-eth.workspace = true alloy-rpc-types-mev.workspace = true alloy-consensus.workspace = true +# scroll +reth-scroll-execution.workspace = true +reth-scroll-storage = { workspace = true, optional = true } + # rpc jsonrpsee = { workspace = true, features = ["server", "macros"] } jsonrpsee-types.workspace = true @@ -61,3 +65,13 @@ tracing.workspace = true [features] js-tracer = ["revm-inspectors/js-tracer", "reth-rpc-eth-types/js-tracer"] client = ["jsonrpsee/client", "jsonrpsee/async-client"] +scroll = [ + "reth-trie/scroll", + "reth-provider/scroll", + "reth-execution-types/scroll", + "reth-revm/scroll", + "reth-primitives/scroll", + "reth-evm/scroll", + "reth-rpc-eth-types/scroll", + "reth-scroll-storage" +] diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index d7e74c37b567..077fee2826fa 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -109,6 +109,10 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock { let this = self.clone(); self.spawn_with_state_at_block(block, move |state| { + #[cfg(feature = "scroll")] + let mut db = + CacheDB::new(reth_scroll_storage::ScrollStateProviderDatabase::new(state)); + #[cfg(not(feature = "scroll"))] let mut db = CacheDB::new(StateProviderDatabase::new(state)); let mut blocks: Vec>> = Vec::with_capacity(block_state_calls.len()); diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index 548f9101023d..631e46787420 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -24,14 +24,12 @@ use reth_provider::{ BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderError, ReceiptProvider, StateProviderFactory, }; -use reth_revm::{ - database::StateProviderDatabase, - primitives::{ - BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, EVMError, Env, ExecutionResult, InvalidTransaction, - ResultAndState, SpecId, - }, +use reth_revm::primitives::{ + BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, EVMError, Env, ExecutionResult, InvalidTransaction, + ResultAndState, SpecId, }; use reth_rpc_eth_types::{EthApiError, PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin}; +use reth_scroll_execution::FinalizeExecution; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use reth_trie::HashedPostState; use revm::{db::states::bundle_state::BundleRetention, DatabaseCommit, State}; @@ -226,7 +224,10 @@ pub trait LoadPendingBlock: .provider() .history_by_block_hash(parent_hash) .map_err(Self::Error::from_eth_err)?; - let state = StateProviderDatabase::new(state_provider); + #[cfg(not(feature = "scroll"))] + let state = reth_revm::database::StateProviderDatabase::new(state_provider); + #[cfg(feature = "scroll")] + let state = reth_scroll_storage::ScrollStateProviderDatabase::new(state_provider); let mut db = State::builder().with_database(state).with_bundle_update().build(); let mut cumulative_gas_used = 0; @@ -384,7 +385,7 @@ pub trait LoadPendingBlock: db.merge_transitions(BundleRetention::PlainState); let execution_outcome = ExecutionOutcome::new( - db.take_bundle(), + db.finalize(), vec![receipts.clone()].into(), block_number, Vec::new(), diff --git a/crates/rpc/rpc-eth-types/Cargo.toml b/crates/rpc/rpc-eth-types/Cargo.toml index 98b9530d63c2..ef7a9b99cbfc 100644 --- a/crates/rpc/rpc-eth-types/Cargo.toml +++ b/crates/rpc/rpc-eth-types/Cargo.toml @@ -33,11 +33,14 @@ alloy-primitives.workspace = true alloy-consensus.workspace = true alloy-sol-types.workspace = true alloy-rpc-types-eth.workspace = true -revm.workspace = true revm-inspectors.workspace = true revm-primitives = { workspace = true, features = ["dev"] } alloy-eips.workspace = true +# scroll +revm.workspace = true +reth-scroll-storage = { workspace = true, optional = true } + # rpc jsonrpsee-core.workspace = true jsonrpsee-types.workspace = true @@ -65,3 +68,12 @@ serde_json.workspace = true [features] js-tracer = ["revm-inspectors/js-tracer"] +scroll = [ + "revm/scroll", + "reth-execution-types/scroll", + "reth-revm/scroll", + "reth-primitives/scroll", + "reth-evm/scroll", + "reth-trie/scroll", + "reth-scroll-storage/scroll" +] diff --git a/crates/rpc/rpc-eth-types/src/simulate.rs b/crates/rpc/rpc-eth-types/src/simulate.rs index 5a0daa1b42f0..d296286b83b5 100644 --- a/crates/rpc/rpc-eth-types/src/simulate.rs +++ b/crates/rpc/rpc-eth-types/src/simulate.rs @@ -12,7 +12,6 @@ use reth_primitives::{ proofs::{calculate_receipt_root, calculate_transaction_root}, BlockBody, BlockWithSenders, Receipt, TransactionSigned, }; -use reth_revm::database::StateProviderDatabase; use reth_rpc_server_types::result::rpc_err; use reth_rpc_types_compat::{block::from_block, TransactionCompat}; use reth_storage_api::StateRootProvider; @@ -151,7 +150,12 @@ pub fn build_block>( parent_hash: B256, total_difficulty: U256, full_transactions: bool, - db: &CacheDB>>, + #[cfg(feature = "scroll")] db: &CacheDB< + reth_scroll_storage::ScrollStateProviderDatabase>, + >, + #[cfg(not(feature = "scroll"))] db: &CacheDB< + reth_revm::database::StateProviderDatabase>, + >, tx_resp_builder: &T, ) -> Result>, T::Error> { let mut calls: Vec = Vec::with_capacity(results.len()); @@ -232,7 +236,13 @@ pub fn build_block>( let mut hashed_state = HashedPostState::default(); for (address, account) in &db.accounts { let hashed_address = keccak256(address); - hashed_state.accounts.insert(hashed_address, Some(account.info.clone().into())); + #[cfg(feature = "scroll")] + let hashed_account = + Into::::into((account.info.clone(), &db.db.post_execution_context)) + .into(); + #[cfg(not(feature = "scroll"))] + let hashed_account = account.info.clone().into(); + hashed_state.accounts.insert(hashed_address, Some(hashed_account)); let storage = hashed_state .storages diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index 804ecd11120e..f79c30fac642 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -64,6 +64,9 @@ revm = { workspace = true, features = [ ] } revm-primitives = { workspace = true, features = ["serde"] } +# scroll +reth-scroll-storage = { workspace = true, optional = true } + # rpc jsonrpsee.workspace = true http.workspace = true @@ -102,3 +105,15 @@ jsonrpsee = { workspace = true, features = ["client"] } [features] js-tracer = ["revm-inspectors/js-tracer", "reth-rpc-eth-types/js-tracer"] +scroll = [ + "reth-trie/scroll", + "reth-evm/scroll", + "reth-rpc-eth-types/scroll", + "reth-primitives/scroll", + "reth-revm/scroll", + "reth-provider/scroll", + "reth-testing-utils/scroll", + "reth-evm-ethereum/scroll", + "reth-rpc-eth-api/scroll", + "reth-scroll-storage/scroll", +] diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index dd6bf9bbc24e..ca8c4493f1c5 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -608,7 +608,10 @@ where self.eth_api() .spawn_with_state_at_block(block.parent_hash.into(), move |state_provider| { + #[cfg(not(feature = "scroll"))] let db = StateProviderDatabase::new(&state_provider); + #[cfg(feature = "scroll")] + let db = reth_scroll_storage::ScrollStateProviderDatabase::new(&state_provider); let block_executor = this.inner.block_executor.executor(db); let mut witness_record = ExecutionWitnessRecord::default(); @@ -617,7 +620,11 @@ where .execute_with_state_closure( (&(*block).clone().unseal(), block.difficulty).into(), |statedb: &State<_>| { - witness_record.record_executed_state(statedb); + witness_record.record_executed_state( + statedb, + #[cfg(feature = "scroll")] + &statedb.database.post_execution_context, + ); }, ) .map_err(|err| EthApiError::Internal(err.into()))?; diff --git a/crates/scroll/execution/Cargo.toml b/crates/scroll/execution/Cargo.toml index 6abb7d1cd7f6..7a6af2b39798 100644 --- a/crates/scroll/execution/Cargo.toml +++ b/crates/scroll/execution/Cargo.toml @@ -14,22 +14,11 @@ workspace = true [dependencies] # reth reth-revm.workspace = true - -# scroll -reth-scroll-primitives = { workspace = true, optional = true } -reth-scroll-revm.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", + "reth-revm/scroll" ] -test-utils = [ - "reth-scroll-revm/test-utils", - "reth-revm/test-utils" -] \ No newline at end of file +test-utils = ["reth-revm/test-utils"] diff --git a/crates/scroll/execution/src/context.rs b/crates/scroll/execution/src/context.rs index 6ddd47dc531f..020aa0a7e318 100644 --- a/crates/scroll/execution/src/context.rs +++ b/crates/scroll/execution/src/context.rs @@ -1,68 +1,75 @@ -#[cfg(feature = "test-utils")] -use reth_revm::{database::StateProviderDatabase, db::CacheDB}; -use reth_revm::{Database, State}; +#![allow(clippy::useless_conversion)] + +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +use reth_revm::{cached::CachedReadsDbMut, revm::CacheDB, DatabaseRef}; +use reth_revm::{ + database::{EvmStateProvider, StateProviderDatabase}, + revm::State, +}; +#[cfg(feature = "scroll")] +use reth_scroll_storage::ScrollStateProviderDatabase; /// Finalize the execution of the type and return the output -pub trait FinalizeExecution { +pub trait FinalizeExecution { + /// The output of the finalization. + type Output; + /// Finalize the state and return the output. - fn finalize(&mut self) -> Output; + fn finalize(&mut self) -> Self::Output; } -impl FinalizeExecution - for State -{ - fn finalize(&mut self) -> reth_scroll_revm::states::ScrollBundleState { +#[cfg(feature = "scroll")] +impl FinalizeExecution for State> { + type Output = reth_revm::states::ScrollBundleState; + + fn finalize(&mut self) -> Self::Output { let bundle = self.take_bundle(); - (bundle, self.database.context()).into() + (bundle, &self.database.post_execution_context).into() } } -/// A type that returns additional execution context. -pub trait ContextFul: WithContext {} -impl ContextFul for T where T: WithContext {} - -/// Types that can provide a context. -#[auto_impl::auto_impl(&, &mut)] -pub trait WithContext { - /// The context returned. - type Context; +#[cfg(feature = "scroll")] +impl FinalizeExecution for State<&mut ScrollStateProviderDatabase> { + type Output = reth_revm::states::ScrollBundleState; - /// Returns the context from the type. - fn context(&self) -> &Self::Context; + fn finalize(&mut self) -> Self::Output { + let bundle = self.take_bundle(); + (bundle, &self.database.post_execution_context).into() + } } -#[cfg(not(feature = "scroll"))] -type ExecutionContext = (); -#[cfg(feature = "scroll")] -type ExecutionContext = reth_scroll_primitives::ScrollPostExecutionContext; - -#[cfg(feature = "scroll")] -impl WithContext for reth_scroll_storage::ScrollStateProviderDatabase { - type Context = ExecutionContext; +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +impl FinalizeExecution for State> { + type Output = reth_revm::db::BundleState; - fn context(&self) -> &Self::Context { - &self.post_execution_context + fn finalize(&mut self) -> Self::Output { + self.take_bundle().into() } } -#[cfg(feature = "test-utils")] -static DEFAULT_CONTEXT: std::sync::LazyLock = - std::sync::LazyLock::new(Default::default); +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +impl FinalizeExecution for State<&mut StateProviderDatabase> { + type Output = reth_revm::db::BundleState; + + fn finalize(&mut self) -> Self::Output { + self.take_bundle().into() + } +} -#[cfg(feature = "test-utils")] -impl WithContext for StateProviderDatabase { - type Context = ExecutionContext; +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +impl FinalizeExecution for State> { + type Output = reth_revm::db::BundleState; - fn context(&self) -> &Self::Context { - &DEFAULT_CONTEXT + fn finalize(&mut self) -> Self::Output { + self.take_bundle().into() } } -#[cfg(feature = "test-utils")] -impl WithContext for CacheDB { - type Context = ExecutionContext; +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +impl FinalizeExecution for State> { + type Output = reth_revm::db::BundleState; - fn context(&self) -> &Self::Context { - &DEFAULT_CONTEXT + fn finalize(&mut self) -> Self::Output { + self.take_bundle().into() } } diff --git a/crates/scroll/execution/src/lib.rs b/crates/scroll/execution/src/lib.rs index 3a7b2353563f..150a0e9700da 100644 --- a/crates/scroll/execution/src/lib.rs +++ b/crates/scroll/execution/src/lib.rs @@ -2,5 +2,5 @@ #![warn(unused_crate_dependencies)] -pub use context::{ContextFul, FinalizeExecution, WithContext}; +pub use context::FinalizeExecution; mod context; diff --git a/crates/scroll/revm/Cargo.toml b/crates/scroll/revm/Cargo.toml index 44956d812b1e..b43263667797 100644 --- a/crates/scroll/revm/Cargo.toml +++ b/crates/scroll/revm/Cargo.toml @@ -13,7 +13,7 @@ workspace = true [dependencies] # revm -revm.workspace = true +revm = { version = "18.0.0", features = ["std"], default-features = false } # scroll reth-scroll-primitives.workspace = true @@ -23,6 +23,7 @@ serde = { workspace = true, optional = true } [features] default = ["std"] +dev = ["revm/dev"] arbitrary = [ "revm/arbitrary", "reth-scroll-primitives/arbitrary" @@ -40,3 +41,9 @@ std = [ "revm/std", "serde/std" ] + +blst = ["revm/blst"] +optional_block_gas_limit = ["revm/optional_block_gas_limit"] +optional_eip3607 = ["revm/optional_eip3607"] +optional_no_base_fee = ["revm/optional_no_base_fee"] +secp256k1 = ["revm/secp256k1"] diff --git a/crates/scroll/revm/src/lib.rs b/crates/scroll/revm/src/lib.rs index 3ace4cd19bdc..750d8fdd1dec 100644 --- a/crates/scroll/revm/src/lib.rs +++ b/crates/scroll/revm/src/lib.rs @@ -4,9 +4,11 @@ #![warn(unused_crate_dependencies)] pub mod states; +#[cfg(feature = "test-utils")] +mod test_utils; #[cfg(feature = "optimism")] -pub use revm::primitives::OptimismFields; +pub use revm::{primitives::OptimismFields, L1BlockInfo, L1_BLOCK_CONTRACT}; pub use revm::{ db::*, @@ -15,7 +17,8 @@ pub use revm::{ keccak256, AuthorizationList, Bytecode, BytecodeDecodeError, JumpTable, LegacyAnalyzedBytecode, TxEnv, TxKind, }, - Evm, EvmBuilder, GetInspector, + ContextPrecompile, ContextPrecompiles, Evm, EvmBuilder, EvmContext, GetInspector, Inspector, + JournaledState, }; #[cfg(feature = "scroll")] @@ -26,7 +29,12 @@ pub use states::ScrollAccountInfo; /// Shared module, available for all feature flags. pub mod shared { - pub use revm::primitives::AccountInfo; + pub use revm::{db::states::BundleState, primitives::AccountInfo}; +} + +/// Match the `revm` module structure +pub mod handler { + pub use revm::handler::*; } /// Match the `revm` module structure @@ -34,6 +42,11 @@ pub mod interpreter { pub use revm::interpreter::*; } +/// Match the `revm` module structure +pub mod inspectors { + pub use revm::inspectors::*; +} + /// Match the `revm` module structure pub mod precompile { pub use revm::precompile::*; diff --git a/crates/scroll/revm/src/states/account_info.rs b/crates/scroll/revm/src/states/account_info.rs index e9464470be4b..ad21e46f14ce 100644 --- a/crates/scroll/revm/src/states/account_info.rs +++ b/crates/scroll/revm/src/states/account_info.rs @@ -42,18 +42,6 @@ impl From<(AccountInfo, &ScrollPostExecutionContext)> for ScrollAccountInfo { } } -// This conversion causes a loss of information. -impl From for AccountInfo { - fn from(info: ScrollAccountInfo) -> Self { - Self { - balance: info.balance, - nonce: info.nonce, - code_hash: info.code_hash, - code: info.code, - } - } -} - impl Default for ScrollAccountInfo { fn default() -> Self { Self { @@ -88,6 +76,26 @@ impl ScrollAccountInfo { Self { balance, nonce, code: Some(code), code_hash, code_size, poseidon_code_hash } } + /// Returns a copy of this account with the [`Bytecode`] removed. This is + /// useful when creating journals or snapshots of the state, where it is + /// desirable to store the code blobs elsewhere. + /// + /// ## Note + /// + /// This is distinct from [`ScrollAccountInfo::without_code`] in that it returns + /// a new `ScrollAccountInfo` instance with the code removed. + /// [`ScrollAccountInfo::without_code`] will modify and return the same instance. + pub const fn copy_without_code(&self) -> Self { + Self { + balance: self.balance, + nonce: self.nonce, + code_hash: self.code_hash, + code: None, + code_size: self.code_size, + poseidon_code_hash: self.poseidon_code_hash, + } + } + /// Returns account info without the code. pub fn without_code(mut self) -> Self { self.take_bytecode(); diff --git a/crates/scroll/revm/src/states/bundle.rs b/crates/scroll/revm/src/states/bundle.rs index f3f6f2f2b630..172e826fcab3 100644 --- a/crates/scroll/revm/src/states/bundle.rs +++ b/crates/scroll/revm/src/states/bundle.rs @@ -20,7 +20,7 @@ use std::{ ops::RangeInclusive, }; -/// An code copy of the [`BundleState`] modified with Scroll compatible fields. +/// A code copy of the [`BundleState`] modified with Scroll compatible fields. #[derive(Default, Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ScrollBundleState { @@ -70,9 +70,19 @@ impl From<(BundleState, &ScrollPostExecutionContext)> for ScrollBundleState { } } +// This conversion can cause a loss of information since performed without additional context. +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +impl From for ScrollBundleState { + fn from(bundle: BundleState) -> Self { + (bundle, &ScrollPostExecutionContext::default()).into() + } +} + +// This conversion can cause a loss of information since performed without additional context. +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] impl From<(BundleState, &())> for ScrollBundleState { fn from((bundle, _): (BundleState, &())) -> Self { - (bundle, &ScrollPostExecutionContext::default()).into() + bundle.into() } } @@ -272,19 +282,20 @@ impl ScrollBundleState { self.reverts.extend(other.reverts); } - /// Consume the bundle state and return plain state. - pub fn into_plain_state(self, is_value_known: OriginalValuesKnown) -> ScrollStateChangeset { + /// Generate a [`ScrollStateChangeset`] from the bundle state without consuming + /// it. + pub fn to_plain_state(&self, is_value_known: OriginalValuesKnown) -> ScrollStateChangeset { // pessimistically pre-allocate assuming _all_ accounts changed. let state_len = self.state.len(); let mut accounts = Vec::with_capacity(state_len); let mut storage = Vec::with_capacity(state_len); - for (address, account) in self.state { + for (address, account) in &self.state { // append account info if it is changed. let was_destroyed = account.was_destroyed(); if is_value_known.is_not_known() || account.is_info_changed() { - let info = account.info.map(ScrollAccountInfo::without_code); - accounts.push((address, info)); + let info = account.info.as_ref().map(ScrollAccountInfo::copy_without_code); + accounts.push((*address, info)); } // append storage changes @@ -293,7 +304,7 @@ impl ScrollBundleState { // database so we can check if plain state was wiped or not. let mut account_storage_changed = Vec::with_capacity(account.storage.len()); - for (key, slot) in account.storage { + for (key, slot) in account.storage.iter().map(|(k, v)| (*k, *v)) { // If storage was destroyed that means that storage was wiped. // In that case we need to check if present storage value is different then ZERO. let destroyed_and_not_zero = was_destroyed && !slot.present_value.is_zero(); @@ -313,29 +324,30 @@ impl ScrollBundleState { if !account_storage_changed.is_empty() || was_destroyed { // append storage changes to account. storage.push(PlainStorageChangeset { - address, + address: *address, wipe_storage: was_destroyed, storage: account_storage_changed, }); } } + let contracts = self .contracts - .into_iter() + .iter() // remove empty bytecodes - .filter(|(b, _)| *b != KECCAK_EMPTY) + .filter(|(b, _)| **b != KECCAK_EMPTY) + .map(|(b, code)| (*b, code.clone())) .collect::>(); ScrollStateChangeset { accounts, storage, contracts } } - /// Consume the bundle state and split it into reverts and plain state. - pub fn into_plain_state_and_reverts( - mut self, + /// Generate a [`ScrollStateChangeset`] and [`ScrollPlainStateReverts`] from the bundle + /// state. + pub fn to_plain_state_and_reverts( + &self, is_value_known: OriginalValuesKnown, ) -> (ScrollStateChangeset, ScrollPlainStateReverts) { - let reverts = self.take_all_reverts(); - let plain_state = self.into_plain_state(is_value_known); - (plain_state, reverts.into_plain_state_reverts()) + (self.to_plain_state(is_value_known), self.reverts.to_plain_state_reverts()) } /// Take first N raw reverts from the [`ScrollBundleState`]. diff --git a/crates/scroll/revm/src/states/reverts.rs b/crates/scroll/revm/src/states/reverts.rs index 750796eb9f3b..e10034000d8b 100644 --- a/crates/scroll/revm/src/states/reverts.rs +++ b/crates/scroll/revm/src/states/reverts.rs @@ -47,26 +47,34 @@ impl ScrollReverts { } } - /// Consume reverts and create plain state reverts. + /// Generate a [`ScrollPlainStateReverts`]. /// /// Note that account are sorted by address. - pub fn into_plain_state_reverts(mut self) -> ScrollPlainStateReverts { + pub fn to_plain_state_reverts(&self) -> ScrollPlainStateReverts { let mut state_reverts = ScrollPlainStateReverts::with_capacity(self.0.len()); - for reverts in self.0.drain(..) { + for reverts in &self.0 { // pessimistically pre-allocate assuming _all_ accounts changed. let mut accounts = Vec::with_capacity(reverts.len()); let mut storage = Vec::with_capacity(reverts.len()); for (address, revert_account) in reverts { - match revert_account.account { - ScrollAccountInfoRevert::RevertTo(acc) => accounts.push((address, Some(acc))), - ScrollAccountInfoRevert::DeleteIt => accounts.push((address, None)), + match &revert_account.account { + ScrollAccountInfoRevert::RevertTo(acc) => { + // cloning is cheap, because account info has 3 small + // fields and a Bytes + accounts.push((*address, Some(acc.clone()))) + } + ScrollAccountInfoRevert::DeleteIt => accounts.push((*address, None)), ScrollAccountInfoRevert::DoNothing => (), } if revert_account.wipe_storage || !revert_account.storage.is_empty() { storage.push(PlainStorageRevert { - address, + address: *address, wiped: revert_account.wipe_storage, - storage_revert: revert_account.storage.into_iter().collect::>(), + storage_revert: revert_account + .storage + .iter() + .map(|(k, v)| (*k, *v)) + .collect::>(), }); } } diff --git a/crates/scroll/revm/src/test_utils.rs b/crates/scroll/revm/src/test_utils.rs new file mode 100644 index 000000000000..f6538100dd87 --- /dev/null +++ b/crates/scroll/revm/src/test_utils.rs @@ -0,0 +1,97 @@ +use crate::{ + shared::AccountInfo, + states::{ + ScrollAccountInfoRevert, ScrollAccountRevert, ScrollPlainStateReverts, ScrollStateChangeset, + }, + ScrollAccountInfo, +}; +use reth_scroll_primitives::{hash_code, POSEIDON_EMPTY}; +use revm::db::{ + states::{reverts::AccountInfoRevert, PlainStateReverts, StateChangeset}, + AccountRevert, +}; + +// This conversion can cause a loss of information since performed without additional context. +impl From for ScrollStateChangeset { + fn from(changeset: StateChangeset) -> Self { + Self { + accounts: changeset + .accounts + .into_iter() + .map(|(add, acc)| (add, acc.map(Into::into))) + .collect(), + storage: changeset.storage, + contracts: changeset.contracts, + } + } +} + +// This conversion can cause a loss of information since performed without additional context. +impl From for ScrollPlainStateReverts { + fn from(reverts: PlainStateReverts) -> Self { + Self { + accounts: reverts + .accounts + .into_iter() + .map(|accounts| { + accounts.into_iter().map(|(add, acc)| (add, acc.map(Into::into))).collect() + }) + .collect(), + storage: reverts.storage, + } + } +} + +// This conversion can cause a loss of information since performed without additional context. +impl From for ScrollAccountInfoRevert { + fn from(account: AccountInfoRevert) -> Self { + match account { + AccountInfoRevert::DoNothing => Self::DoNothing, + AccountInfoRevert::DeleteIt => Self::DeleteIt, + AccountInfoRevert::RevertTo(account) => Self::RevertTo(account.into()), + } + } +} + +// This conversion can cause a loss of information since performed without additional context. +impl From for ScrollAccountRevert { + fn from(account: AccountRevert) -> Self { + Self { + account: account.account.into(), + storage: account.storage, + previous_status: account.previous_status, + wipe_storage: account.wipe_storage, + } + } +} + +// This conversion can cause a loss of information since performed without additional context. +impl From for ScrollAccountInfo { + fn from(info: AccountInfo) -> Self { + let (code_size, poseidon_code_hash) = info + .code + .as_ref() + .map(|code| (code.len() as u64, hash_code(code.original_byte_slice()))) + .unwrap_or((0, POSEIDON_EMPTY)); + Self { + balance: info.balance, + nonce: info.nonce, + code_hash: info.code_hash, + code: info.code, + code_size, + poseidon_code_hash, + } + } +} + +// This conversion causes a loss of information. +impl From for AccountInfo { + fn from(info: ScrollAccountInfo) -> Self { + Self { + balance: info.balance, + nonce: info.nonce, + code_hash: info.code_hash, + code: info.code, + } + } +} diff --git a/crates/stages/stages/Cargo.toml b/crates/stages/stages/Cargo.toml index 432af6f8a728..691d618e4fc6 100644 --- a/crates/stages/stages/Cargo.toml +++ b/crates/stages/stages/Cargo.toml @@ -41,6 +41,7 @@ reth-testing-utils = { workspace = true, optional = true } # scroll reth-scroll-primitives = { workspace = true, optional = true } +reth-scroll-storage = { workspace = true, optional = true } alloy-eips.workspace = true alloy-primitives.workspace = true @@ -120,7 +121,21 @@ test-utils = [ "reth-trie/test-utils", "reth-prune-types/test-utils", ] -scroll = ["reth-scroll-primitives"] +scroll = [ + "reth-primitives-traits/scroll", + "reth-testing-utils?/scroll", + "reth-trie/scroll", + "reth-provider/scroll", + "reth-primitives/scroll", + "reth-evm/scroll", + "reth-execution-types/scroll", + "reth-trie-db/scroll", + "reth-db/scroll", + "reth-evm-ethereum/scroll", + "reth-exex/scroll", + "reth-scroll-storage/scroll", + "reth-scroll-primitives" +] [[bench]] name = "criterion" diff --git a/crates/stages/stages/src/lib.rs b/crates/stages/stages/src/lib.rs index ce6a96cf3496..f21cbc9b2e14 100644 --- a/crates/stages/stages/src/lib.rs +++ b/crates/stages/stages/src/lib.rs @@ -80,6 +80,8 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use reth_revm as _; + #[allow(missing_docs)] #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index a62d947e722b..16d87c35c3a2 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -21,7 +21,6 @@ use reth_provider::{ StatsReader, TransactionVariant, }; use reth_prune_types::PruneModes; -use reth_revm::database::StateProviderDatabase; use reth_stages_api::{ BlockErrorKind, CheckpointBlockRange, EntitiesCheckpoint, ExecInput, ExecOutput, ExecutionCheckpoint, ExecutionStageThresholds, Stage, StageCheckpoint, StageError, StageId, @@ -225,7 +224,11 @@ where None }; - let db = StateProviderDatabase(LatestStateProviderRef::new(provider)); + let state = LatestStateProviderRef::new(provider); + #[cfg(feature = "scroll")] + let db = reth_scroll_storage::ScrollStateProviderDatabase::new(state); + #[cfg(not(feature = "scroll"))] + let db = reth_revm::database::StateProviderDatabase(state); let mut executor = self.executor_provider.batch_executor(db); executor.set_tip(max_block); executor.set_prune_modes(prune_modes); @@ -661,7 +664,7 @@ where mod tests { use super::*; use crate::test_utils::TestStageDB; - use alloy_primitives::{address, hex_literal::hex, keccak256, Address, B256, U256}; + use alloy_primitives::{address, b256, hex_literal::hex, keccak256, Address, B256, U256}; use alloy_rlp::Decodable; use assert_matches::assert_matches; use reth_chainspec::ChainSpecBuilder; @@ -884,9 +887,10 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): use `from_bytecode` #[cfg(feature = "scroll")] - account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode(&code), + ), }, ) .unwrap(); @@ -953,9 +957,10 @@ mod tests { balance: U256::ZERO, nonce: 0x00, bytecode_hash: Some(code_hash), - // TODO (scroll): use `from_bytecode`. #[cfg(feature = "scroll")] - account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode( + &code, + )), }; let account2 = address!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"); let account2_info = Account { @@ -1051,9 +1056,8 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): use `from_bytecode`. #[cfg(feature = "scroll")] - account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode(&code)), }; let acc2 = address!("a94f5374fce5edbc8e2a8697c15331677e6ebf0b"); let acc2_info = Account { @@ -1190,9 +1194,8 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): use `from_bytecode`. #[cfg(feature = "scroll")] - account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + account_extension: Some(reth_scroll_primitives::AccountExtension::from_bytecode(&code)), }; // set account @@ -1303,4 +1306,110 @@ mod tests { ] ); } + + #[test] + fn test_create() { + let test_db = TestStageDB::default(); + let provider = test_db.factory.database_provider_rw().unwrap(); + + // set up block + let beneficiary_address = address!("00000000000000000000000000000000deadbeef"); + let gas_limit = 1000000; + let data = hex!("6080604052600d8060106000396000f3604260000160005260206000f3"); + let code = hex!("604260000160005260206000f3"); + let pk = b256!("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"); + let transaction = reth_primitives::Transaction::Legacy(alloy_consensus::TxLegacy { + gas_limit, + to: alloy_primitives::TxKind::Create, + input: alloy_primitives::Bytes::from(data), + ..Default::default() + }); + let signature = reth_primitives::sign_message(pk, transaction.signature_hash()).unwrap(); + + let header = SealedHeader::new( + Header { + number: 1, + gas_limit, + gas_used: 56043, + receipts_root: b256!( + "141fb9a024b83e3752156621fb9f8376e8a16d281b8392640637f5b9fd095e36" + ), + beneficiary: beneficiary_address, + ..Default::default() + }, + B256::random(), + ); + let transaction = reth_primitives::TransactionSigned::new_unhashed(transaction, signature); + let block = SealedBlock::new( + header, + reth_primitives::BlockBody { + transactions: vec![transaction.clone()], + ..Default::default() + }, + ); + provider.insert_historical_block(block.try_seal_with_senders().unwrap()).unwrap(); + provider + .static_file_provider() + .latest_writer(StaticFileSegment::Headers) + .unwrap() + .commit() + .unwrap(); + provider.commit().unwrap(); + + // caller pre state + let caller_address = transaction.recover_signer().unwrap(); + let deployed_address = address!("5fbdb2315678afecb367f032d93f642f64180aa3"); + let balance = U256::MAX; + let caller_info = Account { + nonce: 0, + balance, + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + }; + + // set account + let provider = test_db.factory.provider_rw().unwrap(); + provider.tx_ref().put::(caller_address, caller_info).unwrap(); + provider.commit().unwrap(); + + // execute + let provider = test_db.factory.database_provider_rw().unwrap(); + let mut execution_stage = stage(); + let input = ExecInput { target: Some(1), checkpoint: None }; + let _ = execution_stage.execute(&provider, input).unwrap(); + provider.commit().unwrap(); + + // verify plain accounts content from storage + let plain_accounts = test_db.table::().unwrap(); + + assert_eq!( + plain_accounts, + vec![ + ( + beneficiary_address, + Account { + nonce: 0, + balance: U256::from(0x1bc16d674ec80000u64), + bytecode_hash: None, + #[cfg(feature = "scroll")] + account_extension: Some(reth_scroll_primitives::AccountExtension::empty()) + } + ), + ( + deployed_address, + Account { + nonce: 1, + balance: U256::ZERO, + bytecode_hash: Some(keccak256(code)), + #[cfg(feature = "scroll")] + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode(&code) + ), + } + ), + (caller_address, Account { nonce: 1, ..caller_info }), + ] + ) + } } diff --git a/crates/stages/stages/src/stages/mod.rs b/crates/stages/stages/src/stages/mod.rs index 7f351efc60e1..b0bcebd5e9a7 100644 --- a/crates/stages/stages/src/stages/mod.rs +++ b/crates/stages/stages/src/stages/mod.rs @@ -121,9 +121,10 @@ mod tests { nonce: 0, balance: U256::ZERO, bytecode_hash: Some(code_hash), - // TODO (scroll): use `from_bytecode`. #[cfg(feature = "scroll")] - account_extension: Some(reth_scroll_primitives::AccountExtension::empty()), + account_extension: Some( + reth_scroll_primitives::AccountExtension::from_bytecode(&code), + ), }, ) .unwrap(); diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 21891bce1f69..7429f76afd71 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -63,6 +63,8 @@ tempfile.workspace = true test-fuzz.workspace = true parking_lot.workspace = true +reth-scroll-primitives.workspace = true + pprof = { workspace = true, features = [ "flamegraph", "frame-pointer", @@ -111,10 +113,15 @@ arbitrary = [ "reth-prune-types/arbitrary", "reth-stages-types/arbitrary", "alloy-consensus/arbitrary", + "reth-scroll-primitives/arbitrary" ] optimism = ["reth-primitives/optimism", "reth-db-api/optimism"] disable-lock = [] -scroll = [] +scroll = [ + "reth-primitives-traits/scroll", + "reth-primitives/scroll", + "reth-trie-common/scroll" +] [[bench]] name = "hash_keys" diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index 6f65d990dfd2..9db25d5ee09b 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -138,4 +138,13 @@ test-utils = [ "reth-stages-types/test-utils", "reth-optimism-primitives?/arbitrary", ] -scroll = ["reth-scroll-primitives"] +scroll = [ + "reth-primitives/scroll", + "reth-testing-utils/scroll", + "reth-db/scroll", + "reth-trie-db/scroll", + "reth-trie/scroll", + "reth-execution-types/scroll", + "reth-evm/scroll", + "reth-scroll-primitives" +] diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index c26623487f65..88034d82794c 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -472,6 +472,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::useless_conversion)] + use super::*; use crate::{ test_utils::create_test_provider_factory, AccountReader, StorageTrieWriter, TrieWriter, @@ -570,13 +572,13 @@ mod tests { let mut state = State::builder().with_bundle_update().build(); state.insert_not_existing(address_a); - state.insert_account(address_b, account_b.clone()); + state.insert_account(address_b, account_b.clone().into()); // 0x00.. is created state.commit(HashMap::from_iter([( address_a, RevmAccount { - info: account_a.clone(), + info: account_a.clone().into(), status: AccountStatus::Touched | AccountStatus::Created, storage: HashMap::default(), }, @@ -586,7 +588,7 @@ mod tests { state.commit(HashMap::from_iter([( address_b, RevmAccount { - info: account_b_changed.clone(), + info: account_b_changed.clone().into(), status: AccountStatus::Touched, storage: HashMap::default(), }, @@ -596,8 +598,10 @@ mod tests { let mut revm_bundle_state = state.take_bundle(); // Write plain state and reverts separately. - let reverts = revm_bundle_state.take_all_reverts().to_plain_state_reverts(); - let plain_state = revm_bundle_state.to_plain_state(OriginalValuesKnown::Yes); + let reverts: revm::db::states::PlainStateReverts = + revm_bundle_state.take_all_reverts().to_plain_state_reverts().into(); + let plain_state: revm::db::states::StateChangeset = + revm_bundle_state.to_plain_state(OriginalValuesKnown::Yes).into(); assert!(plain_state.storage.is_empty()); assert!(plain_state.contracts.is_empty()); provider.write_state_changes(plain_state).expect("Could not write plain state to DB"); @@ -638,14 +642,14 @@ mod tests { ); let mut state = State::builder().with_bundle_update().build(); - state.insert_account(address_b, account_b_changed.clone()); + state.insert_account(address_b, account_b_changed.clone().into()); // 0xff.. is destroyed state.commit(HashMap::from_iter([( address_b, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: account_b_changed, + info: account_b_changed.into(), storage: HashMap::default(), }, )])); @@ -654,8 +658,10 @@ mod tests { let mut revm_bundle_state = state.take_bundle(); // Write plain state and reverts separately. - let reverts = revm_bundle_state.take_all_reverts().to_plain_state_reverts(); - let plain_state = revm_bundle_state.to_plain_state(OriginalValuesKnown::Yes); + let reverts: revm::db::states::PlainStateReverts = + revm_bundle_state.take_all_reverts().to_plain_state_reverts().into(); + let plain_state: revm::db::states::StateChangeset = + revm_bundle_state.to_plain_state(OriginalValuesKnown::Yes).into(); // Account B selfdestructed so flag for it should be present. assert_eq!( plain_state.storage, @@ -699,7 +705,7 @@ mod tests { state.insert_not_existing(address_a); state.insert_account_with_storage( address_b, - account_b.clone(), + account_b.clone().into(), HashMap::from_iter([(U256::from(1), U256::from(1))]), ); @@ -708,7 +714,7 @@ mod tests { address_a, RevmAccount { status: AccountStatus::Touched | AccountStatus::Created, - info: RevmAccountInfo::default(), + info: RevmAccountInfo::default().into(), // 0x00 => 0 => 1 // 0x01 => 0 => 2 storage: HashMap::from_iter([ @@ -727,7 +733,7 @@ mod tests { address_b, RevmAccount { status: AccountStatus::Touched, - info: account_b, + info: account_b.into(), // 0x01 => 1 => 2 storage: HashMap::from_iter([( U256::from(1), @@ -744,7 +750,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); + ExecutionOutcome::new(state.take_bundle().into(), Receipts::default(), 1, Vec::new()); let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) @@ -832,20 +838,20 @@ mod tests { // Delete account A let mut state = State::builder().with_bundle_update().build(); - state.insert_account(address_a, RevmAccountInfo::default()); + state.insert_account(address_a, RevmAccountInfo::default().into()); state.commit(HashMap::from_iter([( address_a, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: RevmAccountInfo::default(), + info: RevmAccountInfo::default().into(), storage: HashMap::default(), }, )])); state.merge_transitions(BundleRetention::Reverts); let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new()); + ExecutionOutcome::new(state.take_bundle().into(), Receipts::default(), 2, Vec::new()); let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) @@ -894,7 +900,7 @@ mod tests { init_state.commit(HashMap::from_iter([( address1, RevmAccount { - info: account_info.clone(), + info: account_info.clone().into(), status: AccountStatus::Touched | AccountStatus::Created, // 0x00 => 0 => 1 // 0x01 => 0 => 2 @@ -912,8 +918,12 @@ mod tests { )])); init_state.merge_transitions(BundleRetention::Reverts); - let outcome = - ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); + let outcome = ExecutionOutcome::new( + init_state.take_bundle().into(), + Receipts::default(), + 0, + Vec::new(), + ); let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) @@ -922,7 +932,7 @@ mod tests { let mut state = State::builder().with_bundle_update().build(); state.insert_account_with_storage( address1, - account_info.clone(), + account_info.clone().into(), HashMap::from_iter([(U256::ZERO, U256::from(1)), (U256::from(1), U256::from(2))]), ); @@ -931,7 +941,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched, - info: account_info.clone(), + info: account_info.clone().into(), // 0x00 => 1 => 2 storage: HashMap::from_iter([( U256::ZERO, @@ -950,7 +960,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -961,7 +971,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::Created, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -972,7 +982,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched, - info: account_info.clone(), + info: account_info.clone().into(), // 0x00 => 0 => 2 // 0x02 => 0 => 4 // 0x06 => 0 => 6 @@ -999,7 +1009,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -1010,7 +1020,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::Created, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -1018,7 +1028,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched, - info: account_info.clone(), + info: account_info.clone().into(), // 0x00 => 0 => 2 storage: HashMap::from_iter([( U256::ZERO, @@ -1030,7 +1040,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -1038,7 +1048,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::Created, - info: account_info.clone(), + info: account_info.clone().into(), storage: HashMap::default(), }, )])); @@ -1049,7 +1059,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched, - info: account_info, + info: account_info.into(), // 0x00 => 0 => 9 storage: HashMap::from_iter([( U256::ZERO, @@ -1059,7 +1069,7 @@ mod tests { )])); state.merge_transitions(BundleRetention::Reverts); - let bundle = state.take_bundle(); + let bundle = state.take_bundle().into(); let outcome: ExecutionOutcome = ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()); @@ -1210,7 +1220,7 @@ mod tests { init_state.commit(HashMap::from_iter([( address1, RevmAccount { - info: account1.clone(), + info: account1.clone().into(), status: AccountStatus::Touched | AccountStatus::Created, // 0x00 => 0 => 1 // 0x01 => 0 => 2 @@ -1227,8 +1237,12 @@ mod tests { }, )])); init_state.merge_transitions(BundleRetention::Reverts); - let outcome = - ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); + let outcome = ExecutionOutcome::new( + init_state.take_bundle().into(), + Receipts::default(), + 0, + Vec::new(), + ); let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) @@ -1237,7 +1251,7 @@ mod tests { let mut state = State::builder().with_bundle_update().build(); state.insert_account_with_storage( address1, - account1.clone(), + account1.clone().into(), HashMap::from_iter([(U256::ZERO, U256::from(1)), (U256::from(1), U256::from(2))]), ); @@ -1246,7 +1260,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: account1.clone(), + info: account1.clone().into(), storage: HashMap::default(), }, )])); @@ -1255,7 +1269,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::Created, - info: account1.clone(), + info: account1.clone().into(), storage: HashMap::default(), }, )])); @@ -1264,7 +1278,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched, - info: account1, + info: account1.into(), // 0x01 => 0 => 5 storage: HashMap::from_iter([( U256::from(1), @@ -1276,7 +1290,7 @@ mod tests { // Commit block #1 changes to the database. state.merge_transitions(BundleRetention::Reverts); let outcome = - ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); + ExecutionOutcome::new(state.take_bundle().into(), Receipts::default(), 1, Vec::new()); let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) @@ -1381,7 +1395,7 @@ mod tests { StateRoot::overlay_root( tx, ExecutionOutcome::::new( - state.bundle_state.clone(), + state.bundle_state.clone().into(), Receipts::default(), 0, Vec::new() @@ -1408,7 +1422,7 @@ mod tests { address1, RevmAccount { status: AccountStatus::Touched | AccountStatus::SelfDestructed, - info: RevmAccountInfo::default(), + info: RevmAccountInfo::default().into(), storage: HashMap::default(), }, )])); diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index 0a3893beb20e..2aa9ad114620 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -20,8 +20,9 @@ alloy-rlp = { workspace = true, features = ["arrayvec"] } alloy-trie = { workspace = true, features = ["serde"] } alloy-consensus.workspace = true alloy-genesis.workspace = true -revm-primitives.workspace = true +# revm-primitives scroll re-export +revm-primitives = { package = "reth-scroll-revm", path = "../../scroll/revm" } reth-scroll-primitives = { workspace = true, optional = true } bytes.workspace = true @@ -51,7 +52,8 @@ test-utils = [ "dep:hash-db", "arbitrary", "reth-primitives-traits/test-utils", - "reth-codecs/test-utils" + "reth-codecs/test-utils", + "revm-primitives/test-utils" ] arbitrary = [ "alloy-trie/arbitrary", @@ -64,4 +66,8 @@ arbitrary = [ "reth-codecs/arbitrary", "reth-scroll-primitives?/arbitrary" ] -scroll = ["reth-scroll-primitives"] +scroll = [ + "reth-primitives-traits/scroll", + "dep:reth-scroll-primitives", + "revm-primitives/scroll" +] diff --git a/crates/trie/db/Cargo.toml b/crates/trie/db/Cargo.toml index 370ee6a33ea2..ef9517fb8b95 100644 --- a/crates/trie/db/Cargo.toml +++ b/crates/trie/db/Cargo.toml @@ -88,4 +88,10 @@ test-utils = [ "reth-trie/test-utils", "revm/test-utils" ] -scroll = [] +scroll = [ + "reth-db/scroll", + "reth-primitives/scroll", + "reth-trie-common/scroll", + "reth-provider/scroll", + "revm/scroll" +] diff --git a/crates/trie/db/src/state.rs b/crates/trie/db/src/state.rs index 9b07a95f85a1..5156d4f6168a 100644 --- a/crates/trie/db/src/state.rs +++ b/crates/trie/db/src/state.rs @@ -91,8 +91,8 @@ pub trait DatabaseStateRoot<'a, TX>: Sized { /// nonce: 1, /// balance: U256::from(10), /// bytecode_hash: None, - /// // TODO (scroll): remove at last Scroll `Account` related PR. - /// ..Default::default() + /// #[cfg(feature = "scroll")] + /// account_extension: None, /// }), /// ); /// diff --git a/crates/trie/trie/Cargo.toml b/crates/trie/trie/Cargo.toml index 6136fa8e56bb..30ada617146d 100644 --- a/crates/trie/trie/Cargo.toml +++ b/crates/trie/trie/Cargo.toml @@ -19,6 +19,8 @@ reth-stages-types.workspace = true reth-storage-errors.workspace = true reth-trie-common.workspace = true +# revm re-export scroll +reth-primitives-traits.workspace = true revm.workspace = true # alloy @@ -70,19 +72,27 @@ serde = [ "alloy-consensus/serde", "alloy-primitives/serde", "revm/serde", - "alloy-trie/serde" + "alloy-trie/serde", + "reth-primitives-traits/serde" ] serde-bincode-compat = [ "serde_with", "reth-primitives/serde-bincode-compat", - "alloy-consensus/serde-bincode-compat" + "alloy-consensus/serde-bincode-compat", + "reth-primitives-traits/serde-bincode-compat" ] test-utils = [ "triehash", "reth-trie-common/test-utils", "reth-primitives/test-utils", "revm/test-utils", - "reth-stages-types/test-utils" + "reth-stages-types/test-utils", + "reth-primitives-traits/test-utils" +] +scroll = [ + "revm/scroll", + "reth-primitives-traits/scroll", + "reth-trie-common/scroll" ] [[bench]] diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index eca126744e96..0a69dcf9da80 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -59,7 +59,8 @@ impl HashedPostState { .into_par_iter() .map(|(address, account)| { let hashed_address = keccak256(address); - let hashed_account = account.account.as_ref().map(|a| a.info.clone().into()); + let hashed_account = + account.account.as_ref().map(|a| Account::from_account_info(a.info.clone())); let hashed_storage = HashedStorage::from_plain_storage( account.status, account.account.as_ref().map(|a| a.storage.iter()).into_iter().flatten(), @@ -348,13 +349,14 @@ impl HashedStorageSorted { #[cfg(test)] mod tests { use super::*; - use alloy_primitives::Bytes; + use alloy_primitives::{Address, Bytes}; use revm::{ db::{ - states::{plain_account::PlainStorage, StorageSlot}, - PlainAccount, StorageWithOriginalValues, + states::{plain_account::PlainStorage, CacheAccount, StorageSlot}, + BundleAccount, StorageWithOriginalValues, }, primitives::{AccountInfo, Bytecode}, + PlainAccount, }; #[test] @@ -442,6 +444,10 @@ mod tests { nonce: 42, code_hash: B256::random(), code: Some(Bytecode::LegacyRaw(Bytes::from(vec![1, 2]))), + #[cfg(feature = "scroll")] + code_size: 2, + #[cfg(feature = "scroll")] + poseidon_code_hash: B256::random(), }; let mut storage = StorageWithOriginalValues::default(); @@ -481,7 +487,7 @@ mod tests { let address = Address::random(); // Create mock account info. - let account_info = AccountInfo { + let account_info = revm::shared::AccountInfo { balance: U256::from(500), nonce: 5, code_hash: B256::random(), @@ -525,6 +531,10 @@ mod tests { nonce: 1, code_hash: B256::random(), code: None, + #[cfg(feature = "scroll")] + code_size: 10, + #[cfg(feature = "scroll")] + poseidon_code_hash: B256::random(), }; // Create hashed accounts with addresses. diff --git a/examples/beacon-api-sidecar-fetcher/Cargo.toml b/examples/beacon-api-sidecar-fetcher/Cargo.toml index d9590f87e07a..d30ce6b08244 100644 --- a/examples/beacon-api-sidecar-fetcher/Cargo.toml +++ b/examples/beacon-api-sidecar-fetcher/Cargo.toml @@ -20,3 +20,6 @@ reqwest.workspace = true serde_json.workspace = true serde.workspace = true thiserror.workspace = true + +[features] +scroll = [] diff --git a/examples/beacon-api-sidecar-fetcher/src/main.rs b/examples/beacon-api-sidecar-fetcher/src/main.rs index a0b9b6e01ec8..473d986604d4 100644 --- a/examples/beacon-api-sidecar-fetcher/src/main.rs +++ b/examples/beacon-api-sidecar-fetcher/src/main.rs @@ -12,6 +12,9 @@ //! See beacon Node API: #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use std::{ collections::VecDeque, diff --git a/examples/beacon-api-sse/Cargo.toml b/examples/beacon-api-sse/Cargo.toml index ca49897c9ee0..6b759aa35550 100644 --- a/examples/beacon-api-sse/Cargo.toml +++ b/examples/beacon-api-sse/Cargo.toml @@ -16,3 +16,6 @@ futures-util.workspace = true mev-share-sse = { version = "0.4.0", default-features = false } tokio = { workspace = true, features = ["time"] } tracing.workspace = true + +[features] +scroll = [] diff --git a/examples/beacon-api-sse/src/main.rs b/examples/beacon-api-sse/src/main.rs index 243511d4960e..00af7b39f818 100644 --- a/examples/beacon-api-sse/src/main.rs +++ b/examples/beacon-api-sse/src/main.rs @@ -16,6 +16,9 @@ //! See lighthouse beacon Node API: #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_rpc_types_beacon::events::PayloadAttributesEvent; use clap::Parser; diff --git a/examples/custom-beacon-withdrawals/Cargo.toml b/examples/custom-beacon-withdrawals/Cargo.toml index c396ca11df8b..b4a2e62e7b0e 100644 --- a/examples/custom-beacon-withdrawals/Cargo.toml +++ b/examples/custom-beacon-withdrawals/Cargo.toml @@ -13,6 +13,9 @@ reth-chainspec.workspace = true reth-evm.workspace = true reth-primitives.workspace = true +# scroll +reth-scroll-execution.workspace = true + alloy-sol-macro = "0.8.9" alloy-sol-types.workspace = true alloy-eips.workspace = true @@ -23,4 +26,5 @@ eyre.workspace = true [features] optimism = [ "reth-primitives/optimism" -] \ No newline at end of file +] +scroll = [] \ No newline at end of file diff --git a/examples/custom-beacon-withdrawals/src/main.rs b/examples/custom-beacon-withdrawals/src/main.rs index 47adc64c0048..3b2301024379 100644 --- a/examples/custom-beacon-withdrawals/src/main.rs +++ b/examples/custom-beacon-withdrawals/src/main.rs @@ -2,6 +2,9 @@ //! custom mechanism instead of minting native tokens #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_eips::{eip4895::Withdrawal, eip7685::Requests}; use alloy_sol_macro::sol; @@ -19,6 +22,7 @@ use reth::{ address, Address, BlockEnv, Bytes, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, TransactTo, TxEnv, U256, }, + shared::BundleState, Database, DatabaseCommit, Evm, State, }, }; @@ -30,6 +34,7 @@ use reth_evm::execute::{ use reth_evm_ethereum::EthEvmConfig; use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode}; use reth_primitives::{BlockWithSenders, Receipt}; +use reth_scroll_execution::FinalizeExecution; use std::{fmt::Display, sync::Arc}; pub const SYSTEM_ADDRESS: Address = address!("fffffffffffffffffffffffffffffffffffffffe"); @@ -91,11 +96,15 @@ pub struct CustomExecutorStrategyFactory { } impl BlockExecutionStrategyFactory for CustomExecutorStrategyFactory { - type Strategy + Display>> = CustomExecutorStrategy; + type Strategy + Display>> + = CustomExecutorStrategy + where + State: FinalizeExecution; fn create_strategy(&self, db: DB) -> Self::Strategy where DB: Database + Display>, + State: FinalizeExecution, { let state = State::builder().with_database(db).with_bundle_update().without_state_clear().build(); @@ -144,6 +153,7 @@ where impl BlockExecutionStrategy for CustomExecutorStrategy where DB: Database + Display>, + State: FinalizeExecution, { type Error = BlockExecutionError; diff --git a/examples/custom-dev-node/Cargo.toml b/examples/custom-dev-node/Cargo.toml index 8ed277686f4e..f101b22adbc3 100644 --- a/examples/custom-dev-node/Cargo.toml +++ b/examples/custom-dev-node/Cargo.toml @@ -19,3 +19,6 @@ serde_json.workspace = true alloy-genesis.workspace = true alloy-primitives.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-dev-node/src/main.rs b/examples/custom-dev-node/src/main.rs index 7fa44418c523..f6cabf47a744 100644 --- a/examples/custom-dev-node/src/main.rs +++ b/examples/custom-dev-node/src/main.rs @@ -2,6 +2,9 @@ //! through rpc. #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use std::sync::Arc; diff --git a/examples/custom-engine-types/Cargo.toml b/examples/custom-engine-types/Cargo.toml index d6642a8edfe5..68a72f676c1d 100644 --- a/examples/custom-engine-types/Cargo.toml +++ b/examples/custom-engine-types/Cargo.toml @@ -25,3 +25,6 @@ eyre.workspace = true tokio.workspace = true thiserror.workspace = true serde.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-engine-types/src/main.rs b/examples/custom-engine-types/src/main.rs index c21e893e05aa..16a096305a51 100644 --- a/examples/custom-engine-types/src/main.rs +++ b/examples/custom-engine-types/src/main.rs @@ -1,21 +1,24 @@ -//! This example shows how to implement a custom [EngineTypes]. +//! This example shows how to implement a custom `EngineTypes`. //! -//! The [EngineTypes] trait can be implemented to configure the engine to work with custom types, +//! The `EngineTypes` trait can be implemented to configure the engine to work with custom types, //! as long as those types implement certain traits. //! //! Custom payload attributes can be supported by implementing two main traits: //! -//! [PayloadAttributes] can be implemented for payload attributes types that are used as +//! `PayloadAttributes` can be implemented for payload attributes types that are used as //! arguments to the `engine_forkchoiceUpdated` method. This type should be used to define and //! _spawn_ payload jobs. //! -//! [PayloadBuilderAttributes] can be implemented for payload attributes types that _describe_ +//! `PayloadBuilderAttributes` can be implemented for payload attributes types that _describe_ //! running payload jobs. //! -//! Once traits are implemented and custom types are defined, the [EngineTypes] trait can be +//! Once traits are implemented and custom types are defined, the `EngineTypes` trait can be //! implemented: #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use std::{convert::Infallible, sync::Arc}; diff --git a/examples/custom-evm/Cargo.toml b/examples/custom-evm/Cargo.toml index e763a932eabf..a807fe3aa9b7 100644 --- a/examples/custom-evm/Cargo.toml +++ b/examples/custom-evm/Cargo.toml @@ -20,3 +20,6 @@ alloy-consensus.workspace = true eyre.workspace = true tokio.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-evm/src/main.rs b/examples/custom-evm/src/main.rs index 7a5278061f23..5eeb3ddea006 100644 --- a/examples/custom-evm/src/main.rs +++ b/examples/custom-evm/src/main.rs @@ -1,6 +1,9 @@ //! This example shows how to implement a node with a custom EVM #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_consensus::Header; use alloy_genesis::Genesis; diff --git a/examples/custom-inspector/Cargo.toml b/examples/custom-inspector/Cargo.toml index ee6f887e64c0..3566eb355711 100644 --- a/examples/custom-inspector/Cargo.toml +++ b/examples/custom-inspector/Cargo.toml @@ -12,4 +12,8 @@ alloy-rpc-types-eth.workspace = true clap = { workspace = true, features = ["derive"] } futures-util.workspace = true alloy-primitives.workspace = true + alloy-eips.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-inspector/src/main.rs b/examples/custom-inspector/src/main.rs index 67863d00e1e9..dccc30eaecd3 100644 --- a/examples/custom-inspector/src/main.rs +++ b/examples/custom-inspector/src/main.rs @@ -9,6 +9,9 @@ //! If no recipients are specified, all transactions will be inspected. #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_eips::BlockNumberOrTag; use alloy_primitives::Address; diff --git a/examples/custom-node-components/Cargo.toml b/examples/custom-node-components/Cargo.toml index 507088970de8..43940db3e3c4 100644 --- a/examples/custom-node-components/Cargo.toml +++ b/examples/custom-node-components/Cargo.toml @@ -13,3 +13,6 @@ reth-transaction-pool.workspace = true reth-tracing.workspace = true eyre.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-node-components/src/main.rs b/examples/custom-node-components/src/main.rs index d00b8a70224a..7bdcc00f0415 100644 --- a/examples/custom-node-components/src/main.rs +++ b/examples/custom-node-components/src/main.rs @@ -1,6 +1,9 @@ //! This example shows how to configure custom components for a reth node. #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use reth::{ api::NodeTypes, diff --git a/examples/custom-payload-builder/Cargo.toml b/examples/custom-payload-builder/Cargo.toml index b77a3f2945ca..b60c87803c94 100644 --- a/examples/custom-payload-builder/Cargo.toml +++ b/examples/custom-payload-builder/Cargo.toml @@ -21,3 +21,6 @@ alloy-eips.workspace = true tracing.workspace = true futures-util.workspace = true eyre.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-payload-builder/src/main.rs b/examples/custom-payload-builder/src/main.rs index e46b969adaa1..54026655fe76 100644 --- a/examples/custom-payload-builder/src/main.rs +++ b/examples/custom-payload-builder/src/main.rs @@ -10,6 +10,9 @@ //! This launch the regular reth node overriding the engine api payload builder with our custom. #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use generator::EmptyBlockPayloadJobGenerator; use reth::{ diff --git a/examples/custom-rlpx-subprotocol/Cargo.toml b/examples/custom-rlpx-subprotocol/Cargo.toml index 18c136671c06..5fd30de7fafa 100644 --- a/examples/custom-rlpx-subprotocol/Cargo.toml +++ b/examples/custom-rlpx-subprotocol/Cargo.toml @@ -19,3 +19,6 @@ eyre.workspace = true rand.workspace = true tracing.workspace = true alloy-primitives.workspace = true + +[features] +scroll = [] diff --git a/examples/custom-rlpx-subprotocol/src/main.rs b/examples/custom-rlpx-subprotocol/src/main.rs index 702d0e8cf5ef..84a4f42645c5 100644 --- a/examples/custom-rlpx-subprotocol/src/main.rs +++ b/examples/custom-rlpx-subprotocol/src/main.rs @@ -8,6 +8,10 @@ //! //! This launch a regular reth node with a custom rlpx subprotocol. +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + mod subprotocol; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; diff --git a/examples/db-access/Cargo.toml b/examples/db-access/Cargo.toml index 3310d1cbd676..1d468700dba2 100644 --- a/examples/db-access/Cargo.toml +++ b/examples/db-access/Cargo.toml @@ -19,3 +19,6 @@ alloy-primitives.workspace = true eyre.workspace = true + +[features] +scroll = [] diff --git a/examples/db-access/src/main.rs b/examples/db-access/src/main.rs index 179d12160535..988e75b60de7 100644 --- a/examples/db-access/src/main.rs +++ b/examples/db-access/src/main.rs @@ -1,3 +1,7 @@ +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + use alloy_primitives::{Address, B256}; use alloy_rpc_types_eth::{Filter, FilteredParams}; use reth_chainspec::ChainSpecBuilder; diff --git a/examples/node-custom-rpc/Cargo.toml b/examples/node-custom-rpc/Cargo.toml index e82254757ec1..13aa5872fccf 100644 --- a/examples/node-custom-rpc/Cargo.toml +++ b/examples/node-custom-rpc/Cargo.toml @@ -15,3 +15,6 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] } [dev-dependencies] tokio.workspace = true + +[features] +scroll = [] diff --git a/examples/node-custom-rpc/src/main.rs b/examples/node-custom-rpc/src/main.rs index 92e0bfea26e9..889924b5e8d9 100644 --- a/examples/node-custom-rpc/src/main.rs +++ b/examples/node-custom-rpc/src/main.rs @@ -12,6 +12,10 @@ //! cast rpc txpoolExt_transactionCount //! ``` +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + use clap::Parser; use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth::{chainspec::EthereumChainSpecParser, cli::Cli}; diff --git a/examples/node-event-hooks/Cargo.toml b/examples/node-event-hooks/Cargo.toml index 450f6f006b28..2e01b99a8893 100644 --- a/examples/node-event-hooks/Cargo.toml +++ b/examples/node-event-hooks/Cargo.toml @@ -8,3 +8,6 @@ license.workspace = true [dependencies] reth.workspace = true reth-node-ethereum.workspace = true + +[features] +scroll = [] diff --git a/examples/node-event-hooks/src/main.rs b/examples/node-event-hooks/src/main.rs index e8a751840e0d..a3dc823ccc07 100644 --- a/examples/node-event-hooks/src/main.rs +++ b/examples/node-event-hooks/src/main.rs @@ -11,6 +11,10 @@ //! > "All components initialized" – once all components have been initialized //! > "Node started" – once the node has been started. +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + use reth::cli::Cli; use reth_node_ethereum::EthereumNode; diff --git a/examples/rpc-db/Cargo.toml b/examples/rpc-db/Cargo.toml index 262b3df8babc..cce1b763d7fa 100644 --- a/examples/rpc-db/Cargo.toml +++ b/examples/rpc-db/Cargo.toml @@ -15,3 +15,6 @@ reth-node-ethereum.workspace = true reth-provider = { workspace = true, features = ["test-utils"] } tokio = { workspace = true, features = ["full"] } eyre.workspace = true + +[features] +scroll = [] diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 92ae86f00bb9..99d152a7d0e1 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -12,6 +12,10 @@ //! cast rpc myrpcExt_customMethod //! ``` +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] + use std::{path::Path, sync::Arc}; use reth::{ diff --git a/examples/stateful-precompile/Cargo.toml b/examples/stateful-precompile/Cargo.toml index 478886d061f8..7488cc497bee 100644 --- a/examples/stateful-precompile/Cargo.toml +++ b/examples/stateful-precompile/Cargo.toml @@ -21,3 +21,6 @@ eyre.workspace = true parking_lot.workspace = true schnellru.workspace = true tokio.workspace = true + +[features] +scroll = [] diff --git a/examples/stateful-precompile/src/main.rs b/examples/stateful-precompile/src/main.rs index f683af4e430a..718779cab829 100644 --- a/examples/stateful-precompile/src/main.rs +++ b/examples/stateful-precompile/src/main.rs @@ -1,6 +1,9 @@ //! This example shows how to implement a node with a custom EVM that uses a stateful precompile #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_consensus::Header; use alloy_genesis::Genesis; diff --git a/examples/txpool-tracing/Cargo.toml b/examples/txpool-tracing/Cargo.toml index 38d0ad9409b6..67e45929a4d4 100644 --- a/examples/txpool-tracing/Cargo.toml +++ b/examples/txpool-tracing/Cargo.toml @@ -12,3 +12,6 @@ alloy-rpc-types-trace.workspace = true clap = { workspace = true, features = ["derive"] } futures-util.workspace = true alloy-primitives.workspace = true + +[features] +scroll = [] diff --git a/examples/txpool-tracing/src/main.rs b/examples/txpool-tracing/src/main.rs index 94f800987a96..415fd46fad79 100644 --- a/examples/txpool-tracing/src/main.rs +++ b/examples/txpool-tracing/src/main.rs @@ -9,6 +9,9 @@ //! If no recipients are specified, all transactions will be traced. #![cfg_attr(not(test), warn(unused_crate_dependencies))] +// Don't use the crate if `scroll` feature is used. +#![cfg_attr(feature = "scroll", allow(unused_crate_dependencies))] +#![cfg(not(feature = "scroll"))] use alloy_primitives::Address; use alloy_rpc_types_trace::{parity::TraceType, tracerequest::TraceCallRequest}; diff --git a/testing/ef-tests/Cargo.toml b/testing/ef-tests/Cargo.toml index eb754cba7794..72d1fb90893f 100644 --- a/testing/ef-tests/Cargo.toml +++ b/testing/ef-tests/Cargo.toml @@ -18,7 +18,14 @@ asm-keccak = [ "alloy-primitives/asm-keccak", "revm/asm-keccak", ] -scroll = [] +scroll = [ + "reth-scroll-primitives", + "reth-revm/scroll", + "reth-primitives/scroll", + "reth-provider/scroll", + "reth-db/scroll", + "reth-stages/scroll" +] [dependencies] reth-chainspec.workspace = true diff --git a/testing/testing-utils/Cargo.toml b/testing/testing-utils/Cargo.toml index 4278da97a95c..f108fd9654e9 100644 --- a/testing/testing-utils/Cargo.toml +++ b/testing/testing-utils/Cargo.toml @@ -26,4 +26,4 @@ secp256k1 = { workspace = true, features = ["rand"] } alloy-eips.workspace = true [features] -scroll = [] +scroll = ["reth-primitives/scroll"]