From 5e9f38164daba1f209d63c0e01f09fa83d49d0f3 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 18 Sep 2024 01:03:15 +0200 Subject: [PATCH] evm: use `Header` AT in `ConfigureEvmEnv` (#10968) --- Cargo.lock | 2 ++ .../engine/invalid-block-hooks/src/witness.rs | 8 +++-- crates/engine/util/src/reorg.rs | 4 +-- crates/ethereum/evm/src/execute.rs | 14 ++++----- crates/ethereum/evm/src/lib.rs | 22 +++++++++++++- crates/ethereum/node/Cargo.toml | 1 + crates/ethereum/node/src/node.rs | 3 +- crates/ethereum/payload/src/lib.rs | 6 ++-- crates/evm/src/lib.rs | 30 ++++--------------- crates/evm/src/provider.rs | 10 +++---- crates/evm/src/system_calls/eip2935.rs | 7 +++-- crates/evm/src/system_calls/mod.rs | 14 ++++----- crates/node/api/Cargo.toml | 1 + crates/node/api/src/node.rs | 3 +- crates/node/builder/src/components/builder.rs | 3 +- crates/node/builder/src/components/execute.rs | 5 ++-- crates/node/builder/src/components/mod.rs | 7 +++-- crates/optimism/evm/src/execute.rs | 14 ++++----- crates/optimism/evm/src/lib.rs | 24 +++++++++++++-- crates/optimism/node/src/node.rs | 3 +- crates/optimism/payload/src/builder.rs | 6 ++-- crates/optimism/rpc/src/eth/call.rs | 7 +++-- crates/optimism/rpc/src/eth/mod.rs | 3 +- crates/optimism/rpc/src/eth/pending_block.rs | 4 +-- crates/rpc/rpc-builder/Cargo.toml | 2 +- crates/rpc/rpc-builder/src/eth.rs | 3 +- crates/rpc/rpc-builder/src/lib.rs | 16 ++++++---- crates/rpc/rpc-eth-api/src/helpers/call.rs | 4 +-- .../rpc-eth-api/src/helpers/pending_block.rs | 2 +- crates/rpc/rpc-eth-api/src/helpers/trace.rs | 3 +- crates/rpc/rpc-eth-types/src/cache/mod.rs | 12 ++++---- crates/rpc/rpc/src/eth/helpers/call.rs | 5 ++-- .../rpc/rpc/src/eth/helpers/pending_block.rs | 5 ++-- crates/rpc/rpc/src/eth/helpers/trace.rs | 5 ++-- .../src/providers/blockchain_provider.rs | 8 ++--- .../provider/src/providers/database/mod.rs | 8 ++--- .../src/providers/database/provider.rs | 8 ++--- crates/storage/provider/src/providers/mod.rs | 8 ++--- .../storage/provider/src/test_utils/mock.rs | 8 ++--- .../storage/provider/src/test_utils/noop.rs | 8 ++--- examples/custom-evm/src/main.rs | 24 +++++++++++++-- examples/stateful-precompile/src/main.rs | 24 +++++++++++++-- 42 files changed, 220 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab4e47533920..09de394ebc50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7631,6 +7631,7 @@ dependencies = [ "reth-node-types", "reth-payload-builder", "reth-payload-primitives", + "reth-primitives", "reth-provider", "reth-rpc-eth-api", "reth-tasks", @@ -7782,6 +7783,7 @@ dependencies = [ "reth-node-builder", "reth-node-core", "reth-payload-builder", + "reth-primitives", "reth-provider", "reth-rpc", "reth-tasks", diff --git a/crates/engine/invalid-block-hooks/src/witness.rs b/crates/engine/invalid-block-hooks/src/witness.rs index eb703fb3336a..343dc6bb314e 100644 --- a/crates/engine/invalid-block-hooks/src/witness.rs +++ b/crates/engine/invalid-block-hooks/src/witness.rs @@ -9,7 +9,9 @@ use reth_evm::{ system_calls::{apply_beacon_root_contract_call, apply_blockhashes_contract_call}, ConfigureEvm, }; -use reth_primitives::{keccak256, Receipt, SealedBlockWithSenders, SealedHeader, B256, U256}; +use reth_primitives::{ + keccak256, Header, Receipt, SealedBlockWithSenders, SealedHeader, B256, U256, +}; use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory}; use reth_revm::{ database::StateProviderDatabase, @@ -50,7 +52,7 @@ impl InvalidBlockWitnessHook { impl InvalidBlockWitnessHook where P: StateProviderFactory + ChainSpecProvider + Send + Sync + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { fn on_invalid_block( &self, @@ -236,7 +238,7 @@ where impl InvalidBlockHook for InvalidBlockWitnessHook where P: StateProviderFactory + ChainSpecProvider + Send + Sync + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { fn on_invalid_block( &self, diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 0459ff341ad1..622e01847521 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -105,7 +105,7 @@ where S: Stream>, Engine: EngineTypes, Provider: BlockReader + StateProviderFactory, - Evm: ConfigureEvm, + Evm: ConfigureEvm
, { type Item = S::Item; @@ -237,7 +237,7 @@ fn create_reorg_head( ) -> RethResult<(ExecutionPayload, Option)> where Provider: BlockReader + StateProviderFactory, - Evm: ConfigureEvm, + Evm: ConfigureEvm
, { let chain_spec = payload_validator.chain_spec(); diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index f173c6cca454..096b44d0e828 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -67,7 +67,7 @@ impl EthExecutorProvider { impl EthExecutorProvider where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { fn eth_executor(&self, db: DB) -> EthBlockExecutor where @@ -83,7 +83,7 @@ where impl BlockExecutorProvider for EthExecutorProvider where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { type Executor + Display>> = EthBlockExecutor; @@ -126,7 +126,7 @@ struct EthEvmExecutor { impl EthEvmExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { /// Executes the transactions in the block and returns the receipts of the transactions in the /// block, the total gas used and the list of EIP-7685 [requests](Request). @@ -267,7 +267,7 @@ impl EthBlockExecutor { impl EthBlockExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { /// Configures a new evm configuration and block environment for the given block. @@ -356,7 +356,7 @@ where impl Executor for EthBlockExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; @@ -391,7 +391,7 @@ pub struct BlockAccessListExecutor { impl Executor for BlockAccessListExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; @@ -485,7 +485,7 @@ impl EthBatchExecutor { impl BatchExecutor for EthBatchExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index 80d96c80cc7e..2894b66e7dd0 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -122,9 +122,29 @@ impl ConfigureEvmEnv for EthEvmConfig { cfg_env.handler_cfg.spec_id = spec_id; } + fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool) { + block_env.number = U256::from(header.number); + block_env.coinbase = header.beneficiary; + block_env.timestamp = U256::from(header.timestamp); + if after_merge { + block_env.prevrandao = Some(header.mix_hash); + block_env.difficulty = U256::ZERO; + } else { + block_env.difficulty = header.difficulty; + block_env.prevrandao = None; + } + block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default()); + block_env.gas_limit = U256::from(header.gas_limit); + + // EIP-4844 excess blob gas of this block, introduced in Cancun + if let Some(excess_blob_gas) = header.excess_blob_gas { + block_env.set_blob_excess_gas_and_price(excess_blob_gas); + } + } + fn next_cfg_and_block_env( &self, - parent: &Header, + parent: &Self::Header, attributes: NextBlockEnvAttributes, ) -> (CfgEnvWithHandlerCfg, BlockEnv) { // configure evm env based on parent block diff --git a/crates/ethereum/node/Cargo.toml b/crates/ethereum/node/Cargo.toml index e7a5e702956e..145a966833cf 100644 --- a/crates/ethereum/node/Cargo.toml +++ b/crates/ethereum/node/Cargo.toml @@ -28,6 +28,7 @@ reth-beacon-consensus.workspace = true reth-rpc.workspace = true reth-node-api.workspace = true reth-chainspec.workspace = true +reth-primitives.workspace = true # misc eyre.workspace = true diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 939f3db1e56e..050f9b9bc181 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -21,6 +21,7 @@ use reth_node_builder::{ BuilderContext, Node, PayloadBuilderConfig, PayloadTypes, }; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; +use reth_primitives::Header; use reth_provider::CanonStateSubscriptions; use reth_rpc::EthApi; use reth_tracing::tracing::{debug, info}; @@ -217,7 +218,7 @@ impl EthereumPayloadBuilder { where Types: NodeTypesWithEngine, Node: FullNodeTypes, - Evm: ConfigureEvm, + Evm: ConfigureEvm
, Pool: TransactionPool + Unpin + 'static, Types::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index cde5d52d299b..9cd7981ff367 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -67,7 +67,7 @@ impl EthereumPayloadBuilder { impl EthereumPayloadBuilder where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { /// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the targeted payload /// (that has the `parent` as its parent). @@ -88,7 +88,7 @@ where // Default implementation of [PayloadBuilder] for unit type impl PayloadBuilder for EthereumPayloadBuilder where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, Client: StateProviderFactory, Pool: TransactionPool, { @@ -137,7 +137,7 @@ pub fn default_ethereum_payload( initialized_block_env: BlockEnv, ) -> Result, PayloadBuilderError> where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, Client: StateProviderFactory, Pool: TransactionPool, { diff --git a/crates/evm/src/lib.rs b/crates/evm/src/lib.rs index f767d254f2c6..14a8ff21bf03 100644 --- a/crates/evm/src/lib.rs +++ b/crates/evm/src/lib.rs @@ -14,9 +14,7 @@ extern crate alloc; use core::ops::Deref; use crate::builder::RethEvmBuilder; -use reth_primitives::{ - Address, Header, TransactionSigned, TransactionSignedEcRecovered, B256, U256, -}; +use reth_primitives::{Address, TransactionSigned, TransactionSignedEcRecovered, B256, U256}; use revm::{Database, Evm, GetInspector}; use revm_primitives::{ BlockEnv, Bytes, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv, @@ -139,30 +137,12 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static { fn fill_cfg_env( &self, cfg_env: &mut CfgEnvWithHandlerCfg, - header: &Header, + header: &Self::Header, total_difficulty: U256, ); /// Fill [`BlockEnv`] field according to the chain spec and given header - fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Header, after_merge: bool) { - block_env.number = U256::from(header.number); - block_env.coinbase = header.beneficiary; - block_env.timestamp = U256::from(header.timestamp); - if after_merge { - block_env.prevrandao = Some(header.mix_hash); - block_env.difficulty = U256::ZERO; - } else { - block_env.difficulty = header.difficulty; - block_env.prevrandao = None; - } - block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default()); - block_env.gas_limit = U256::from(header.gas_limit); - - // EIP-4844 excess blob gas of this block, introduced in Cancun - if let Some(excess_blob_gas) = header.excess_blob_gas { - block_env.set_blob_excess_gas_and_price(excess_blob_gas); - } - } + fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool); /// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and /// [`ConfigureEvmEnv::fill_block_env`]. @@ -172,7 +152,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static { &self, cfg: &mut CfgEnvWithHandlerCfg, block_env: &mut BlockEnv, - header: &Header, + header: &Self::Header, total_difficulty: U256, ) { self.fill_cfg_env(cfg, header, total_difficulty); @@ -187,7 +167,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static { /// the CL, such as the timestamp, suggested fee recipient, and randomness value. fn next_cfg_and_block_env( &self, - parent: &Header, + parent: &Self::Header, attributes: NextBlockEnvAttributes, ) -> (CfgEnvWithHandlerCfg, BlockEnv); } diff --git a/crates/evm/src/provider.rs b/crates/evm/src/provider.rs index b847a0665a35..fc3d4ff94f79 100644 --- a/crates/evm/src/provider.rs +++ b/crates/evm/src/provider.rs @@ -22,7 +22,7 @@ pub trait EvmEnvProvider: Send + Sync { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv; + EvmConfig: ConfigureEvmEnv
; /// Fills the default [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the /// given [Header]. @@ -32,7 +32,7 @@ pub trait EvmEnvProvider: Send + Sync { evm_config: EvmConfig, ) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let mut cfg = CfgEnvWithHandlerCfg::new_with_spec_id(CfgEnv::default(), SpecId::LATEST); let mut block_env = BlockEnv::default(); @@ -50,7 +50,7 @@ pub trait EvmEnvProvider: Send + Sync { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv; + EvmConfig: ConfigureEvmEnv
; /// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given /// [BlockHashOrNumber]. @@ -61,7 +61,7 @@ pub trait EvmEnvProvider: Send + Sync { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv; + EvmConfig: ConfigureEvmEnv
; /// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given [Header]. fn fill_cfg_env_with_header( @@ -71,5 +71,5 @@ pub trait EvmEnvProvider: Send + Sync { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv; + EvmConfig: ConfigureEvmEnv
; } diff --git a/crates/evm/src/system_calls/eip2935.rs b/crates/evm/src/system_calls/eip2935.rs index 0ed123e8a879..d32a58966653 100644 --- a/crates/evm/src/system_calls/eip2935.rs +++ b/crates/evm/src/system_calls/eip2935.rs @@ -7,6 +7,7 @@ use crate::ConfigureEvm; use core::fmt::Display; use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_execution_errors::{BlockExecutionError, BlockValidationError}; +use reth_primitives::Header; use revm::{interpreter::Host, Database, DatabaseCommit, Evm}; use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, B256}; @@ -28,7 +29,7 @@ pub fn pre_block_blockhashes_contract_call( where DB: Database + DatabaseCommit, DB::Error: Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // Apply the pre-block EIP-2935 contract call let mut evm_pre_block = Evm::builder() @@ -74,7 +75,7 @@ pub fn transact_blockhashes_contract_call( where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { if !chain_spec.is_prague_active_at_timestamp(block_timestamp) { return Ok(None) @@ -133,7 +134,7 @@ pub fn apply_blockhashes_contract_call( where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { if let Some(res) = transact_blockhashes_contract_call( evm_config, diff --git a/crates/evm/src/system_calls/mod.rs b/crates/evm/src/system_calls/mod.rs index 24af2098c87d..21073d869da3 100644 --- a/crates/evm/src/system_calls/mod.rs +++ b/crates/evm/src/system_calls/mod.rs @@ -11,7 +11,7 @@ use alloy_eips::{ }; use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_execution_errors::{BlockExecutionError, BlockValidationError}; -use reth_primitives::{Buf, Request}; +use reth_primitives::{Buf, Header, Request}; use revm::{interpreter::Host, Database, DatabaseCommit, Evm}; use revm_primitives::{ Address, BlockEnv, Bytes, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, FixedBytes, @@ -39,7 +39,7 @@ pub fn pre_block_beacon_root_contract_call( where DB: Database + DatabaseCommit, DB::Error: Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // apply pre-block EIP-4788 contract call let mut evm_pre_block = Evm::builder() @@ -81,7 +81,7 @@ pub fn apply_beacon_root_contract_call( where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { if !chain_spec.is_cancun_active_at_timestamp(block_timestamp) { return Ok(()) @@ -152,7 +152,7 @@ pub fn post_block_withdrawal_requests_contract_call( where DB: Database + DatabaseCommit, DB::Error: Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // apply post-block EIP-7002 contract call let mut evm_post_block = Evm::builder() @@ -180,7 +180,7 @@ pub fn apply_withdrawal_requests_contract_call( where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // get previous env let previous_env = Box::new(evm.context.env().clone()); @@ -282,7 +282,7 @@ pub fn post_block_consolidation_requests_contract_call( where DB: Database + DatabaseCommit, DB::Error: Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // apply post-block EIP-7251 contract call let mut evm_post_block = Evm::builder() @@ -310,7 +310,7 @@ pub fn apply_consolidation_requests_contract_call( where DB: Database + DatabaseCommit, DB::Error: core::fmt::Display, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { // get previous env let previous_env = Box::new(evm.context.env().clone()); diff --git a/crates/node/api/Cargo.toml b/crates/node/api/Cargo.toml index 82e863d5a98b..e7685acc84fd 100644 --- a/crates/node/api/Cargo.toml +++ b/crates/node/api/Cargo.toml @@ -22,3 +22,4 @@ reth-tasks.workspace = true reth-rpc-eth-api.workspace = true reth-network-api.workspace = true reth-node-types.workspace = true +reth-primitives.workspace = true diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index bc59c134a022..ce6b16c8ffcd 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -6,6 +6,7 @@ use reth_evm::execute::BlockExecutorProvider; use reth_network_api::FullNetwork; use reth_node_types::{NodeTypesWithDB, NodeTypesWithEngine}; use reth_payload_builder::PayloadBuilderHandle; +use reth_primitives::Header; use reth_provider::FullProvider; use reth_rpc_eth_api::EthApiTypes; use reth_tasks::TaskExecutor; @@ -48,7 +49,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static { type Pool: TransactionPool + Unpin; /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. - type Evm: ConfigureEvm; + type Evm: ConfigureEvm
; /// The type that knows how to execute blocks. type Executor: BlockExecutorProvider; diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index 650ab24abc13..ef9f303a740a 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -4,6 +4,7 @@ use std::{future::Future, marker::PhantomData}; use reth_consensus::Consensus; use reth_evm::execute::BlockExecutorProvider; +use reth_primitives::Header; use reth_transaction_pool::TransactionPool; use crate::{ @@ -371,7 +372,7 @@ where F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future>> + Send, Pool: TransactionPool + Unpin + 'static, - EVM: ConfigureEvm, + EVM: ConfigureEvm
, Executor: BlockExecutorProvider, Cons: Consensus + Clone + Unpin + 'static, { diff --git a/crates/node/builder/src/components/execute.rs b/crates/node/builder/src/components/execute.rs index 891f8e01feec..90cff588f7cc 100644 --- a/crates/node/builder/src/components/execute.rs +++ b/crates/node/builder/src/components/execute.rs @@ -2,6 +2,7 @@ use crate::{BuilderContext, FullNodeTypes}; use reth_evm::execute::BlockExecutorProvider; use reth_node_api::ConfigureEvm; +use reth_primitives::Header; use std::future::Future; /// A type that knows how to build the executor types. @@ -9,7 +10,7 @@ pub trait ExecutorBuilder: Send { /// The EVM config to use. /// /// This provides the node with the necessary configuration to configure an EVM. - type EVM: ConfigureEvm; + type EVM: ConfigureEvm
; /// The type that knows how to execute blocks. type Executor: BlockExecutorProvider; @@ -24,7 +25,7 @@ pub trait ExecutorBuilder: Send { impl ExecutorBuilder for F where Node: FullNodeTypes, - EVM: ConfigureEvm, + EVM: ConfigureEvm
, Executor: BlockExecutorProvider, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future> + Send, diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index b268b43a1921..42001fc10056 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -27,6 +27,7 @@ use reth_network::NetworkHandle; use reth_network_api::FullNetwork; use reth_node_api::NodeTypesWithEngine; use reth_payload_builder::PayloadBuilderHandle; +use reth_primitives::Header; use reth_transaction_pool::TransactionPool; use crate::{ConfigureEvm, FullNodeTypes}; @@ -41,7 +42,7 @@ pub trait NodeComponents: Clone + Unpin + Send + Sync + 'stati type Pool: TransactionPool + Unpin; /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. - type Evm: ConfigureEvm; + type Evm: ConfigureEvm
; /// The type that knows how to execute blocks. type Executor: BlockExecutorProvider; @@ -95,7 +96,7 @@ impl NodeComponents where Node: FullNodeTypes, Pool: TransactionPool + Unpin + 'static, - EVM: ConfigureEvm, + EVM: ConfigureEvm
, Executor: BlockExecutorProvider, Cons: Consensus + Clone + Unpin + 'static, { @@ -136,7 +137,7 @@ impl Clone for Components, Executor: BlockExecutorProvider, Cons: Consensus + Clone, { diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 3e2a8751689b..05c0da8f1187 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -59,7 +59,7 @@ impl OpExecutorProvider { impl OpExecutorProvider where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { fn op_executor(&self, db: DB) -> OpBlockExecutor where @@ -75,7 +75,7 @@ where impl BlockExecutorProvider for OpExecutorProvider where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { type Executor + Display>> = OpBlockExecutor; @@ -109,7 +109,7 @@ pub struct OpEvmExecutor { impl OpEvmExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { /// Executes the transactions in the block and returns the receipts. /// @@ -262,7 +262,7 @@ impl OpBlockExecutor { impl OpBlockExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { /// Configures a new evm configuration and block environment for the given block. @@ -335,7 +335,7 @@ where impl Executor for OpBlockExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; @@ -376,7 +376,7 @@ pub struct OpBlockAccessListExecutor { impl Executor for OpBlockAccessListExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; @@ -472,7 +472,7 @@ impl OpBatchExecutor { impl BatchExecutor for OpBatchExecutor where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index bfda1d8ecab7..77669f86a115 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -106,7 +106,7 @@ impl ConfigureEvmEnv for OptimismEvmConfig { fn fill_cfg_env( &self, cfg_env: &mut CfgEnvWithHandlerCfg, - header: &Header, + header: &Self::Header, total_difficulty: U256, ) { let spec_id = revm_spec( @@ -127,9 +127,29 @@ impl ConfigureEvmEnv for OptimismEvmConfig { cfg_env.handler_cfg.is_optimism = self.chain_spec.is_optimism(); } + fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool) { + block_env.number = U256::from(header.number); + block_env.coinbase = header.beneficiary; + block_env.timestamp = U256::from(header.timestamp); + if after_merge { + block_env.prevrandao = Some(header.mix_hash); + block_env.difficulty = U256::ZERO; + } else { + block_env.difficulty = header.difficulty; + block_env.prevrandao = None; + } + block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default()); + block_env.gas_limit = U256::from(header.gas_limit); + + // EIP-4844 excess blob gas of this block, introduced in Cancun + if let Some(excess_blob_gas) = header.excess_blob_gas { + block_env.set_blob_excess_gas_and_price(excess_blob_gas); + } + } + fn next_cfg_and_block_env( &self, - parent: &Header, + parent: &Self::Header, attributes: NextBlockEnvAttributes, ) -> (CfgEnvWithHandlerCfg, BlockEnv) { // configure evm env based on parent block diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index d4fabdbf1144..fec6d5065496 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -20,6 +20,7 @@ use reth_optimism_chainspec::OpChainSpec; use reth_optimism_consensus::OptimismBeaconConsensus; use reth_optimism_rpc::OpEthApi; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; +use reth_primitives::Header; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ @@ -254,7 +255,7 @@ impl OptimismPayloadBuilder { Types: NodeTypesWithEngine, >, Pool: TransactionPool + Unpin + 'static, - Evm: ConfigureEvm, + Evm: ConfigureEvm
, { let payload_builder = reth_optimism_payload_builder::OptimismPayloadBuilder::new(evm_config) diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index f7d8421ddad6..a7ec600eb894 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -70,7 +70,7 @@ impl OptimismPayloadBuilder { } impl OptimismPayloadBuilder where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { /// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the targeted payload /// (that has the `parent` as its parent). @@ -93,7 +93,7 @@ impl PayloadBuilder for OptimismPayloadBu where Client: StateProviderFactory, Pool: TransactionPool, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { type Attributes = OptimismPayloadBuilderAttributes; type BuiltPayload = OptimismBuiltPayload; @@ -161,7 +161,7 @@ pub(crate) fn optimism_payload( _compute_pending_block: bool, ) -> Result, PayloadBuilderError> where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, Client: StateProviderFactory, Pool: TransactionPool, { diff --git a/crates/optimism/rpc/src/eth/call.rs b/crates/optimism/rpc/src/eth/call.rs index 40e7a6aa2049..8a29f3c2f852 100644 --- a/crates/optimism/rpc/src/eth/call.rs +++ b/crates/optimism/rpc/src/eth/call.rs @@ -2,7 +2,10 @@ use alloy_primitives::{Bytes, TxKind, U256}; use reth_chainspec::ChainSpec; use reth_evm::ConfigureEvm; use reth_node_api::{FullNodeComponents, NodeTypes}; -use reth_primitives::revm_primitives::{BlockEnv, OptimismFields, TxEnv}; +use reth_primitives::{ + revm_primitives::{BlockEnv, OptimismFields, TxEnv}, + Header, +}; use reth_rpc_eth_api::{ helpers::{Call, EthCall, LoadState, SpawnBlocking}, FromEthApiError, IntoEthApiError, @@ -31,7 +34,7 @@ where } #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 25af6f029393..c79a11a42911 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -18,6 +18,7 @@ use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes, NodeTypes}; use reth_node_builder::EthApiBuilderCtx; +use reth_primitives::Header; use reth_provider::{ BlockIdReader, BlockNumReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, HeaderProvider, StageCheckpointReader, StateProviderFactory, @@ -230,7 +231,7 @@ where N: FullNodeComponents, { #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } } diff --git a/crates/optimism/rpc/src/eth/pending_block.rs b/crates/optimism/rpc/src/eth/pending_block.rs index 3b9fe2e20554..43542baf522a 100644 --- a/crates/optimism/rpc/src/eth/pending_block.rs +++ b/crates/optimism/rpc/src/eth/pending_block.rs @@ -5,7 +5,7 @@ use reth_chainspec::ChainSpec; use reth_evm::ConfigureEvm; use reth_node_api::{FullNodeComponents, NodeTypes}; use reth_primitives::{ - revm_primitives::BlockEnv, BlockNumberOrTag, Receipt, SealedBlockWithSenders, + revm_primitives::BlockEnv, BlockNumberOrTag, Header, Receipt, SealedBlockWithSenders, }; use reth_provider::{ BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ExecutionOutcome, @@ -46,7 +46,7 @@ where } #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } diff --git a/crates/rpc/rpc-builder/Cargo.toml b/crates/rpc/rpc-builder/Cargo.toml index 98d36ffa1600..af7096ac8684 100644 --- a/crates/rpc/rpc-builder/Cargo.toml +++ b/crates/rpc/rpc-builder/Cargo.toml @@ -29,6 +29,7 @@ reth-transaction-pool.workspace = true reth-evm.workspace = true reth-engine-primitives.workspace = true reth-rpc-types.workspace = true +reth-primitives.workspace = true # ethereum alloy-network.workspace = true @@ -57,7 +58,6 @@ reth-network-peers.workspace = true reth-evm-ethereum.workspace = true reth-ethereum-engine-primitives.workspace = true reth-payload-builder = { workspace = true, features = ["test-utils"] } -reth-primitives.workspace = true reth-provider = { workspace = true, features = ["test-utils"] } reth-rpc-api = { workspace = true, features = ["client"] } reth-rpc-engine-api.workspace = true diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index af0097c23b3c..50f6ed8a0065 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -1,4 +1,5 @@ use reth_evm::ConfigureEvm; +use reth_primitives::Header; use reth_provider::{BlockReader, CanonStateSubscriptions, EvmEnvProvider, StateProviderFactory}; use reth_rpc::{EthFilter, EthPubSub}; use reth_rpc_eth_types::{ @@ -75,7 +76,7 @@ impl where Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static, Pool: Send + Sync + Clone + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, Network: Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 53802e5221a6..9e450356b004 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -18,6 +18,7 @@ //! ``` //! use reth_evm::ConfigureEvm; //! use reth_network_api::{NetworkInfo, Peers}; +//! use reth_primitives::Header; //! use reth_provider::{AccountReader, CanonStateSubscriptions, ChangeSetReader, FullRpcProvider}; //! use reth_rpc::EthApi; //! use reth_rpc_builder::{ @@ -37,7 +38,7 @@ //! Pool: TransactionPool + 'static, //! Network: NetworkInfo + Peers + Clone + 'static, //! Events: CanonStateSubscriptions + Clone + 'static, -//! EvmConfig: ConfigureEvm, +//! EvmConfig: ConfigureEvm
, //! { //! // configure the rpc module per transport //! let transports = TransportRpcModuleConfig::default().with_http(vec![ @@ -69,6 +70,7 @@ //! use reth_engine_primitives::EngineTypes; //! use reth_evm::ConfigureEvm; //! use reth_network_api::{NetworkInfo, Peers}; +//! use reth_primitives::Header; //! use reth_provider::{AccountReader, CanonStateSubscriptions, ChangeSetReader, FullRpcProvider}; //! use reth_rpc::EthApi; //! use reth_rpc_api::EngineApiServer; @@ -94,7 +96,7 @@ //! Events: CanonStateSubscriptions + Clone + 'static, //! EngineApi: EngineApiServer, //! EngineT: EngineTypes, -//! EvmConfig: ConfigureEvm, +//! EvmConfig: ConfigureEvm
, //! { //! // configure the rpc module per transport //! let transports = TransportRpcModuleConfig::default().with_http(vec![ @@ -154,6 +156,7 @@ use reth_chainspec::ChainSpec; use reth_engine_primitives::EngineTypes; use reth_evm::ConfigureEvm; use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers}; +use reth_primitives::Header; use reth_provider::{ AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullRpcProvider, StateProviderFactory, @@ -228,7 +231,7 @@ where Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, EthApi: FullEthApiServer< NetworkTypes: alloy_network::Network, >, @@ -416,7 +419,7 @@ where Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { /// Configures all [`RpcModule`]s specific to the given [`TransportRpcModuleConfig`] which can /// be used to start the transport server(s). @@ -467,13 +470,14 @@ where /// ```no_run /// use reth_evm::ConfigureEvm; /// use reth_network_api::noop::NoopNetwork; + /// use reth_primitives::Header; /// use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions}; /// use reth_rpc::EthApi; /// use reth_rpc_builder::RpcModuleBuilder; /// use reth_tasks::TokioTaskExecutor; /// use reth_transaction_pool::noop::NoopTransactionPool; /// - /// fn init(evm: Evm) { + /// fn init + 'static>(evm: Evm) { /// let mut registry = RpcModuleBuilder::default() /// .with_provider(NoopProvider::default()) /// .with_pool(NoopTransactionPool::default()) @@ -661,7 +665,7 @@ where >, ) -> Self where - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { let blocking_pool_guard = BlockingTaskGuard::new(config.eth.max_tracing_requests); diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index 99b90d6729f2..06e14695583b 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -12,7 +12,7 @@ use reth_primitives::{ ResultAndState, TransactTo, TxEnv, }, transaction::AccessListResult, - TransactionSignedEcRecovered, + Header, TransactionSignedEcRecovered, }; use reth_provider::{ChainSpecProvider, StateProvider}; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; @@ -306,7 +306,7 @@ pub trait Call: LoadState + SpawnBlocking { /// Returns a handle for reading evm config. /// /// Data access in default (L1) trait method implementations. - fn evm_config(&self) -> &impl ConfigureEvm; + fn evm_config(&self) -> &impl ConfigureEvm
; /// Executes the closure with the state that corresponds to the given [`BlockId`]. fn with_state_at_block(&self, at: BlockId, f: F) -> Result 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 3c811acebae3..0f7000c01b25 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -66,7 +66,7 @@ pub trait LoadPendingBlock: EthApiTypes { /// Returns a handle for reading evm config. /// /// Data access in default (L1) trait method implementations. - fn evm_config(&self) -> &impl ConfigureEvm; + fn evm_config(&self) -> &impl ConfigureEvm
; /// Configures the [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the pending block /// diff --git a/crates/rpc/rpc-eth-api/src/helpers/trace.rs b/crates/rpc/rpc-eth-api/src/helpers/trace.rs index 896d28bab2a0..7c774c088112 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/trace.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/trace.rs @@ -3,6 +3,7 @@ use alloy_primitives::B256; use futures::Future; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; +use reth_primitives::Header; use reth_revm::database::StateProviderDatabase; use reth_rpc_eth_types::{ cache::db::{StateCacheDb, StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper}, @@ -22,7 +23,7 @@ pub trait Trace: LoadState { /// Returns a handle for reading evm config. /// /// Data access in default (L1) trait method implementations. - fn evm_config(&self) -> &impl ConfigureEvm; + fn evm_config(&self) -> &impl ConfigureEvm
; /// Executes the [`EnvWithHandlerCfg`] against the given [Database] without committing state /// changes. diff --git a/crates/rpc/rpc-eth-types/src/cache/mod.rs b/crates/rpc/rpc-eth-types/src/cache/mod.rs index b224d36c2399..0df853330795 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -7,8 +7,8 @@ use reth_errors::{ProviderError, ProviderResult}; use reth_evm::{provider::EvmEnvProvider, ConfigureEvm}; use reth_execution_types::Chain; use reth_primitives::{ - Block, BlockHashOrNumber, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, - TransactionSigned, TransactionSignedEcRecovered, + Block, BlockHashOrNumber, BlockWithSenders, Header, Receipt, SealedBlock, + SealedBlockWithSenders, TransactionSigned, TransactionSignedEcRecovered, }; use reth_storage_api::{BlockReader, StateProviderFactory, TransactionVariant}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; @@ -106,7 +106,7 @@ impl EthStateCache { ) -> Self where Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { Self::spawn_with(provider, config, TokioTaskExecutor::default(), evm_config) } @@ -124,7 +124,7 @@ impl EthStateCache { where Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { let EthStateCacheConfig { max_blocks, max_receipts, max_envs, max_concurrent_db_requests } = config; @@ -316,7 +316,7 @@ impl EthStateCacheService, { fn on_new_block(&mut self, block_hash: B256, res: ProviderResult>) { if let Some(queued) = self.full_block_cache.remove(&block_hash) { @@ -403,7 +403,7 @@ impl Future for EthStateCacheService, { type Output = (); diff --git a/crates/rpc/rpc/src/eth/helpers/call.rs b/crates/rpc/rpc/src/eth/helpers/call.rs index c442c46b4b80..3e93a5a7a0b5 100644 --- a/crates/rpc/rpc/src/eth/helpers/call.rs +++ b/crates/rpc/rpc/src/eth/helpers/call.rs @@ -1,6 +1,7 @@ //! Contains RPC handler implementations specific to endpoints that call/execute within evm. use reth_evm::ConfigureEvm; +use reth_primitives::Header; use reth_rpc_eth_api::helpers::{Call, EthCall, LoadPendingBlock, LoadState, SpawnBlocking}; use crate::EthApi; @@ -13,7 +14,7 @@ impl EthCall for EthApi Call for EthApi where Self: LoadState + SpawnBlocking, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { #[inline] fn call_gas_limit(&self) -> u64 { @@ -21,7 +22,7 @@ where } #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } } diff --git a/crates/rpc/rpc/src/eth/helpers/pending_block.rs b/crates/rpc/rpc/src/eth/helpers/pending_block.rs index 0660a92da7dc..04775a718bcd 100644 --- a/crates/rpc/rpc/src/eth/helpers/pending_block.rs +++ b/crates/rpc/rpc/src/eth/helpers/pending_block.rs @@ -2,6 +2,7 @@ use reth_chainspec::ChainSpec; use reth_evm::ConfigureEvm; +use reth_primitives::Header; use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory}; use reth_rpc_eth_api::helpers::{LoadPendingBlock, SpawnBlocking}; use reth_rpc_eth_types::PendingBlock; @@ -18,7 +19,7 @@ where + ChainSpecProvider + StateProviderFactory, Pool: TransactionPool, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { #[inline] fn provider( @@ -41,7 +42,7 @@ where } #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } } diff --git a/crates/rpc/rpc/src/eth/helpers/trace.rs b/crates/rpc/rpc/src/eth/helpers/trace.rs index fe1ee9f13cf4..c40b7acf50d1 100644 --- a/crates/rpc/rpc/src/eth/helpers/trace.rs +++ b/crates/rpc/rpc/src/eth/helpers/trace.rs @@ -1,6 +1,7 @@ //! Contains RPC handler implementations specific to tracing. use reth_evm::ConfigureEvm; +use reth_primitives::Header; use reth_rpc_eth_api::helpers::{LoadState, Trace}; use crate::EthApi; @@ -8,10 +9,10 @@ use crate::EthApi; impl Trace for EthApi where Self: LoadState, - EvmConfig: ConfigureEvm, + EvmConfig: ConfigureEvm
, { #[inline] - fn evm_config(&self) -> &impl ConfigureEvm { + fn evm_config(&self) -> &impl ConfigureEvm
{ self.inner.evm_config() } } diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 2eb598e1f944..81d7c115b743 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -1000,7 +1000,7 @@ impl EvmEnvProvider for BlockchainProvider2 { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let hash = self.convert_number(at)?.ok_or(ProviderError::HeaderNotFound(at))?; let header = self.header(&hash)?.ok_or(ProviderError::HeaderNotFound(at))?; @@ -1015,7 +1015,7 @@ impl EvmEnvProvider for BlockchainProvider2 { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let total_difficulty = self .header_td_by_number(header.number)? @@ -1031,7 +1031,7 @@ impl EvmEnvProvider for BlockchainProvider2 { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let hash = self.convert_number(at)?.ok_or(ProviderError::HeaderNotFound(at))?; let header = self.header(&hash)?.ok_or(ProviderError::HeaderNotFound(at))?; @@ -1045,7 +1045,7 @@ impl EvmEnvProvider for BlockchainProvider2 { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let total_difficulty = self .header_td_by_number(header.number)? diff --git a/crates/storage/provider/src/providers/database/mod.rs b/crates/storage/provider/src/providers/database/mod.rs index 0011e2848b1a..a055292a6298 100644 --- a/crates/storage/provider/src/providers/database/mod.rs +++ b/crates/storage/provider/src/providers/database/mod.rs @@ -550,7 +550,7 @@ impl EvmEnvProvider for ProviderFactory { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.provider()?.fill_env_at(cfg, block_env, at, evm_config) } @@ -563,7 +563,7 @@ impl EvmEnvProvider for ProviderFactory { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.provider()?.fill_env_with_header(cfg, block_env, header, evm_config) } @@ -575,7 +575,7 @@ impl EvmEnvProvider for ProviderFactory { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.provider()?.fill_cfg_env_at(cfg, at, evm_config) } @@ -587,7 +587,7 @@ impl EvmEnvProvider for ProviderFactory { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.provider()?.fill_cfg_env_with_header(cfg, header, evm_config) } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index d06a06f04985..7da5459be8fb 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -2362,7 +2362,7 @@ impl EvmEnvProvider for DatabaseProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let hash = self.convert_number(at)?.ok_or(ProviderError::HeaderNotFound(at))?; let header = self.header(&hash)?.ok_or(ProviderError::HeaderNotFound(at))?; @@ -2377,7 +2377,7 @@ impl EvmEnvProvider for DatabaseProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let total_difficulty = self .header_td_by_number(header.number)? @@ -2393,7 +2393,7 @@ impl EvmEnvProvider for DatabaseProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let hash = self.convert_number(at)?.ok_or(ProviderError::HeaderNotFound(at))?; let header = self.header(&hash)?.ok_or(ProviderError::HeaderNotFound(at))?; @@ -2407,7 +2407,7 @@ impl EvmEnvProvider for DatabaseProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { let total_difficulty = self .header_td_by_number(header.number)? diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index 6ccdcfea223c..8c404614642c 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -524,7 +524,7 @@ impl EvmEnvProvider for BlockchainProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.database.provider()?.fill_env_at(cfg, block_env, at, evm_config) } @@ -537,7 +537,7 @@ impl EvmEnvProvider for BlockchainProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.database.provider()?.fill_env_with_header(cfg, block_env, header, evm_config) } @@ -549,7 +549,7 @@ impl EvmEnvProvider for BlockchainProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.database.provider()?.fill_cfg_env_at(cfg, at, evm_config) } @@ -561,7 +561,7 @@ impl EvmEnvProvider for BlockchainProvider { evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { self.database.provider()?.fill_cfg_env_with_header(cfg, header, evm_config) } diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 2ee1fa8f2325..c14eb3d54ce9 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -680,7 +680,7 @@ impl EvmEnvProvider for MockEthProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -693,7 +693,7 @@ impl EvmEnvProvider for MockEthProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -705,7 +705,7 @@ impl EvmEnvProvider for MockEthProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -717,7 +717,7 @@ impl EvmEnvProvider for MockEthProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } diff --git a/crates/storage/provider/src/test_utils/noop.rs b/crates/storage/provider/src/test_utils/noop.rs index 0b04a74ed67b..b58cdbea36fe 100644 --- a/crates/storage/provider/src/test_utils/noop.rs +++ b/crates/storage/provider/src/test_utils/noop.rs @@ -404,7 +404,7 @@ impl EvmEnvProvider for NoopProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -417,7 +417,7 @@ impl EvmEnvProvider for NoopProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -429,7 +429,7 @@ impl EvmEnvProvider for NoopProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } @@ -441,7 +441,7 @@ impl EvmEnvProvider for NoopProvider { _evm_config: EvmConfig, ) -> ProviderResult<()> where - EvmConfig: ConfigureEvmEnv, + EvmConfig: ConfigureEvmEnv
, { Ok(()) } diff --git a/examples/custom-evm/src/main.rs b/examples/custom-evm/src/main.rs index 0df070c621b6..964c4283989d 100644 --- a/examples/custom-evm/src/main.rs +++ b/examples/custom-evm/src/main.rs @@ -108,15 +108,35 @@ impl ConfigureEvmEnv for MyEvmConfig { fn fill_cfg_env( &self, cfg_env: &mut CfgEnvWithHandlerCfg, - header: &Header, + header: &Self::Header, total_difficulty: U256, ) { self.inner.fill_cfg_env(cfg_env, header, total_difficulty); } + fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool) { + block_env.number = U256::from(header.number); + block_env.coinbase = header.beneficiary; + block_env.timestamp = U256::from(header.timestamp); + if after_merge { + block_env.prevrandao = Some(header.mix_hash); + block_env.difficulty = U256::ZERO; + } else { + block_env.difficulty = header.difficulty; + block_env.prevrandao = None; + } + block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default()); + block_env.gas_limit = U256::from(header.gas_limit); + + // EIP-4844 excess blob gas of this block, introduced in Cancun + if let Some(excess_blob_gas) = header.excess_blob_gas { + block_env.set_blob_excess_gas_and_price(excess_blob_gas); + } + } + fn next_cfg_and_block_env( &self, - parent: &Header, + parent: &Self::Header, attributes: NextBlockEnvAttributes, ) -> (CfgEnvWithHandlerCfg, BlockEnv) { self.inner.next_cfg_and_block_env(parent, attributes) diff --git a/examples/stateful-precompile/src/main.rs b/examples/stateful-precompile/src/main.rs index f8b280b77ea3..f21a111b2d47 100644 --- a/examples/stateful-precompile/src/main.rs +++ b/examples/stateful-precompile/src/main.rs @@ -164,15 +164,35 @@ impl ConfigureEvmEnv for MyEvmConfig { fn fill_cfg_env( &self, cfg_env: &mut CfgEnvWithHandlerCfg, - header: &Header, + header: &Self::Header, total_difficulty: U256, ) { self.inner.fill_cfg_env(cfg_env, header, total_difficulty) } + fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool) { + block_env.number = U256::from(header.number); + block_env.coinbase = header.beneficiary; + block_env.timestamp = U256::from(header.timestamp); + if after_merge { + block_env.prevrandao = Some(header.mix_hash); + block_env.difficulty = U256::ZERO; + } else { + block_env.difficulty = header.difficulty; + block_env.prevrandao = None; + } + block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default()); + block_env.gas_limit = U256::from(header.gas_limit); + + // EIP-4844 excess blob gas of this block, introduced in Cancun + if let Some(excess_blob_gas) = header.excess_blob_gas { + block_env.set_blob_excess_gas_and_price(excess_blob_gas); + } + } + fn next_cfg_and_block_env( &self, - parent: &Header, + parent: &Self::Header, attributes: NextBlockEnvAttributes, ) -> (CfgEnvWithHandlerCfg, BlockEnv) { self.inner.next_cfg_and_block_env(parent, attributes)