diff --git a/Cargo.lock b/Cargo.lock index d10fc812ac9..3f37433f72b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1161,9 +1161,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.2" +version = "3.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130" +checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" [[package]] name = "byte-slice-cast" @@ -1286,7 +1286,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.3", ] [[package]] @@ -1872,12 +1872,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" dependencies = [ - "darling_core 0.20.6", - "darling_macro 0.20.6", + "darling_core 0.20.8", + "darling_macro 0.20.8", ] [[package]] @@ -1910,9 +1910,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" dependencies = [ "fnv", "ident_case", @@ -1946,11 +1946,11 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.6" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ - "darling_core 0.20.6", + "darling_core 0.20.8", "quote", "syn 2.0.50", ] @@ -2969,9 +2969,9 @@ checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-timer" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" dependencies = [ "gloo-timers", "send_wrapper 0.4.0", @@ -3360,7 +3360,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.5", + "socket2 0.5.6", "tokio", "tower-service", "tracing", @@ -3738,7 +3738,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2 0.5.5", + "socket2 0.5.6", "widestring", "windows-sys 0.48.0", "winreg", @@ -6338,6 +6338,7 @@ version = "0.1.0-alpha.19" dependencies = [ "reth-primitives", "reth-rpc-types", + "revm", "revm-primitives", "serde", "thiserror", @@ -6462,6 +6463,7 @@ dependencies = [ "reth-rpc-types", "reth-tracing", "reth-transaction-pool", + "revm", "serde", ] @@ -6484,6 +6486,7 @@ dependencies = [ "reth-rpc-types-compat", "reth-tracing", "reth-transaction-pool", + "revm", "serde", ] @@ -7654,7 +7657,7 @@ version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "865f9743393e638991566a8b7a479043c2c8da94a33e0a31f18214c9cae0a64d" dependencies = [ - "darling 0.20.6", + "darling 0.20.8", "proc-macro2", "quote", "syn 2.0.50", @@ -7885,12 +7888,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -8222,7 +8225,7 @@ version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f9bc8c69f276df24e4d1c082e52ea057544495916c4aa0708b82e47f55f364" dependencies = [ - "darling 0.20.6", + "darling 0.20.8", "itertools 0.12.1", "once_cell", "prettyplease", @@ -8381,7 +8384,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.5", + "socket2 0.5.6", "tokio-macros", "windows-sys 0.48.0", ] @@ -9219,7 +9222,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core", - "windows-targets 0.52.0", + "windows-targets 0.52.3", ] [[package]] @@ -9228,7 +9231,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.3", ] [[package]] @@ -9246,7 +9249,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.3", ] [[package]] @@ -9266,17 +9269,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.3", + "windows_aarch64_msvc 0.52.3", + "windows_i686_gnu 0.52.3", + "windows_i686_msvc 0.52.3", + "windows_x86_64_gnu 0.52.3", + "windows_x86_64_gnullvm 0.52.3", + "windows_x86_64_msvc 0.52.3", ] [[package]] @@ -9287,9 +9290,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" [[package]] name = "windows_aarch64_msvc" @@ -9299,9 +9302,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" [[package]] name = "windows_i686_gnu" @@ -9311,9 +9314,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" [[package]] name = "windows_i686_msvc" @@ -9323,9 +9326,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" [[package]] name = "windows_x86_64_gnu" @@ -9335,9 +9338,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" [[package]] name = "windows_x86_64_gnullvm" @@ -9347,9 +9350,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" [[package]] name = "windows_x86_64_msvc" @@ -9359,9 +9362,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" [[package]] name = "winnow" diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index d85dc3d34ae..76234b065ed 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -58,13 +58,13 @@ use tracing::{debug, error, info, instrument, trace, warn}; /// * [BlockchainTree::make_canonical]: Check if we have the hash of a block that is the current /// canonical head and commit it to db. #[derive(Debug)] -pub struct BlockchainTree { +pub struct BlockchainTree { /// The state of the tree /// /// Tracks all the chains, the block indices, and the block buffer. state: TreeState, /// External components (the database, consensus engine etc.) - externals: TreeExternals, + externals: TreeExternals, /// Tree configuration config: BlockchainTreeConfig, /// Broadcast channel for canon state changes notifications. @@ -76,10 +76,10 @@ pub struct BlockchainTree { prune_modes: Option, } -impl BlockchainTree { +impl BlockchainTree { /// Create a new blockchain tree. pub fn new( - externals: TreeExternals, + externals: TreeExternals, config: BlockchainTreeConfig, prune_modes: Option, ) -> RethResult { diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 0685d02b3dd..682ec35d62f 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -163,18 +163,18 @@ impl AppendableChain { /// - [BlockAttachment] represents if the block extends the canonical chain, and thus we can /// cache the trie state updates. /// - [BlockValidationKind] determines if the state root __should__ be validated. - fn validate_and_execute( + fn validate_and_execute( block: SealedBlockWithSenders, parent_block: &SealedHeader, bundle_state_data_provider: BSDP, - externals: &TreeExternals, + externals: &TreeExternals, block_attachment: BlockAttachment, block_validation_kind: BlockValidationKind, ) -> RethResult<(BundleStateWithReceipts, Option)> where BSDP: BundleStateDataProvider, DB: Database, - EF: ExecutorFactory, + EVM: ExecutorFactory, { // some checks are done before blocks comes here. externals.consensus.validate_header_against_parent(&block, parent_block)?; diff --git a/crates/blockchain-tree/src/externals.rs b/crates/blockchain-tree/src/externals.rs index 9bd12195aa4..150a09c6677 100644 --- a/crates/blockchain-tree/src/externals.rs +++ b/crates/blockchain-tree/src/externals.rs @@ -16,27 +16,27 @@ use std::{collections::BTreeMap, sync::Arc}; /// - The executor factory to execute blocks with /// - The chain spec #[derive(Debug)] -pub struct TreeExternals { +pub struct TreeExternals { /// The provider factory, used to commit the canonical chain, or unwind it. pub(crate) provider_factory: ProviderFactory, /// The consensus engine. pub(crate) consensus: Arc, /// The executor factory to execute blocks with. - pub(crate) executor_factory: EF, + pub(crate) executor_factory: EVM, } -impl TreeExternals { +impl TreeExternals { /// Create new tree externals. pub fn new( provider_factory: ProviderFactory, consensus: Arc, - executor_factory: EF, + executor_factory: EVM, ) -> Self { Self { provider_factory, consensus, executor_factory } } } -impl TreeExternals { +impl TreeExternals { /// Fetches the latest canonical block hashes by walking backwards from the head. /// /// Returns the hashes sorted by increasing block numbers diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 47bfca4f7ff..2f05b29c708 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -19,7 +19,7 @@ use reth_interfaces::{ consensus::{Consensus, ConsensusError}, executor::{BlockExecutionError, BlockValidationError}, }; -use reth_node_api::{ConfigureEvmEnv, EngineTypes}; +use reth_node_api::{ConfigureEvm, EngineTypes}; use reth_primitives::{ constants::{EMPTY_RECEIPTS, EMPTY_TRANSACTIONS, ETHEREUM_BLOCK_GAS_LIMIT}, proofs, Block, BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders, Bloom, @@ -320,7 +320,7 @@ impl StorageInner { executor: &mut EVMProcessor<'_, EvmConfig>, ) -> Result<(BundleStateWithReceipts, u64), BlockExecutionError> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { trace!(target: "consensus::auto", transactions=?&block.body, "executing transactions"); // TODO: there isn't really a parent beacon block root here, so not sure whether or not to @@ -434,7 +434,7 @@ impl StorageInner { evm_config: EvmConfig, ) -> Result<(SealedHeader, BundleStateWithReceipts), BlockExecutionError> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { let header = self.build_header_template(&transactions, chain_spec.clone()); diff --git a/crates/consensus/auto-seal/src/task.rs b/crates/consensus/auto-seal/src/task.rs index f77f694714d..f1c2abecea6 100644 --- a/crates/consensus/auto-seal/src/task.rs +++ b/crates/consensus/auto-seal/src/task.rs @@ -2,7 +2,7 @@ use crate::{mode::MiningMode, Storage}; use futures_util::{future::BoxFuture, FutureExt}; use reth_beacon_consensus::{BeaconEngineMessage, ForkchoiceStatus}; use reth_interfaces::consensus::ForkchoiceState; -use reth_node_api::{ConfigureEvmEnv, EngineTypes}; +use reth_node_api::{ConfigureEvm, EngineTypes}; use reth_primitives::{Block, ChainSpec, IntoRecoveredTransaction, SealedBlockWithSenders}; use reth_provider::{CanonChainTracker, CanonStateNotificationSender, Chain, StateProviderFactory}; use reth_stages::PipelineEvent; @@ -88,7 +88,7 @@ where Pool: TransactionPool + Unpin + 'static, ::Transaction: IntoRecoveredTransaction, Engine: EngineTypes + 'static, - EvmConfig: ConfigureEvmEnv + Clone + Unpin + Send + Sync + 'static, + EvmConfig: ConfigureEvm + Clone + Unpin + Send + Sync + 'static, { type Output = (); diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index b9dbf08340d..3541a84ceed 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -17,6 +17,7 @@ use reth_downloaders::{ }; use reth_interfaces::{ consensus::Consensus, + executor::BlockExecutionError, p2p::{bodies::client::BodiesClient, either::EitherDownloader, headers::client::HeadersClient}, sync::NoopSyncStateUpdater, test_utils::{NoopFullBlockClient, TestConsensus}, @@ -174,7 +175,7 @@ where fn with_state<'a, SP: reth_provider::StateProvider + 'a>( &'a self, sp: SP, - ) -> Box { + ) -> Box + 'a> { match self { EitherExecutorFactory::Left(a) => a.with_state::<'a, SP>(sp), EitherExecutorFactory::Right(b) => b.with_state::<'a, SP>(sp), diff --git a/crates/node-api/Cargo.toml b/crates/node-api/Cargo.toml index ce756a9b6a1..6b01dd8c075 100644 --- a/crates/node-api/Cargo.toml +++ b/crates/node-api/Cargo.toml @@ -16,6 +16,7 @@ reth-primitives.workspace = true reth-rpc-types.workspace = true revm-primitives.workspace = true thiserror.workspace = true +revm.workspace = true # io serde.workspace = true diff --git a/crates/node-api/src/evm/mod.rs b/crates/node-api/src/evm/mod.rs index e62ed617cf0..e93d66480f6 100644 --- a/crates/node-api/src/evm/mod.rs +++ b/crates/node-api/src/evm/mod.rs @@ -1,38 +1,5 @@ -use reth_primitives::{revm::env::fill_block_env, Address, ChainSpec, Header, Transaction, U256}; -use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId, TxEnv}; +//! Traits and structs for working with a configurable EVM. -/// EVM configuration trait. -pub trait EvmConfig: ConfigureEvmEnv + Clone + Send + Sync + 'static {} - -/// This represents the set of methods used to configure the EVM before execution. -pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone { - /// The type of the transaction metadata. - type TxMeta; - - /// Fill transaction environment from a [Transaction] and the given sender address. - fn fill_tx_env(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta) - where - T: AsRef; - - /// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header - fn fill_cfg_env( - cfg_env: &mut CfgEnvWithHandlerCfg, - chain_spec: &ChainSpec, - header: &Header, - total_difficulty: U256, - ); - - /// Convenience function to call both [fill_cfg_env](ConfigureEvmEnv::fill_cfg_env) and - /// [fill_block_env]. - fn fill_cfg_and_block_env( - cfg: &mut CfgEnvWithHandlerCfg, - block_env: &mut BlockEnv, - chain_spec: &ChainSpec, - header: &Header, - total_difficulty: U256, - ) { - Self::fill_cfg_env(cfg, chain_spec, header, total_difficulty); - let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE; - fill_block_env(block_env, chain_spec, header, after_merge); - } -} +/// Traits for working with a configurable EVM. +mod traits; +pub use traits::{ConfigureEvm, ConfigureEvmEnv}; diff --git a/crates/node-api/src/evm/traits.rs b/crates/node-api/src/evm/traits.rs new file mode 100644 index 00000000000..d0a8f3c418a --- /dev/null +++ b/crates/node-api/src/evm/traits.rs @@ -0,0 +1,54 @@ +use reth_primitives::{revm::env::fill_block_env, Address, ChainSpec, Header, Transaction, U256}; +use revm::{Database, Evm, EvmBuilder}; +use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId, TxEnv}; + +/// Trait for configuring the EVM for executing full blocks. +pub trait ConfigureEvm: ConfigureEvmEnv { + /// Returns new EVM with the given database + fn evm<'a, DB: Database + 'a>(&self, db: DB) -> Evm<'a, (), DB> { + EvmBuilder::default().with_db(db).build() + } + + /// Returns a new EVM with the given inspector + fn evm_with_inspector<'a, DB: Database + 'a, I>(&self, db: DB, inspector: I) -> Evm<'a, I, DB> { + EvmBuilder::default().with_db(db).with_external_context(inspector).build() + } +} + +/// This represents the set of methods used to configure the EVM's environment before block +/// execution. +pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone { + /// The type of the transaction metadata that should be used to fill fields in the transaction + /// environment. + /// + /// On ethereum mainnet, this is `()`, and on optimism these are the L1 fee fields and + /// additional L1 block info. + type TxMeta; + + /// Fill transaction environment from a [Transaction] and the given sender address. + fn fill_tx_env(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta) + where + T: AsRef; + + /// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header + fn fill_cfg_env( + cfg_env: &mut CfgEnvWithHandlerCfg, + chain_spec: &ChainSpec, + header: &Header, + total_difficulty: U256, + ); + + /// Convenience function to call both [fill_cfg_env](ConfigureEvmEnv::fill_cfg_env) and + /// [fill_block_env]. + fn fill_cfg_and_block_env( + cfg: &mut CfgEnvWithHandlerCfg, + block_env: &mut BlockEnv, + chain_spec: &ChainSpec, + header: &Header, + total_difficulty: U256, + ) { + Self::fill_cfg_env(cfg, chain_spec, header, total_difficulty); + let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE; + fill_block_env(block_env, chain_spec, header, after_merge); + } +} diff --git a/crates/node-api/src/lib.rs b/crates/node-api/src/lib.rs index 757269c3650..b9ef1c60b79 100644 --- a/crates/node-api/src/lib.rs +++ b/crates/node-api/src/lib.rs @@ -19,6 +19,6 @@ pub use engine::{ /// Traits and helper types used to abstract over EVM methods and types. pub mod evm; -pub use evm::ConfigureEvmEnv; +pub use evm::{ConfigureEvm, ConfigureEvmEnv}; pub mod primitives; diff --git a/crates/node-builder/src/builder.rs b/crates/node-builder/src/builder.rs index 1267046ee10..f7f6b583bfc 100644 --- a/crates/node-builder/src/builder.rs +++ b/crates/node-builder/src/builder.rs @@ -66,7 +66,7 @@ type RethFullProviderType = /// engine types. /// /// Next all stateful components of the node are configured, these include the -/// [EvmConfig](reth_node_api::evm::EvmConfig), the database [Database] and finally all the +/// [ConfigureEvm](reth_node_api::evm::ConfigureEvm), the database [Database] and finally all the /// components of the node that are downstream of those types, these include: /// /// - The transaction pool: [PoolBuilder](crate::components::PoolBuilder) diff --git a/crates/node-builder/src/node.rs b/crates/node-builder/src/node.rs index 68a9d3b9678..a3d1b744e09 100644 --- a/crates/node-builder/src/node.rs +++ b/crates/node-builder/src/node.rs @@ -4,7 +4,7 @@ use crate::{ }; use reth_db::database::Database; use reth_network::NetworkHandle; -use reth_node_api::{evm::EvmConfig, primitives::NodePrimitives, EngineTypes}; +use reth_node_api::{evm::ConfigureEvm, primitives::NodePrimitives, EngineTypes}; use reth_node_core::{ cli::components::FullProvider, dirs::{ChainPath, DataDirPath}, @@ -21,7 +21,7 @@ pub trait NodeTypes: Send + Sync + 'static { /// The node's engine types. type Engine: EngineTypes; /// The node's evm configuration. - type Evm: EvmConfig; + type Evm: ConfigureEvm; /// Returns the node's evm config. fn evm_config(&self) -> Self::Evm; diff --git a/crates/node-core/src/node_config.rs b/crates/node-core/src/node_config.rs index de52bd451d1..b0cfc4a1e51 100644 --- a/crates/node-core/src/node_config.rs +++ b/crates/node-core/src/node_config.rs @@ -39,7 +39,7 @@ use reth_network::{ transactions::{TransactionFetcherConfig, TransactionsManagerConfig}, NetworkBuilder, NetworkConfig, NetworkHandle, NetworkManager, }; -use reth_node_api::ConfigureEvmEnv; +use reth_node_api::ConfigureEvm; use reth_primitives::{ constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP}, kzg::KzgSettings, @@ -433,7 +433,7 @@ impl NodeConfig { ) -> eyre::Result>> where DB: Database + Unpin + Clone + 'static, - EvmConfig: ConfigureEvmEnv + Clone + 'static, + EvmConfig: ConfigureEvm + Clone + 'static, { // configure blockchain tree let tree_externals = TreeExternals::new( @@ -547,7 +547,7 @@ impl NodeConfig { where DB: Database + Unpin + Clone + 'static, Client: HeadersClient + BodiesClient + Clone + 'static, - EvmConfig: ConfigureEvmEnv + Clone + 'static, + EvmConfig: ConfigureEvm + Clone + 'static, { // building network downloaders using the fetch client let header_downloader = ReverseHeadersDownloaderBuilder::new(config.headers) @@ -796,7 +796,7 @@ impl NodeConfig { DB: Database + Clone + 'static, H: HeaderDownloader + 'static, B: BodyDownloader + 'static, - EvmConfig: ConfigureEvmEnv + Clone + 'static, + EvmConfig: ConfigureEvm + Clone + 'static, { let mut builder = Pipeline::builder(); diff --git a/crates/node-ethereum/Cargo.toml b/crates/node-ethereum/Cargo.toml index 103b1600bed..47674bce879 100644 --- a/crates/node-ethereum/Cargo.toml +++ b/crates/node-ethereum/Cargo.toml @@ -23,6 +23,7 @@ reth-tracing.workspace = true reth-provider.workspace = true reth-transaction-pool.workspace = true reth-network.workspace = true +revm.workspace = true # misc eyre.workspace = true diff --git a/crates/node-ethereum/src/evm.rs b/crates/node-ethereum/src/evm.rs index 1b5c90213d3..327714fc1a3 100644 --- a/crates/node-ethereum/src/evm.rs +++ b/crates/node-ethereum/src/evm.rs @@ -1,4 +1,4 @@ -use reth_node_api::{evm::EvmConfig, ConfigureEvmEnv}; +use reth_node_api::{ConfigureEvm, ConfigureEvmEnv}; use reth_primitives::{ revm::{config::revm_spec, env::fill_tx_env}, revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv}, @@ -44,8 +44,7 @@ impl ConfigureEvmEnv for EthEvmConfig { } } -// TODO -impl EvmConfig for EthEvmConfig {} +impl ConfigureEvm for EthEvmConfig {} #[cfg(test)] mod tests { diff --git a/crates/node-optimism/Cargo.toml b/crates/node-optimism/Cargo.toml index 8de6c76b510..bee83b25167 100644 --- a/crates/node-optimism/Cargo.toml +++ b/crates/node-optimism/Cargo.toml @@ -25,6 +25,7 @@ reth-tracing.workspace = true reth-provider.workspace = true reth-transaction-pool.workspace = true reth-network.workspace = true +revm.workspace = true # io serde.workspace = true diff --git a/crates/node-optimism/src/evm.rs b/crates/node-optimism/src/evm.rs index c1c8f52625e..93ea7f330a9 100644 --- a/crates/node-optimism/src/evm.rs +++ b/crates/node-optimism/src/evm.rs @@ -1,9 +1,10 @@ -use reth_node_api::{evm::EvmConfig, ConfigureEvmEnv}; +use reth_node_api::{ConfigureEvm, ConfigureEvmEnv}; use reth_primitives::{ revm::{config::revm_spec, env::fill_op_tx_env}, - revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv}, + revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, HandlerCfg, SpecId, TxEnv}, Address, Bytes, ChainSpec, Head, Header, Transaction, U256, }; +use revm::{Database, Evm, EvmBuilder}; /// Optimism-related EVM configuration. #[derive(Debug, Default, Clone, Copy)] @@ -45,13 +46,26 @@ impl ConfigureEvmEnv for OptimismEvmConfig { } } -// TODO -impl EvmConfig for OptimismEvmConfig {} +impl ConfigureEvm for OptimismEvmConfig { + fn evm<'a, DB: Database + 'a>(&self, db: DB) -> Evm<'a, (), DB> { + let handler_cfg = HandlerCfg { spec_id: SpecId::LATEST, is_optimism: true }; + EvmBuilder::default().with_db(db).with_handler_cfg(handler_cfg).build() + } + + fn evm_with_inspector<'a, DB: Database + 'a, I>(&self, db: DB, inspector: I) -> Evm<'a, I, DB> { + let handler_cfg = HandlerCfg { spec_id: SpecId::LATEST, is_optimism: true }; + EvmBuilder::default() + .with_db(db) + .with_external_context(inspector) + .with_handler_cfg(handler_cfg) + .build() + } +} #[cfg(test)] mod tests { use super::*; - use reth_primitives::revm_primitives::{BlockEnv, CfgEnv, SpecId}; + use reth_primitives::revm_primitives::{BlockEnv, CfgEnv}; #[test] #[ignore] diff --git a/crates/revm/src/factory.rs b/crates/revm/src/factory.rs index fca80f321ed..a90afa9a0b2 100644 --- a/crates/revm/src/factory.rs +++ b/crates/revm/src/factory.rs @@ -3,7 +3,8 @@ use crate::{ processor::EVMProcessor, stack::{InspectorStack, InspectorStackConfig}, }; -use reth_node_api::ConfigureEvmEnv; +use reth_interfaces::executor::BlockExecutionError; +use reth_node_api::ConfigureEvm; use reth_primitives::ChainSpec; use reth_provider::{ExecutorFactory, PrunableBlockExecutor, StateProvider}; use std::sync::Arc; @@ -38,12 +39,12 @@ impl EvmProcessorFactory { impl ExecutorFactory for EvmProcessorFactory where - EvmConfig: ConfigureEvmEnv + Send + Sync + Clone + 'static, + EvmConfig: ConfigureEvm + Send + Sync + Clone + 'static, { fn with_state<'a, SP: StateProvider + 'a>( &'a self, sp: SP, - ) -> Box { + ) -> Box + 'a> { let database_state = StateProviderDatabase::new(sp); let mut evm = Box::new(EVMProcessor::new_with_db( self.chain_spec.clone(), diff --git a/crates/revm/src/optimism/processor.rs b/crates/revm/src/optimism/processor.rs index 1fb5e84fee2..65f15c237ae 100644 --- a/crates/revm/src/optimism/processor.rs +++ b/crates/revm/src/optimism/processor.rs @@ -2,12 +2,12 @@ use crate::processor::{compare_receipts_root_and_logs_bloom, EVMProcessor}; use reth_interfaces::executor::{ BlockExecutionError, BlockValidationError, OptimismBlockExecutionError, }; -use reth_node_api::ConfigureEvmEnv; +use reth_node_api::ConfigureEvm; use reth_primitives::{ proofs::calculate_receipt_root_optimism, revm_primitives::ResultAndState, BlockWithSenders, Bloom, ChainSpec, Hardfork, Receipt, ReceiptWithBloom, TxType, B256, U256, }; -use reth_provider::{BlockExecutor, BlockExecutorStats, BundleStateWithReceipts}; +use reth_provider::{BlockExecutor, BundleStateWithReceipts}; use revm::DatabaseCommit; use std::time::Instant; use tracing::{debug, trace}; @@ -40,8 +40,10 @@ pub fn verify_receipt_optimism<'a>( impl<'a, EvmConfig> BlockExecutor for EVMProcessor<'a, EvmConfig> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { + type Error = BlockExecutionError; + fn execute( &mut self, block: &BlockWithSenders, @@ -196,10 +198,6 @@ where ) } - fn stats(&self) -> BlockExecutorStats { - self.stats.clone() - } - fn size_hint(&self) -> Option { Some(self.evm.context.evm.db.bundle_size_hint()) } diff --git a/crates/revm/src/processor.rs b/crates/revm/src/processor.rs index f10f375d8c3..4bc1c3e31ee 100644 --- a/crates/revm/src/processor.rs +++ b/crates/revm/src/processor.rs @@ -5,7 +5,7 @@ use crate::{ state_change::{apply_beacon_root_contract_call, post_block_balance_increments}, }; use reth_interfaces::executor::{BlockExecutionError, BlockValidationError}; -use reth_node_api::ConfigureEvmEnv; +use reth_node_api::ConfigureEvm; use reth_primitives::{ Address, Block, BlockNumber, BlockWithSenders, Bloom, ChainSpec, GotExpected, Hardfork, Header, PruneMode, PruneModes, PruneSegmentError, Receipt, ReceiptWithBloom, Receipts, @@ -83,7 +83,7 @@ pub struct EVMProcessor<'a, EvmConfig> { impl<'a, EvmConfig> EVMProcessor<'a, EvmConfig> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { /// Return chain spec. pub fn chain_spec(&self) -> &Arc { @@ -93,17 +93,14 @@ where /// Create a new pocessor with the given chain spec. pub fn new(chain_spec: Arc, evm_config: EvmConfig) -> Self { // create evm with boxed empty db that is going to be set later. - let evm = Evm::builder() - .with_db( - Box::new( - StateBuilder::new() - .with_database_boxed(Box::new(EmptyDBTyped::::new())), - ) - .build(), - ) - // Hook and inspector stack that we want to invoke on that hook. - .with_external_context(InspectorStack::new(InspectorStackConfig::default())) - .build(); + let db = Box::new( + StateBuilder::new().with_database_boxed(Box::new(EmptyDBTyped::::new())), + ) + .build(); + + // Hook and inspector stack that we want to invoke on that hook. + let stack = InspectorStack::new(InspectorStackConfig::default()); + let evm = evm_config.evm_with_inspector(db, stack); EVMProcessor { chain_spec, evm, @@ -137,10 +134,8 @@ where revm_state: StateDBBox<'a, ProviderError>, evm_config: EvmConfig, ) -> Self { - let evm = Evm::builder() - .with_db(revm_state) - .with_external_context(InspectorStack::new(InspectorStackConfig::default())) - .build(); + let stack = InspectorStack::new(InspectorStackConfig::default()); + let evm = evm_config.evm_with_inspector(revm_state, stack); EVMProcessor { chain_spec, evm, @@ -409,8 +404,10 @@ where #[cfg(not(feature = "optimism"))] impl<'a, EvmConfig> BlockExecutor for EVMProcessor<'a, EvmConfig> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { + type Error = BlockExecutionError; + fn execute( &mut self, block: &BlockWithSenders, @@ -505,6 +502,7 @@ where } fn take_output_state(&mut self) -> BundleStateWithReceipts { + self.stats.log_info(); let receipts = std::mem::take(&mut self.receipts); BundleStateWithReceipts::new( self.evm.context.evm.db.take_bundle(), @@ -513,10 +511,6 @@ where ) } - fn stats(&self) -> BlockExecutorStats { - self.stats.clone() - } - fn size_hint(&self) -> Option { Some(self.evm.context.evm.db.bundle_size_hint()) } @@ -524,7 +518,7 @@ where impl<'a, EvmConfig> PrunableBlockExecutor for EVMProcessor<'a, EvmConfig> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvm, { fn set_tip(&mut self, tip: BlockNumber) { self.tip = Some(tip); diff --git a/crates/stages/src/stages/execution.rs b/crates/stages/src/stages/execution.rs index ff6c378240c..5de44ab7049 100644 --- a/crates/stages/src/stages/execution.rs +++ b/crates/stages/src/stages/execution.rs @@ -206,8 +206,6 @@ impl ExecutionStage { "Execution time" ); - executor.stats().log_info(); - let done = stage_progress == max_block; Ok(ExecOutput { checkpoint: StageCheckpoint::new(stage_progress) diff --git a/crates/storage/provider/src/test_utils/executor.rs b/crates/storage/provider/src/test_utils/executor.rs index 2eb17a8152a..99e65b0ecb0 100644 --- a/crates/storage/provider/src/test_utils/executor.rs +++ b/crates/storage/provider/src/test_utils/executor.rs @@ -1,6 +1,6 @@ use crate::{ - bundle_state::BundleStateWithReceipts, BlockExecutor, BlockExecutorStats, ExecutorFactory, - PrunableBlockExecutor, StateProvider, + bundle_state::BundleStateWithReceipts, BlockExecutor, ExecutorFactory, PrunableBlockExecutor, + StateProvider, }; use parking_lot::Mutex; use reth_interfaces::executor::BlockExecutionError; @@ -11,6 +11,8 @@ use std::sync::Arc; pub struct TestExecutor(pub Option); impl BlockExecutor for TestExecutor { + type Error = BlockExecutionError; + fn execute( &mut self, _block: &BlockWithSenders, @@ -45,10 +47,6 @@ impl BlockExecutor for TestExecutor { self.0.clone().unwrap_or_default() } - fn stats(&self) -> BlockExecutorStats { - BlockExecutorStats::default() - } - fn size_hint(&self) -> Option { None } @@ -77,7 +75,7 @@ impl ExecutorFactory for TestExecutorFactory { fn with_state<'a, SP: StateProvider + 'a>( &'a self, _sp: SP, - ) -> Box { + ) -> Box::Error> + 'a> { let exec_res = self.exec_results.lock().pop(); Box::new(TestExecutor(exec_res)) } diff --git a/crates/storage/provider/src/traits/executor.rs b/crates/storage/provider/src/traits/executor.rs index bcb95f83bfd..d8e9425c1bc 100644 --- a/crates/storage/provider/src/traits/executor.rs +++ b/crates/storage/provider/src/traits/executor.rs @@ -14,17 +14,20 @@ pub trait ExecutorFactory: Send + Sync + 'static { fn with_state<'a, SP: StateProvider + 'a>( &'a self, _sp: SP, - ) -> Box; + ) -> Box + 'a>; } /// An executor capable of executing a block. pub trait BlockExecutor { + /// The error type returned by the executor. + type Error; + /// Execute a block. fn execute( &mut self, block: &BlockWithSenders, total_difficulty: U256, - ) -> Result<(), BlockExecutionError>; + ) -> Result<(), Self::Error>; /// Executes the block and checks receipts. /// @@ -33,7 +36,7 @@ pub trait BlockExecutor { &mut self, block: &BlockWithSenders, total_difficulty: U256, - ) -> Result<(), BlockExecutionError>; + ) -> Result<(), Self::Error>; /// Runs the provided transactions and commits their state to the run-time database. /// @@ -51,14 +54,11 @@ pub trait BlockExecutor { &mut self, block: &BlockWithSenders, total_difficulty: U256, - ) -> Result<(Vec, u64), BlockExecutionError>; + ) -> Result<(Vec, u64), Self::Error>; /// Return bundle state. This is output of executed blocks. fn take_output_state(&mut self) -> BundleStateWithReceipts; - /// Internal statistics of execution. - fn stats(&self) -> BlockExecutorStats; - /// Returns the size hint of current in-memory changes. fn size_hint(&self) -> Option; }