diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 205c85160dcd..ae16d3f99239 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -9,6 +9,7 @@ use op_alloy_consensus::DepositTransaction; use reth_chainspec::EthereumHardforks; use reth_consensus::ConsensusError; use reth_evm::{ + env::EvmEnv, execute::{ balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput, @@ -111,8 +112,9 @@ where /// /// Caution: this does not initialize the tx environment. fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg { - let (cfg, block_env) = self.evm_config.cfg_and_block_env(header, total_difficulty); - EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()) + let evm_env = self.evm_config.cfg_and_block_env(header, total_difficulty); + let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env; + EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default()) } } diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index fb1f9fda7acc..ec5d2ce00560 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -16,7 +16,7 @@ use alloc::{sync::Arc, vec::Vec}; use alloy_consensus::Header; use alloy_primitives::{Address, U256}; use op_alloy_consensus::EIP1559ParamError; -use reth_evm::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes}; +use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes}; use reth_optimism_chainspec::OpChainSpec; use reth_primitives::{transaction::FillTxEnv, Head, TransactionSigned}; use reth_revm::{ @@ -138,7 +138,7 @@ impl ConfigureEvmEnv for OpEvmConfig { &self, parent: &Self::Header, attributes: NextBlockEnvAttributes, - ) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { + ) -> Result { // configure evm env based on parent block let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id()); @@ -173,7 +173,7 @@ impl ConfigureEvmEnv for OpEvmConfig { }; } - Ok((cfg_env_with_handler_cfg, block_env)) + Ok((cfg_env_with_handler_cfg, block_env).into()) } } @@ -251,12 +251,13 @@ mod tests { // Use the `OpEvmConfig` to create the `cfg_env` and `block_env` based on the ChainSpec, // Header, and total difficulty - let (cfg_env, _) = OpEvmConfig::new(Arc::new(OpChainSpec { inner: chain_spec.clone() })) - .cfg_and_block_env(&header, total_difficulty); + let EvmEnv { cfg_env_with_handler_cfg, .. } = + OpEvmConfig::new(Arc::new(OpChainSpec { inner: chain_spec.clone() })) + .cfg_and_block_env(&header, total_difficulty); // Assert that the chain ID in the `cfg_env` is correctly set to the chain ID of the // ChainSpec - assert_eq!(cfg_env.chain_id, chain_spec.chain().id()); + assert_eq!(cfg_env_with_handler_cfg.chain_id, chain_spec.chain().id()); } #[test] diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 0af6832f656f..5dcd81cf96ba 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -15,7 +15,7 @@ use op_alloy_rpc_types_engine::OpPayloadAttributes; use reth_basic_payload_builder::*; use reth_chain_state::ExecutedBlock; use reth_chainspec::{ChainSpecProvider, EthereumHardforks}; -use reth_evm::{system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes}; +use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes}; use reth_execution_types::ExecutionOutcome; use reth_optimism_chainspec::OpChainSpec; use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; @@ -124,9 +124,10 @@ where Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool>, { - let (initialized_cfg, initialized_block_env) = self + let evm_env = self .cfg_and_block_env(&args.config.attributes, &args.config.parent_header) .map_err(PayloadBuilderError::other)?; + let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env; let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args; @@ -134,8 +135,8 @@ where evm_config: self.evm_config.clone(), chain_spec: client.chain_spec(), config, - initialized_cfg, - initialized_block_env, + initialized_cfg: cfg_env_with_handler_cfg, + initialized_block_env: block_env, cancel, best_payload, }; @@ -164,13 +165,13 @@ impl OpPayloadBuilder where EvmConfig: ConfigureEvm
, { - /// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the targeted payload + /// Returns the configured [`EvmEnv`] for the targeted payload /// (that has the `parent` as its parent). pub fn cfg_and_block_env( &self, attributes: &OpPayloadBuilderAttributes, parent: &Header, - ) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), EvmConfig::Error> { + ) -> Result { let next_attributes = NextBlockEnvAttributes { timestamp: attributes.timestamp(), suggested_fee_recipient: attributes.suggested_fee_recipient(), @@ -193,16 +194,17 @@ where let attributes = OpPayloadBuilderAttributes::try_new(parent.hash(), attributes, 3) .map_err(PayloadBuilderError::other)?; - let (initialized_cfg, initialized_block_env) = + let evm_env = self.cfg_and_block_env(&attributes, &parent).map_err(PayloadBuilderError::other)?; + let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env; let config = PayloadConfig { parent_header: Arc::new(parent), attributes }; let ctx = OpPayloadBuilderCtx { evm_config: self.evm_config.clone(), chain_spec: client.chain_spec(), config, - initialized_cfg, - initialized_block_env, + initialized_cfg: cfg_env_with_handler_cfg, + initialized_block_env: block_env, cancel: Default::default(), best_payload: Default::default(), };