chore: Introduce helper type for evm cfg and env tuple (#13377)

This commit is contained in:
Ayodeji Akinola
2024-12-14 09:53:59 +01:00
committed by GitHub
parent 16f6d7a0c3
commit b525231224
33 changed files with 290 additions and 165 deletions

2
Cargo.lock generated
View File

@ -2944,6 +2944,7 @@ dependencies = [
"eyre", "eyre",
"reth", "reth",
"reth-chainspec", "reth-chainspec",
"reth-evm",
"reth-evm-ethereum", "reth-evm-ethereum",
"reth-node-api", "reth-node-api",
"reth-node-core", "reth-node-core",
@ -3132,6 +3133,7 @@ dependencies = [
"parking_lot", "parking_lot",
"reth", "reth",
"reth-chainspec", "reth-chainspec",
"reth-evm",
"reth-node-api", "reth-node-api",
"reth-node-core", "reth-node-core",
"reth-node-ethereum", "reth-node-ethereum",

View File

@ -6,7 +6,8 @@ use pretty_assertions::Comparison;
use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_engine_primitives::InvalidBlockHook; use reth_engine_primitives::InvalidBlockHook;
use reth_evm::{ use reth_evm::{
state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm, env::EvmEnv, state_change::post_block_balance_increments, system_calls::SystemCaller,
ConfigureEvm,
}; };
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader}; use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
use reth_primitives_traits::SignedTransaction; use reth_primitives_traits::SignedTransaction;
@ -77,12 +78,17 @@ where
.build(); .build();
// Setup environment for the execution. // Setup environment for the execution.
let (cfg, block_env) = self.evm_config.cfg_and_block_env(block.header(), U256::MAX); let EvmEnv { cfg_env_with_handler_cfg, block_env } =
self.evm_config.cfg_and_block_env(block.header(), U256::MAX);
// Setup EVM // Setup EVM
let mut evm = self.evm_config.evm_with_env( let mut evm = self.evm_config.evm_with_env(
&mut db, &mut db,
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()), EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg,
block_env,
Default::default(),
),
); );
let mut system_caller = let mut system_caller =

View File

@ -14,8 +14,8 @@ use reth_engine_primitives::{
use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResult}; use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResult};
use reth_ethereum_forks::EthereumHardforks; use reth_ethereum_forks::EthereumHardforks;
use reth_evm::{ use reth_evm::{
state_change::post_block_withdrawals_balance_increments, system_calls::SystemCaller, env::EvmEnv, state_change::post_block_withdrawals_balance_increments,
ConfigureEvm, system_calls::SystemCaller, ConfigureEvm,
}; };
use reth_payload_validator::ExecutionPayloadValidator; use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{ use reth_primitives::{
@ -298,8 +298,13 @@ where
.build(); .build();
// Configure environments // Configure environments
let (cfg, block_env) = evm_config.cfg_and_block_env(&reorg_target.header, U256::MAX); let EvmEnv { cfg_env_with_handler_cfg, block_env } =
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()); evm_config.cfg_and_block_env(&reorg_target.header, U256::MAX);
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg,
block_env,
Default::default(),
);
let mut evm = evm_config.evm_with_env(&mut state, env); let mut evm = evm_config.evm_with_env(&mut state, env);
// apply eip-4788 pre block contract call // apply eip-4788 pre block contract call

View File

@ -12,6 +12,7 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
use reth_consensus::ConsensusError; use reth_consensus::ConsensusError;
use reth_ethereum_consensus::validate_block_post_execution; use reth_ethereum_consensus::validate_block_post_execution;
use reth_evm::{ use reth_evm::{
env::EvmEnv,
execute::{ execute::{
balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError, balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError,
BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput, BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput,
@ -127,8 +128,9 @@ where
header: &alloy_consensus::Header, header: &alloy_consensus::Header,
total_difficulty: U256, total_difficulty: U256,
) -> EnvWithHandlerCfg { ) -> EnvWithHandlerCfg {
let (cfg, block_env) = self.evm_config.cfg_and_block_env(header, total_difficulty); let EvmEnv { cfg_env_with_handler_cfg, block_env } =
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()) self.evm_config.cfg_and_block_env(header, total_difficulty);
EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default())
} }
} }

View File

@ -23,7 +23,7 @@ use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::Header; use alloy_consensus::Header;
use alloy_primitives::{Address, Bytes, TxKind, U256}; use alloy_primitives::{Address, Bytes, TxKind, U256};
use reth_chainspec::{ChainSpec, Head}; use reth_chainspec::{ChainSpec, Head};
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes}; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_primitives::{transaction::FillTxEnv, TransactionSigned}; use reth_primitives::{transaction::FillTxEnv, TransactionSigned};
use revm_primitives::{ use revm_primitives::{
AnalysisKind, BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, Env, SpecId, TxEnv, AnalysisKind, BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, Env, SpecId, TxEnv,
@ -136,7 +136,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
&self, &self,
parent: &Self::Header, parent: &Self::Header,
attributes: NextBlockEnvAttributes, attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { ) -> Result<EvmEnv, Self::Error> {
// configure evm env based on parent block // configure evm env based on parent block
let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id()); let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());
@ -184,7 +184,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
blob_excess_gas_and_price, blob_excess_gas_and_price,
}; };
Ok((CfgEnvWithHandlerCfg::new_with_spec_id(cfg, spec_id), block_env)) Ok((CfgEnvWithHandlerCfg::new_with_spec_id(cfg, spec_id), block_env).into())
} }
} }
@ -201,7 +201,7 @@ mod tests {
use alloy_genesis::Genesis; use alloy_genesis::Genesis;
use alloy_primitives::{B256, U256}; use alloy_primitives::{B256, U256};
use reth_chainspec::{Chain, ChainSpec, MAINNET}; use reth_chainspec::{Chain, ChainSpec, MAINNET};
use reth_evm::execute::ProviderError; use reth_evm::{env::EvmEnv, execute::ProviderError};
use reth_revm::{ use reth_revm::{
db::{CacheDB, EmptyDBTyped}, db::{CacheDB, EmptyDBTyped},
inspectors::NoOpInspector, inspectors::NoOpInspector,
@ -231,12 +231,13 @@ mod tests {
// Use the `EthEvmConfig` to fill the `cfg_env` and `block_env` based on the ChainSpec, // Use the `EthEvmConfig` to fill the `cfg_env` and `block_env` based on the ChainSpec,
// Header, and total difficulty // Header, and total difficulty
let (cfg_env, _) = EthEvmConfig::new(Arc::new(chain_spec.clone())) let EvmEnv { cfg_env_with_handler_cfg, .. } =
.cfg_and_block_env(&header, total_difficulty); EthEvmConfig::new(Arc::new(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 // Assert that the chain ID in the `cfg_env` is correctly set to the chain ID of the
// ChainSpec // 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] #[test]

View File

@ -21,7 +21,7 @@ use reth_basic_payload_builder::{
use reth_chain_state::ExecutedBlock; use reth_chain_state::ExecutedBlock;
use reth_chainspec::{ChainSpec, ChainSpecProvider}; use reth_chainspec::{ChainSpec, ChainSpecProvider};
use reth_errors::RethError; use reth_errors::RethError;
use reth_evm::{system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes}; use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, NextBlockEnvAttributes};
use reth_evm_ethereum::{eip6110::parse_deposits_from_receipts, EthEvmConfig}; use reth_evm_ethereum::{eip6110::parse_deposits_from_receipts, EthEvmConfig};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes}; use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes};
@ -82,7 +82,7 @@ where
&self, &self,
config: &PayloadConfig<EthPayloadBuilderAttributes>, config: &PayloadConfig<EthPayloadBuilderAttributes>,
parent: &Header, parent: &Header,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), EvmConfig::Error> { ) -> Result<EvmEnv, EvmConfig::Error> {
let next_attributes = NextBlockEnvAttributes { let next_attributes = NextBlockEnvAttributes {
timestamp: config.attributes.timestamp(), timestamp: config.attributes.timestamp(),
suggested_fee_recipient: config.attributes.suggested_fee_recipient(), suggested_fee_recipient: config.attributes.suggested_fee_recipient(),
@ -107,7 +107,7 @@ where
&self, &self,
args: BuildArguments<Pool, Client, EthPayloadBuilderAttributes, EthBuiltPayload>, args: BuildArguments<Pool, Client, EthPayloadBuilderAttributes, EthBuiltPayload>,
) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError> { ) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError> {
let (cfg_env, block_env) = self let EvmEnv { cfg_env_with_handler_cfg, block_env } = self
.cfg_and_block_env(&args.config, &args.config.parent_header) .cfg_and_block_env(&args.config, &args.config.parent_header)
.map_err(PayloadBuilderError::other)?; .map_err(PayloadBuilderError::other)?;
@ -116,7 +116,7 @@ where
self.evm_config.clone(), self.evm_config.clone(),
self.builder_config.clone(), self.builder_config.clone(),
args, args,
cfg_env, cfg_env_with_handler_cfg,
block_env, block_env,
|attributes| pool.best_transactions_with_attributes(attributes), |attributes| pool.best_transactions_with_attributes(attributes),
) )
@ -137,7 +137,7 @@ where
None, None,
); );
let (cfg_env, block_env) = self let EvmEnv { cfg_env_with_handler_cfg, block_env } = self
.cfg_and_block_env(&args.config, &args.config.parent_header) .cfg_and_block_env(&args.config, &args.config.parent_header)
.map_err(PayloadBuilderError::other)?; .map_err(PayloadBuilderError::other)?;
@ -147,7 +147,7 @@ where
self.evm_config.clone(), self.evm_config.clone(),
self.builder_config.clone(), self.builder_config.clone(),
args, args,
cfg_env, cfg_env_with_handler_cfg,
block_env, block_env,
|attributes| pool.best_transactions_with_attributes(attributes), |attributes| pool.best_transactions_with_attributes(attributes),
)? )?

44
crates/evm/src/env.rs Normal file
View File

@ -0,0 +1,44 @@
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
/// Container type that holds both the configuration and block environment for EVM execution.
#[derive(Debug, Clone)]
pub struct EvmEnv {
/// The configuration environment with handler settings
pub cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg,
/// The block environment containing block-specific data
pub block_env: BlockEnv,
}
impl EvmEnv {
/// Create a new `EvmEnv` from its components.
///
/// # Arguments
///
/// * `cfg_env_with_handler_cfg` - The configuration environment with handler settings
/// * `block` - The block environment containing block-specific data
pub const fn new(cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg, block_env: BlockEnv) -> Self {
Self { cfg_env_with_handler_cfg, block_env }
}
/// Returns a reference to the block environment.
pub const fn block_env(&self) -> &BlockEnv {
&self.block_env
}
/// Returns a reference to the configuration environment.
pub const fn cfg_env_with_handler_cfg(&self) -> &CfgEnvWithHandlerCfg {
&self.cfg_env_with_handler_cfg
}
}
impl From<(CfgEnvWithHandlerCfg, BlockEnv)> for EvmEnv {
fn from((cfg_env_with_handler_cfg, block_env): (CfgEnvWithHandlerCfg, BlockEnv)) -> Self {
Self { cfg_env_with_handler_cfg, block_env }
}
}
impl From<EvmEnv> for (CfgEnvWithHandlerCfg, BlockEnv) {
fn from(env: EvmEnv) -> Self {
(env.cfg_env_with_handler_cfg, env.block_env)
}
}

View File

@ -26,7 +26,11 @@ use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, Sp
pub mod builder; pub mod builder;
pub mod either; pub mod either;
/// EVM environment configuration.
pub mod env;
pub mod execute; pub mod execute;
use env::EvmEnv;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod metrics; pub mod metrics;
pub mod noop; pub mod noop;
@ -179,16 +183,12 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
} }
} }
/// Creates a new [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the given header. /// Creates a new [`EvmEnv`] for the given header.
fn cfg_and_block_env( fn cfg_and_block_env(&self, header: &Self::Header, total_difficulty: U256) -> EvmEnv {
&self,
header: &Self::Header,
total_difficulty: U256,
) -> (CfgEnvWithHandlerCfg, BlockEnv) {
let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default()); let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
let mut block_env = BlockEnv::default(); let mut block_env = BlockEnv::default();
self.fill_cfg_and_block_env(&mut cfg, &mut block_env, header, total_difficulty); self.fill_cfg_and_block_env(&mut cfg, &mut block_env, header, total_difficulty);
(cfg, block_env) EvmEnv::new(cfg, block_env)
} }
/// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and /// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and
@ -207,7 +207,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
self.fill_block_env(block_env, header, after_merge); self.fill_block_env(block_env, header, after_merge);
} }
/// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for `parent + 1` block. /// Returns the configured [`EvmEnv`] for `parent + 1` block.
/// ///
/// This is intended for usage in block building after the merge and requires additional /// This is intended for usage in block building after the merge and requires additional
/// attributes that can't be derived from the parent block: attributes that are determined by /// attributes that can't be derived from the parent block: attributes that are determined by
@ -216,7 +216,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
&self, &self,
parent: &Self::Header, parent: &Self::Header,
attributes: NextBlockEnvAttributes, attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error>; ) -> Result<EvmEnv, Self::Error>;
} }
/// Represents additional attributes required to configure the next block. /// Represents additional attributes required to configure the next block.

View File

@ -1,24 +1,23 @@
//! Provider trait for populating the EVM environment. //! Provider trait for populating the EVM environment.
use crate::ConfigureEvmEnv; use crate::{env::EvmEnv, ConfigureEvmEnv};
use alloy_consensus::Header; use alloy_consensus::Header;
use reth_storage_errors::provider::ProviderResult; use reth_storage_errors::provider::ProviderResult;
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
/// A provider type that knows chain specific information required to configure a /// A provider type that knows chain specific information required to configure a
/// [`CfgEnvWithHandlerCfg`]. /// [`EvmEnv`].
/// ///
/// This type is mainly used to provide required data to configure the EVM environment that is /// This type is mainly used to provide required data to configure the EVM environment that is
/// not part of the block and stored separately (on disk), for example the total difficulty. /// not part of the block and stored separately (on disk), for example the total difficulty.
#[auto_impl::auto_impl(&, Arc)] #[auto_impl::auto_impl(&, Arc)]
pub trait EvmEnvProvider<H = Header>: Send + Sync { pub trait EvmEnvProvider<H = Header>: Send + Sync {
/// Fills the default [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the /// Fills the default [`EvmEnv`] fields with values specific to the
/// given block header. /// given block header.
fn env_with_header<EvmConfig>( fn env_with_header<EvmConfig>(
&self, &self,
header: &H, header: &H,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = H>; EvmConfig: ConfigureEvmEnv<Header = H>;
} }

View File

@ -1,6 +1,7 @@
//! Helpers for testing. //! Helpers for testing.
use crate::{ use crate::{
env::EvmEnv,
execute::{ execute::{
BasicBatchExecutor, BasicBlockExecutor, BatchExecutor, BlockExecutionInput, BasicBatchExecutor, BasicBlockExecutor, BatchExecutor, BlockExecutionInput,
BlockExecutionOutput, BlockExecutionStrategy, BlockExecutorProvider, Executor, BlockExecutionOutput, BlockExecutionStrategy, BlockExecutorProvider, Executor,
@ -18,7 +19,7 @@ use reth_primitives::{BlockWithSenders, EthPrimitives, NodePrimitives, Receipt,
use reth_prune_types::PruneModes; use reth_prune_types::PruneModes;
use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_storage_errors::provider::{ProviderError, ProviderResult};
use revm::State; use revm::State;
use revm_primitives::{db::Database, BlockEnv, CfgEnvWithHandlerCfg}; use revm_primitives::db::Database;
use std::{fmt::Display, sync::Arc}; use std::{fmt::Display, sync::Arc};
impl<C: Send + Sync, N: NodePrimitives> EvmEnvProvider<N::BlockHeader> impl<C: Send + Sync, N: NodePrimitives> EvmEnvProvider<N::BlockHeader>
@ -28,7 +29,7 @@ impl<C: Send + Sync, N: NodePrimitives> EvmEnvProvider<N::BlockHeader>
&self, &self,
header: &N::BlockHeader, header: &N::BlockHeader,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = N::BlockHeader>, EvmConfig: ConfigureEvmEnv<Header = N::BlockHeader>,
{ {

View File

@ -9,6 +9,7 @@ use op_alloy_consensus::DepositTransaction;
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
use reth_consensus::ConsensusError; use reth_consensus::ConsensusError;
use reth_evm::{ use reth_evm::{
env::EvmEnv,
execute::{ execute::{
balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError, balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError,
BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput, BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput,
@ -111,8 +112,9 @@ where
/// ///
/// Caution: this does not initialize the tx environment. /// Caution: this does not initialize the tx environment.
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg { 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); let evm_env = self.evm_config.cfg_and_block_env(header, total_difficulty);
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()) 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())
} }
} }

View File

@ -16,7 +16,7 @@ use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::Header; use alloy_consensus::Header;
use alloy_primitives::{Address, U256}; use alloy_primitives::{Address, U256};
use op_alloy_consensus::EIP1559ParamError; 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_optimism_chainspec::OpChainSpec;
use reth_primitives::{transaction::FillTxEnv, Head, TransactionSigned}; use reth_primitives::{transaction::FillTxEnv, Head, TransactionSigned};
use reth_revm::{ use reth_revm::{
@ -138,7 +138,7 @@ impl ConfigureEvmEnv for OpEvmConfig {
&self, &self,
parent: &Self::Header, parent: &Self::Header,
attributes: NextBlockEnvAttributes, attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { ) -> Result<EvmEnv, Self::Error> {
// configure evm env based on parent block // configure evm env based on parent block
let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id()); let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());
@ -165,15 +165,15 @@ impl ConfigureEvmEnv for OpEvmConfig {
blob_excess_gas_and_price, blob_excess_gas_and_price,
}; };
let cfg_with_handler_cfg; let cfg_env_with_handler_cfg;
{ {
cfg_with_handler_cfg = CfgEnvWithHandlerCfg { cfg_env_with_handler_cfg = CfgEnvWithHandlerCfg {
cfg_env: cfg, cfg_env: cfg,
handler_cfg: HandlerCfg { spec_id, is_optimism: true }, handler_cfg: HandlerCfg { spec_id, is_optimism: true },
}; };
} }
Ok((cfg_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, // Use the `OpEvmConfig` to create the `cfg_env` and `block_env` based on the ChainSpec,
// Header, and total difficulty // Header, and total difficulty
let (cfg_env, _) = OpEvmConfig::new(Arc::new(OpChainSpec { inner: chain_spec.clone() })) let EvmEnv { cfg_env_with_handler_cfg, .. } =
.cfg_and_block_env(&header, total_difficulty); 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 // Assert that the chain ID in the `cfg_env` is correctly set to the chain ID of the
// ChainSpec // 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] #[test]

View File

@ -15,7 +15,7 @@ use op_alloy_rpc_types_engine::OpPayloadAttributes;
use reth_basic_payload_builder::*; use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock; use reth_chain_state::ExecutedBlock;
use reth_chainspec::{ChainSpecProvider, EthereumHardforks}; 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_execution_types::ExecutionOutcome;
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
@ -124,9 +124,10 @@ where
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = OpChainSpec>, Client: StateProviderFactory + ChainSpecProvider<ChainSpec = OpChainSpec>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>, Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>,
{ {
let (initialized_cfg, initialized_block_env) = self let evm_env = self
.cfg_and_block_env(&args.config.attributes, &args.config.parent_header) .cfg_and_block_env(&args.config.attributes, &args.config.parent_header)
.map_err(PayloadBuilderError::other)?; .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; let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args;
@ -134,8 +135,8 @@ where
evm_config: self.evm_config.clone(), evm_config: self.evm_config.clone(),
chain_spec: client.chain_spec(), chain_spec: client.chain_spec(),
config, config,
initialized_cfg, initialized_cfg: cfg_env_with_handler_cfg,
initialized_block_env, initialized_block_env: block_env,
cancel, cancel,
best_payload, best_payload,
}; };
@ -164,13 +165,13 @@ impl<EvmConfig, Txs> OpPayloadBuilder<EvmConfig, Txs>
where where
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>, EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
{ {
/// 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). /// (that has the `parent` as its parent).
pub fn cfg_and_block_env( pub fn cfg_and_block_env(
&self, &self,
attributes: &OpPayloadBuilderAttributes, attributes: &OpPayloadBuilderAttributes,
parent: &Header, parent: &Header,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), EvmConfig::Error> { ) -> Result<EvmEnv, EvmConfig::Error> {
let next_attributes = NextBlockEnvAttributes { let next_attributes = NextBlockEnvAttributes {
timestamp: attributes.timestamp(), timestamp: attributes.timestamp(),
suggested_fee_recipient: attributes.suggested_fee_recipient(), suggested_fee_recipient: attributes.suggested_fee_recipient(),
@ -193,16 +194,17 @@ where
let attributes = OpPayloadBuilderAttributes::try_new(parent.hash(), attributes, 3) let attributes = OpPayloadBuilderAttributes::try_new(parent.hash(), attributes, 3)
.map_err(PayloadBuilderError::other)?; .map_err(PayloadBuilderError::other)?;
let (initialized_cfg, initialized_block_env) = let evm_env =
self.cfg_and_block_env(&attributes, &parent).map_err(PayloadBuilderError::other)?; 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 config = PayloadConfig { parent_header: Arc::new(parent), attributes };
let ctx = OpPayloadBuilderCtx { let ctx = OpPayloadBuilderCtx {
evm_config: self.evm_config.clone(), evm_config: self.evm_config.clone(),
chain_spec: client.chain_spec(), chain_spec: client.chain_spec(),
config, config,
initialized_cfg, initialized_cfg: cfg_env_with_handler_cfg,
initialized_block_env, initialized_block_env: block_env,
cancel: Default::default(), cancel: Default::default(),
best_payload: Default::default(), best_payload: Default::default(),
}; };

View File

@ -17,7 +17,7 @@ use alloy_rpc_types_eth::{
}; };
use futures::Future; use futures::Future;
use reth_chainspec::EthChainSpec; use reth_chainspec::EthChainSpec;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv};
use reth_node_api::BlockBody; use reth_node_api::BlockBody;
use reth_primitives_traits::SignedTransaction; use reth_primitives_traits::SignedTransaction;
use reth_provider::{BlockIdReader, ChainSpecProvider, ProviderHeader}; use reth_provider::{BlockIdReader, ChainSpecProvider, ProviderHeader};
@ -86,8 +86,8 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
} }
// Build cfg and block env, we'll reuse those. // Build cfg and block env, we'll reuse those.
let (mut cfg, mut block_env, block) = let (evm_env, block) = self.evm_env_at(block.unwrap_or_default()).await?;
self.evm_env_at(block.unwrap_or_default()).await?; let EvmEnv { mut cfg_env_with_handler_cfg, mut block_env } = evm_env;
// Gas cap for entire operation // Gas cap for entire operation
let total_gas_limit = self.call_gas_limit(); let total_gas_limit = self.call_gas_limit();
@ -97,9 +97,9 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let mut parent_hash = base_block.hash(); let mut parent_hash = base_block.hash();
// Only enforce base fee if validation is enabled // Only enforce base fee if validation is enabled
cfg.disable_base_fee = !validation; cfg_env_with_handler_cfg.disable_base_fee = !validation;
// Always disable EIP-3607 // Always disable EIP-3607
cfg.disable_eip3607 = true; cfg_env_with_handler_cfg.disable_eip3607 = true;
let this = self.clone(); let this = self.clone();
self.spawn_with_state_at_block(block, move |state| { self.spawn_with_state_at_block(block, move |state| {
@ -155,7 +155,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
&mut calls, &mut calls,
validation, validation,
block_env.gas_limit.to(), block_env.gas_limit.to(),
cfg.chain_id, cfg_env_with_handler_cfg.chain_id,
&mut db, &mut db,
this.tx_resp_builder(), this.tx_resp_builder(),
)?; )?;
@ -165,7 +165,11 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let mut results = Vec::with_capacity(calls.len()); let mut results = Vec::with_capacity(calls.len());
while let Some(tx) = calls.next() { while let Some(tx) = calls.next() {
let env = this.build_call_evm_env(cfg.clone(), block_env.clone(), tx)?; let env = this.build_call_evm_env(
cfg_env_with_handler_cfg.clone(),
block_env.clone(),
tx,
)?;
let (res, env) = { let (res, env) = {
if trace_transfers { if trace_transfers {
@ -268,10 +272,11 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
.into(); .into();
} }
let ((cfg, block_env, _), block) = futures::try_join!( let ((evm_env, _), block) = futures::try_join!(
self.evm_env_at(target_block), self.evm_env_at(target_block),
self.block_with_senders(target_block) self.block_with_senders(target_block)
)?; )?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?; let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?;
@ -302,7 +307,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let transactions = block.transactions_with_sender().take(num_txs); let transactions = block.transactions_with_sender().take(num_txs);
for (signer, tx) in transactions { for (signer, tx) in transactions {
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
RpcNodeCore::evm_config(&this).tx_env(tx, *signer), RpcNodeCore::evm_config(&this).tx_env(tx, *signer),
); );
@ -320,7 +325,13 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let overrides = EvmOverrides::new(state_overrides, block_overrides.clone()); let overrides = EvmOverrides::new(state_overrides, block_overrides.clone());
let env = this let env = this
.prepare_call_env(cfg.clone(), block_env.clone(), tx, &mut db, overrides) .prepare_call_env(
cfg_env_with_handler_cfg.clone(),
block_env.clone(),
tx,
&mut db,
overrides,
)
.map(Into::into)?; .map(Into::into)?;
let (res, _) = this.transact(&mut db, env)?; let (res, _) = this.transact(&mut db, env)?;
@ -361,10 +372,11 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
{ {
async move { async move {
let block_id = block_number.unwrap_or_default(); let block_id = block_number.unwrap_or_default();
let (cfg, block, at) = self.evm_env_at(block_id).await?; let (evm_env, at) = self.evm_env_at(block_id).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
self.spawn_blocking_io(move |this| { self.spawn_blocking_io(move |this| {
this.create_access_list_with(cfg, block, at, request) this.create_access_list_with(cfg_env_with_handler_cfg, block_env, at, request)
}) })
.await .await
} }
@ -571,14 +583,21 @@ pub trait Call:
R: Send + 'static, R: Send + 'static,
{ {
async move { async move {
let (cfg, block_env, at) = self.evm_env_at(at).await?; let (evm_env, at) = self.evm_env_at(at).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let this = self.clone(); let this = self.clone();
self.spawn_blocking_io(move |_| { self.spawn_blocking_io(move |_| {
let state = this.state_at_block_id(at)?; let state = this.state_at_block_id(at)?;
let mut db = let mut db =
CacheDB::new(StateProviderDatabase::new(StateProviderTraitObjWrapper(&state))); CacheDB::new(StateProviderDatabase::new(StateProviderTraitObjWrapper(&state)));
let env = this.prepare_call_env(cfg, block_env, request, &mut db, overrides)?; let env = this.prepare_call_env(
cfg_env_with_handler_cfg,
block_env,
request,
&mut db,
overrides,
)?;
f(StateCacheDbRefMutWrapper(&mut db), env) f(StateCacheDbRefMutWrapper(&mut db), env)
}) })
@ -614,7 +633,8 @@ pub trait Call:
}; };
let (tx, tx_info) = transaction.split(); let (tx, tx_info) = transaction.split();
let (cfg, block_env, _) = self.evm_env_at(block.hash().into()).await?; let (evm_env, _) = self.evm_env_at(block.hash().into()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
// we need to get the state of the parent block because we're essentially replaying the // we need to get the state of the parent block because we're essentially replaying the
// block the transaction is included in // block the transaction is included in
@ -628,14 +648,14 @@ pub trait Call:
// replay all transactions prior to the targeted transaction // replay all transactions prior to the targeted transaction
this.replay_transactions_until( this.replay_transactions_until(
&mut db, &mut db,
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
block_txs, block_txs,
*tx.tx_hash(), *tx.tx_hash(),
)?; )?;
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()), RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
); );

View File

@ -6,6 +6,7 @@ use alloy_primitives::U256;
use alloy_rpc_types_eth::{state::StateOverride, transaction::TransactionRequest, BlockId}; use alloy_rpc_types_eth::{state::StateOverride, transaction::TransactionRequest, BlockId};
use futures::Future; use futures::Future;
use reth_chainspec::MIN_TRANSACTION_GAS; use reth_chainspec::MIN_TRANSACTION_GAS;
use reth_evm::env::EvmEnv;
use reth_provider::StateProvider; use reth_provider::StateProvider;
use reth_revm::{ use reth_revm::{
database::StateProviderDatabase, database::StateProviderDatabase,
@ -259,13 +260,14 @@ pub trait EstimateCall: Call {
Self: LoadPendingBlock, Self: LoadPendingBlock,
{ {
async move { async move {
let (cfg, block_env, at) = self.evm_env_at(at).await?; let (evm_env, at) = self.evm_env_at(at).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
self.spawn_blocking_io(move |this| { self.spawn_blocking_io(move |this| {
let state = this.state_at_block_id(at)?; let state = this.state_at_block_id(at)?;
EstimateCall::estimate_gas_with( EstimateCall::estimate_gas_with(
&this, &this,
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
request, request,
state, state,

View File

@ -12,8 +12,8 @@ use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_errors::RethError; use reth_errors::RethError;
use reth_evm::{ use reth_evm::{
state_change::post_block_withdrawals_balance_increments, system_calls::SystemCaller, env::EvmEnv, state_change::post_block_withdrawals_balance_increments,
ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes, system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes,
}; };
use reth_primitives::{BlockExt, InvalidTransactionError, SealedBlockWithSenders}; use reth_primitives::{BlockExt, InvalidTransactionError, SealedBlockWithSenders};
use reth_primitives_traits::Receipt; use reth_primitives_traits::Receipt;
@ -87,13 +87,15 @@ pub trait LoadPendingBlock:
// Note: for the PENDING block we assume it is past the known merge block and // Note: for the PENDING block we assume it is past the known merge block and
// thus this will not fail when looking up the total // thus this will not fail when looking up the total
// difficulty value for the blockenv. // difficulty value for the blockenv.
let (cfg, block_env) = self let evm_env = self
.provider() .provider()
.env_with_header(block.header(), self.evm_config().clone()) .env_with_header(block.header(), self.evm_config().clone())
.map_err(Self::Error::from_eth_err)?; .map_err(Self::Error::from_eth_err)?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
return Ok(PendingBlockEnv::new( return Ok(PendingBlockEnv::new(
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
PendingBlockEnvOrigin::ActualPending(block, receipts), PendingBlockEnvOrigin::ActualPending(block, receipts),
)); ));
@ -108,7 +110,7 @@ pub trait LoadPendingBlock:
.map_err(Self::Error::from_eth_err)? .map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(BlockNumberOrTag::Latest.into()))?; .ok_or(EthApiError::HeaderNotFound(BlockNumberOrTag::Latest.into()))?;
let (cfg, block_env) = self let EvmEnv { cfg_env_with_handler_cfg, block_env } = self
.evm_config() .evm_config()
.next_cfg_and_block_env( .next_cfg_and_block_env(
&latest, &latest,
@ -123,7 +125,7 @@ pub trait LoadPendingBlock:
.map_err(Self::Error::from_eth_err)?; .map_err(Self::Error::from_eth_err)?;
Ok(PendingBlockEnv::new( Ok(PendingBlockEnv::new(
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
PendingBlockEnvOrigin::DerivedFromLatest(latest.hash()), PendingBlockEnvOrigin::DerivedFromLatest(latest.hash()),
)) ))

View File

@ -10,14 +10,14 @@ use alloy_serde::JsonStorageKey;
use futures::Future; use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_errors::RethError; use reth_errors::RethError;
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_provider::{ use reth_provider::{
BlockIdReader, BlockNumReader, ChainSpecProvider, EvmEnvProvider as _, ProviderHeader, BlockIdReader, BlockNumReader, ChainSpecProvider, EvmEnvProvider as _, ProviderHeader,
StateProvider, StateProviderBox, StateProviderFactory, StateProvider, StateProviderBox, StateProviderFactory,
}; };
use reth_rpc_eth_types::{EthApiError, PendingBlockEnv, RpcInvalidTransactionError}; use reth_rpc_eth_types::{EthApiError, PendingBlockEnv, RpcInvalidTransactionError};
use reth_transaction_pool::TransactionPool; use reth_transaction_pool::TransactionPool;
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId}; use revm_primitives::SpecId;
/// Helper methods for `eth_` methods relating to state (accounts). /// Helper methods for `eth_` methods relating to state (accounts).
pub trait EthState: LoadState + SpawnBlocking { pub trait EthState: LoadState + SpawnBlocking {
@ -214,7 +214,7 @@ pub trait LoadState:
fn evm_env_at( fn evm_env_at(
&self, &self,
at: BlockId, at: BlockId,
) -> impl Future<Output = Result<(CfgEnvWithHandlerCfg, BlockEnv, BlockId), Self::Error>> + Send ) -> impl Future<Output = Result<(EvmEnv, BlockId), Self::Error>> + Send
where where
Self: LoadPendingBlock + SpawnBlocking, Self: LoadPendingBlock + SpawnBlocking,
{ {
@ -222,7 +222,7 @@ pub trait LoadState:
if at.is_pending() { if at.is_pending() {
let PendingBlockEnv { cfg, block_env, origin } = let PendingBlockEnv { cfg, block_env, origin } =
self.pending_block_env_and_cfg()?; self.pending_block_env_and_cfg()?;
Ok((cfg, block_env, origin.state_block_id())) Ok(((cfg, block_env).into(), origin.state_block_id()))
} else { } else {
// Use cached values if there is no pending block // Use cached values if there is no pending block
let block_hash = RpcNodeCore::provider(self) let block_hash = RpcNodeCore::provider(self)
@ -233,11 +233,11 @@ pub trait LoadState:
let header = let header =
self.cache().get_header(block_hash).await.map_err(Self::Error::from_eth_err)?; self.cache().get_header(block_hash).await.map_err(Self::Error::from_eth_err)?;
let evm_config = self.evm_config().clone(); let evm_config = self.evm_config().clone();
let (cfg, block_env) = self let evm_env = self
.provider() .provider()
.env_with_header(&header, evm_config) .env_with_header(&header, evm_config)
.map_err(Self::Error::from_eth_err)?; .map_err(Self::Error::from_eth_err)?;
Ok((cfg, block_env, block_hash.into())) Ok((evm_env, block_hash.into()))
} }
} }
} }
@ -248,18 +248,19 @@ pub trait LoadState:
fn evm_env_for_raw_block( fn evm_env_for_raw_block(
&self, &self,
header: &ProviderHeader<Self::Provider>, header: &ProviderHeader<Self::Provider>,
) -> impl Future<Output = Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error>> + Send ) -> impl Future<Output = Result<EvmEnv, Self::Error>> + Send
where where
Self: LoadPendingBlock + SpawnBlocking, Self: LoadPendingBlock + SpawnBlocking,
{ {
async move { async move {
// get the parent config first // get the parent config first
let (cfg, mut block_env, _) = self.evm_env_at(header.parent_hash().into()).await?; let (evm_env, _) = self.evm_env_at(header.parent_hash().into()).await?;
let EvmEnv { cfg_env_with_handler_cfg, mut block_env } = evm_env;
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE; let after_merge = cfg_env_with_handler_cfg.handler_cfg.spec_id >= SpecId::MERGE;
self.evm_config().fill_block_env(&mut block_env, header, after_merge); self.evm_config().fill_block_env(&mut block_env, header, after_merge);
Ok((cfg, block_env)) Ok((cfg_env_with_handler_cfg, block_env).into())
} }
} }

View File

@ -8,7 +8,7 @@ use alloy_primitives::B256;
use alloy_rpc_types_eth::{BlockId, TransactionInfo}; use alloy_rpc_types_eth::{BlockId, TransactionInfo};
use futures::Future; use futures::Future;
use reth_chainspec::ChainSpecProvider; use reth_chainspec::ChainSpecProvider;
use reth_evm::{system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv}; use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::SealedBlockWithSenders; use reth_primitives::SealedBlockWithSenders;
use reth_primitives_traits::{BlockBody, SignedTransaction}; use reth_primitives_traits::{BlockBody, SignedTransaction};
use reth_provider::{BlockReader, ProviderBlock, ProviderHeader, ProviderTx}; use reth_provider::{BlockReader, ProviderBlock, ProviderHeader, ProviderTx};
@ -195,7 +195,8 @@ pub trait Trace:
}; };
let (tx, tx_info) = transaction.split(); let (tx, tx_info) = transaction.split();
let (cfg, block_env, _) = self.evm_env_at(block.hash().into()).await?; let (evm_env, _) = self.evm_env_at(block.hash().into()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
// we need to get the state of the parent block because we're essentially replaying the // we need to get the state of the parent block because we're essentially replaying the
// block the transaction is included in // block the transaction is included in
@ -206,19 +207,24 @@ pub trait Trace:
let mut db = CacheDB::new(StateProviderDatabase::new(state)); let mut db = CacheDB::new(StateProviderDatabase::new(state));
let block_txs = block.transactions_with_sender(); let block_txs = block.transactions_with_sender();
this.apply_pre_execution_changes(&block, &mut db, &cfg, &block_env)?; this.apply_pre_execution_changes(
&block,
&mut db,
&cfg_env_with_handler_cfg,
&block_env,
)?;
// replay all transactions prior to the targeted transaction // replay all transactions prior to the targeted transaction
this.replay_transactions_until( this.replay_transactions_until(
&mut db, &mut db,
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
block_txs, block_txs,
*tx.tx_hash(), *tx.tx_hash(),
)?; )?;
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()), RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()),
); );
@ -308,8 +314,9 @@ pub trait Trace:
self.block_with_senders(block_id).await self.block_with_senders(block_id).await
}; };
let ((cfg, block_env, _), block) = let ((evm_env, _), block) = futures::try_join!(self.evm_env_at(block_id), block)?;
futures::try_join!(self.evm_env_at(block_id), block)?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let Some(block) = block else { return Ok(None) }; let Some(block) = block else { return Ok(None) };
@ -333,7 +340,12 @@ pub trait Trace:
let mut db = let mut db =
CacheDB::new(StateProviderDatabase::new(StateProviderTraitObjWrapper(&state))); CacheDB::new(StateProviderDatabase::new(StateProviderTraitObjWrapper(&state)));
this.apply_pre_execution_changes(&block, &mut db, &cfg, &block_env)?; this.apply_pre_execution_changes(
&block,
&mut db,
&cfg_env_with_handler_cfg,
&block_env,
)?;
// prepare transactions, we do everything upfront to reduce time spent with open // prepare transactions, we do everything upfront to reduce time spent with open
// state // state
@ -362,8 +374,11 @@ pub trait Trace:
.peekable(); .peekable();
while let Some((tx_info, tx)) = transactions.next() { while let Some((tx_info, tx)) = transactions.next() {
let env = let env = EnvWithHandlerCfg::new_with_cfg_env(
EnvWithHandlerCfg::new_with_cfg_env(cfg.clone(), block_env.clone(), tx); cfg_env_with_handler_cfg.clone(),
block_env.clone(),
tx,
);
let mut inspector = inspector_setup(); let mut inspector = inspector_setup();
let (res, _) = let (res, _) =

View File

@ -16,6 +16,7 @@ use async_trait::async_trait;
use jsonrpsee::core::RpcResult; use jsonrpsee::core::RpcResult;
use reth_chainspec::EthereumHardforks; use reth_chainspec::EthereumHardforks;
use reth_evm::{ use reth_evm::{
env::EvmEnv,
execute::{BlockExecutorProvider, Executor}, execute::{BlockExecutorProvider, Executor},
ConfigureEvmEnv, ConfigureEvmEnv,
}; };
@ -161,7 +162,8 @@ where
.map_err(BlockError::RlpDecodeRawBlock) .map_err(BlockError::RlpDecodeRawBlock)
.map_err(Eth::Error::from_eth_err)?; .map_err(Eth::Error::from_eth_err)?;
let (cfg, block_env) = self.eth_api().evm_env_for_raw_block(block.header()).await?; let evm_env = self.eth_api().evm_env_for_raw_block(block.header()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
// Depending on EIP-2 we need to recover the transactions differently // Depending on EIP-2 we need to recover the transactions differently
let senders = let senders =
@ -191,7 +193,7 @@ where
self.trace_block( self.trace_block(
Arc::new(block.with_senders_unchecked(senders).seal_slow()), Arc::new(block.with_senders_unchecked(senders).seal_slow()),
cfg, cfg_env_with_handler_cfg,
block_env, block_env,
opts, opts,
) )
@ -210,14 +212,15 @@ where
.map_err(Eth::Error::from_eth_err)? .map_err(Eth::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(block_id))?; .ok_or(EthApiError::HeaderNotFound(block_id))?;
let ((cfg, block_env, _), block) = futures::try_join!( let ((evm_env, _), block) = futures::try_join!(
self.eth_api().evm_env_at(block_hash.into()), self.eth_api().evm_env_at(block_hash.into()),
self.eth_api().block_with_senders(block_hash.into()), self.eth_api().block_with_senders(block_hash.into()),
)?; )?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let block = block.ok_or(EthApiError::HeaderNotFound(block_id))?; let block = block.ok_or(EthApiError::HeaderNotFound(block_id))?;
self.trace_block(block, cfg, block_env, opts).await self.trace_block(block, cfg_env_with_handler_cfg, block_env, opts).await
} }
/// Trace the transaction according to the provided options. /// Trace the transaction according to the provided options.
@ -232,7 +235,8 @@ where
None => return Err(EthApiError::TransactionNotFound.into()), None => return Err(EthApiError::TransactionNotFound.into()),
Some(res) => res, Some(res) => res,
}; };
let (cfg, block_env, _) = self.eth_api().evm_env_at(block.hash().into()).await?; let (evm_env, _) = self.eth_api().evm_env_at(block.hash().into()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
// we need to get the state of the parent block because we're essentially replaying the // we need to get the state of the parent block because we're essentially replaying the
// block the transaction is included in // block the transaction is included in
@ -249,12 +253,17 @@ where
let mut db = CacheDB::new(StateProviderDatabase::new(state)); let mut db = CacheDB::new(StateProviderDatabase::new(state));
this.eth_api().apply_pre_execution_changes(&block, &mut db, &cfg, &block_env)?; this.eth_api().apply_pre_execution_changes(
&block,
&mut db,
&cfg_env_with_handler_cfg,
&block_env,
)?;
// replay all transactions prior to the targeted transaction // replay all transactions prior to the targeted transaction
let index = this.eth_api().replay_transactions_until( let index = this.eth_api().replay_transactions_until(
&mut db, &mut db,
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
block_txs, block_txs,
*tx.tx_hash(), *tx.tx_hash(),
@ -262,11 +271,11 @@ where
let env = EnvWithHandlerCfg { let env = EnvWithHandlerCfg {
env: Env::boxed( env: Env::boxed(
cfg.cfg_env.clone(), cfg_env_with_handler_cfg.cfg_env.clone(),
block_env, block_env,
this.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()), this.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()),
), ),
handler_cfg: cfg.handler_cfg, handler_cfg: cfg_env_with_handler_cfg.handler_cfg,
}; };
this.trace_transaction( this.trace_transaction(
@ -440,7 +449,7 @@ where
GethDebugTracerType::JsTracer(code) => { GethDebugTracerType::JsTracer(code) => {
let config = tracer_config.into_json(); let config = tracer_config.into_json();
let (_, _, at) = self.eth_api().evm_env_at(at).await?; let (_, at) = self.eth_api().evm_env_at(at).await?;
let res = self let res = self
.eth_api() .eth_api()
@ -502,10 +511,11 @@ where
let transaction_index = transaction_index.unwrap_or_default(); let transaction_index = transaction_index.unwrap_or_default();
let target_block = block_number.unwrap_or_default(); let target_block = block_number.unwrap_or_default();
let ((cfg, mut block_env, _), block) = futures::try_join!( let ((evm_env, _), block) = futures::try_join!(
self.eth_api().evm_env_at(target_block), self.eth_api().evm_env_at(target_block),
self.eth_api().block_with_senders(target_block), self.eth_api().block_with_senders(target_block),
)?; )?;
let EvmEnv { cfg_env_with_handler_cfg, mut block_env } = evm_env;
let opts = opts.unwrap_or_default(); let opts = opts.unwrap_or_default();
let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?; let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?;
@ -543,11 +553,11 @@ where
for (signer, tx) in transactions { for (signer, tx) in transactions {
let env = EnvWithHandlerCfg { let env = EnvWithHandlerCfg {
env: Env::boxed( env: Env::boxed(
cfg.cfg_env.clone(), cfg_env_with_handler_cfg.cfg_env.clone(),
block_env.clone(), block_env.clone(),
this.eth_api().evm_config().tx_env(tx, *signer), this.eth_api().evm_config().tx_env(tx, *signer),
), ),
handler_cfg: cfg.handler_cfg, handler_cfg: cfg_env_with_handler_cfg.handler_cfg,
}; };
let (res, _) = this.eth_api().transact(&mut db, env)?; let (res, _) = this.eth_api().transact(&mut db, env)?;
db.commit(res.state); db.commit(res.state);
@ -570,7 +580,7 @@ where
let overrides = EvmOverrides::new(state_overrides, block_overrides.clone()); let overrides = EvmOverrides::new(state_overrides, block_overrides.clone());
let env = this.eth_api().prepare_call_env( let env = this.eth_api().prepare_call_env(
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
tx, tx,
&mut db, &mut db,

View File

@ -5,7 +5,7 @@ use alloy_primitives::{Keccak256, U256};
use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult}; use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult};
use jsonrpsee::core::RpcResult; use jsonrpsee::core::RpcResult;
use reth_chainspec::EthChainSpec; use reth_chainspec::EthChainSpec;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::PooledTransaction; use reth_primitives::PooledTransaction;
use reth_primitives_traits::SignedTransaction; use reth_primitives_traits::SignedTransaction;
use reth_provider::{ChainSpecProvider, HeaderProvider}; use reth_provider::{ChainSpecProvider, HeaderProvider};
@ -109,7 +109,8 @@ where
let block_id: alloy_rpc_types_eth::BlockId = state_block_number.into(); let block_id: alloy_rpc_types_eth::BlockId = state_block_number.into();
// Note: the block number is considered the `parent` block: <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2104> // Note: the block number is considered the `parent` block: <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2104>
let (cfg, mut block_env, at) = self.eth_api().evm_env_at(block_id).await?; let (evm_env, at) = self.eth_api().evm_env_at(block_id).await?;
let EvmEnv { cfg_env_with_handler_cfg, mut block_env } = evm_env;
if let Some(coinbase) = coinbase { if let Some(coinbase) = coinbase {
block_env.coinbase = coinbase; block_env.coinbase = coinbase;
@ -140,7 +141,7 @@ where
if let Some(base_fee) = base_fee { if let Some(base_fee) = base_fee {
block_env.basefee = U256::from(base_fee); block_env.basefee = U256::from(base_fee);
} else if cfg.handler_cfg.spec_id.is_enabled_in(SpecId::LONDON) { } else if cfg_env_with_handler_cfg.handler_cfg.spec_id.is_enabled_in(SpecId::LONDON) {
let parent_block = block_env.number.saturating_to::<u64>(); let parent_block = block_env.number.saturating_to::<u64>();
// here we need to fetch the _next_ block's basefee based on the parent block <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2130> // here we need to fetch the _next_ block's basefee based on the parent block <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2130>
let parent = RpcNodeCore::provider(self.eth_api()) let parent = RpcNodeCore::provider(self.eth_api())
@ -166,7 +167,11 @@ where
.spawn_with_state_at_block(at, move |state| { .spawn_with_state_at_block(at, move |state| {
let coinbase = block_env.coinbase; let coinbase = block_env.coinbase;
let basefee = Some(block_env.basefee.to::<u64>()); let basefee = Some(block_env.basefee.to::<u64>());
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, TxEnv::default()); let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg,
block_env,
TxEnv::default(),
);
let db = CacheDB::new(StateProviderDatabase::new(state)); let db = CacheDB::new(StateProviderDatabase::new(state));
let initial_coinbase = db let initial_coinbase = db

View File

@ -10,7 +10,7 @@ use alloy_rpc_types_mev::{
}; };
use jsonrpsee::core::RpcResult; use jsonrpsee::core::RpcResult;
use reth_chainspec::EthChainSpec; use reth_chainspec::EthChainSpec;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv};
use reth_provider::{ChainSpecProvider, HeaderProvider, ProviderTx}; use reth_provider::{ChainSpecProvider, HeaderProvider, ProviderTx};
use reth_revm::database::StateProviderDatabase; use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::MevSimApiServer; use reth_rpc_api::MevSimApiServer;
@ -245,7 +245,8 @@ where
let flattened_bundle = self.parse_and_flatten_bundle(&request)?; let flattened_bundle = self.parse_and_flatten_bundle(&request)?;
let block_id = parent_block.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending)); let block_id = parent_block.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending));
let (cfg, mut block_env, current_block) = self.eth_api().evm_env_at(block_id).await?; let (evm_env, current_block) = self.eth_api().evm_env_at(block_id).await?;
let EvmEnv { cfg_env_with_handler_cfg, mut block_env } = evm_env;
let parent_header = RpcNodeCore::provider(&self.inner.eth_api) let parent_header = RpcNodeCore::provider(&self.inner.eth_api)
.header_by_number(block_env.number.saturating_to::<u64>()) .header_by_number(block_env.number.saturating_to::<u64>())
@ -273,7 +274,7 @@ where
if let Some(base_fee) = base_fee { if let Some(base_fee) = base_fee {
block_env.basefee = U256::from(base_fee); block_env.basefee = U256::from(base_fee);
} else if cfg.handler_cfg.spec_id.is_enabled_in(SpecId::LONDON) { } else if cfg_env_with_handler_cfg.handler_cfg.spec_id.is_enabled_in(SpecId::LONDON) {
if let Some(base_fee) = parent_header.next_block_base_fee( if let Some(base_fee) = parent_header.next_block_base_fee(
RpcNodeCore::provider(&self.inner.eth_api) RpcNodeCore::provider(&self.inner.eth_api)
.chain_spec() .chain_spec()
@ -293,7 +294,11 @@ where
let current_block_number = current_block.as_u64().unwrap(); let current_block_number = current_block.as_u64().unwrap();
let coinbase = block_env.coinbase; let coinbase = block_env.coinbase;
let basefee = block_env.basefee; let basefee = block_env.basefee;
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, TxEnv::default()); let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg,
block_env,
TxEnv::default(),
);
let db = CacheDB::new(StateProviderDatabase::new(state)); let db = CacheDB::new(StateProviderDatabase::new(state));
let initial_coinbase_balance = DatabaseRef::basic_ref(&db, coinbase) let initial_coinbase_balance = DatabaseRef::basic_ref(&db, coinbase)

View File

@ -18,7 +18,7 @@ use reth_chainspec::EthereumHardforks;
use reth_consensus_common::calc::{ use reth_consensus_common::calc::{
base_block_reward, base_block_reward_pre_merge, block_reward, ommer_reward, base_block_reward, base_block_reward_pre_merge, block_reward, ommer_reward,
}; };
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_primitives_traits::{BlockBody, BlockHeader}; use reth_primitives_traits::{BlockBody, BlockHeader};
use reth_provider::{BlockNumReader, BlockReader, ChainSpecProvider, HeaderProvider}; use reth_provider::{BlockNumReader, BlockReader, ChainSpecProvider, HeaderProvider};
use reth_revm::database::StateProviderDatabase; use reth_revm::database::StateProviderDatabase;
@ -117,11 +117,12 @@ where
let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx)? let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx)?
.map_transaction(<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus); .map_transaction(<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus);
let (cfg, block, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?; let (evm_env, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg, cfg_env_with_handler_cfg,
block, block_env,
self.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()), self.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()),
); );
@ -147,7 +148,8 @@ where
block_id: Option<BlockId>, block_id: Option<BlockId>,
) -> Result<Vec<TraceResults>, Eth::Error> { ) -> Result<Vec<TraceResults>, Eth::Error> {
let at = block_id.unwrap_or(BlockId::pending()); let at = block_id.unwrap_or(BlockId::pending());
let (cfg, block_env, at) = self.eth_api().evm_env_at(at).await?; let (evm_env, at) = self.eth_api().evm_env_at(at).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let this = self.clone(); let this = self.clone();
// execute all transactions on top of each other and record the traces // execute all transactions on top of each other and record the traces
@ -160,7 +162,7 @@ where
while let Some((call, trace_types)) = calls.next() { while let Some((call, trace_types)) = calls.next() {
let env = this.eth_api().prepare_call_env( let env = this.eth_api().prepare_call_env(
cfg.clone(), cfg_env_with_handler_cfg.clone(),
block_env.clone(), block_env.clone(),
call, call,
&mut db, &mut db,

View File

@ -23,7 +23,7 @@ use reth_chain_state::{
use reth_chainspec::{ChainInfo, EthereumHardforks}; use reth_chainspec::{ChainInfo, EthereumHardforks};
use reth_db::{models::BlockNumberAddress, transaction::DbTx, Database}; use reth_db::{models::BlockNumberAddress, transaction::DbTx, Database};
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_node_types::{BlockTy, HeaderTy, NodeTypesWithDB, ReceiptTy, TxTy}; use reth_node_types::{BlockTy, HeaderTy, NodeTypesWithDB, ReceiptTy, TxTy};
use reth_primitives::{ use reth_primitives::{
@ -502,7 +502,7 @@ impl<N: ProviderNodeTypes> EvmEnvProvider<HeaderTy<N>> for BlockchainProvider2<N
&self, &self,
header: &HeaderTy<N>, header: &HeaderTy<N>,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>, EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>,
{ {

View File

@ -17,7 +17,7 @@ use reth_chain_state::{BlockState, CanonicalInMemoryState, MemoryOverlayStatePro
use reth_chainspec::{ChainInfo, EthereumHardforks}; use reth_chainspec::{ChainInfo, EthereumHardforks};
use reth_db::models::BlockNumberAddress; use reth_db::models::BlockNumberAddress;
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_execution_types::{BundleStateInit, ExecutionOutcome, RevertsInit}; use reth_execution_types::{BundleStateInit, ExecutionOutcome, RevertsInit};
use reth_node_types::{BlockTy, HeaderTy, ReceiptTy, TxTy}; use reth_node_types::{BlockTy, HeaderTy, ReceiptTy, TxTy};
use reth_primitives::{ use reth_primitives::{
@ -32,10 +32,7 @@ use reth_storage_api::{
StateProvider, StorageChangeSetReader, StateProvider, StorageChangeSetReader,
}; };
use reth_storage_errors::provider::ProviderResult; use reth_storage_errors::provider::ProviderResult;
use revm::{ use revm::db::states::PlainStorageRevert;
db::states::PlainStorageRevert,
primitives::{BlockEnv, CfgEnvWithHandlerCfg},
};
use std::{ use std::{
collections::{hash_map, HashMap}, collections::{hash_map, HashMap},
ops::{Add, Bound, RangeBounds, RangeInclusive, Sub}, ops::{Add, Bound, RangeBounds, RangeInclusive, Sub},
@ -1240,7 +1237,7 @@ impl<N: ProviderNodeTypes> EvmEnvProvider<HeaderTy<N>> for ConsistentProvider<N>
&self, &self,
header: &HeaderTy<N>, header: &HeaderTy<N>,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>, EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>,
{ {

View File

@ -17,7 +17,7 @@ use reth_chainspec::{ChainInfo, EthereumHardforks};
use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv}; use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv};
use reth_db_api::{database::Database, models::StoredBlockBodyIndices}; use reth_db_api::{database::Database, models::StoredBlockBodyIndices};
use reth_errors::{RethError, RethResult}; use reth_errors::{RethError, RethResult};
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_node_types::{BlockTy, HeaderTy, NodeTypesWithDB, ReceiptTy, TxTy}; use reth_node_types::{BlockTy, HeaderTy, NodeTypesWithDB, ReceiptTy, TxTy};
use reth_primitives::{ use reth_primitives::{
BlockWithSenders, SealedBlockFor, SealedBlockWithSenders, SealedHeader, StaticFileSegment, BlockWithSenders, SealedBlockFor, SealedBlockWithSenders, SealedHeader, StaticFileSegment,
@ -32,10 +32,7 @@ use reth_storage_api::{
use reth_storage_errors::provider::ProviderResult; use reth_storage_errors::provider::ProviderResult;
use reth_trie::HashedPostState; use reth_trie::HashedPostState;
use reth_trie_db::StateCommitment; use reth_trie_db::StateCommitment;
use revm::{ use revm::db::BundleState;
db::BundleState,
primitives::{BlockEnv, CfgEnvWithHandlerCfg},
};
use std::{ use std::{
ops::{RangeBounds, RangeInclusive}, ops::{RangeBounds, RangeInclusive},
path::Path, path::Path,
@ -599,7 +596,7 @@ impl<N: ProviderNodeTypes> EvmEnvProvider<HeaderTy<N>> for ProviderFactory<N> {
&self, &self,
header: &HeaderTy<N>, header: &HeaderTy<N>,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>, EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>,
{ {

View File

@ -47,7 +47,7 @@ use reth_db_api::{
transaction::{DbTx, DbTxMut}, transaction::{DbTx, DbTxMut},
DatabaseError, DatabaseError,
}; };
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_execution_types::{Chain, ExecutionOutcome}; use reth_execution_types::{Chain, ExecutionOutcome};
use reth_network_p2p::headers::downloader::SyncTarget; use reth_network_p2p::headers::downloader::SyncTarget;
use reth_node_types::{BlockTy, BodyTy, HeaderTy, NodeTypes, ReceiptTy, TxTy}; use reth_node_types::{BlockTy, BodyTy, HeaderTy, NodeTypes, ReceiptTy, TxTy};
@ -70,9 +70,8 @@ use reth_trie::{
HashedPostStateSorted, Nibbles, StateRoot, StoredNibbles, HashedPostStateSorted, Nibbles, StateRoot, StoredNibbles,
}; };
use reth_trie_db::{DatabaseStateRoot, DatabaseStorageTrieCursor}; use reth_trie_db::{DatabaseStateRoot, DatabaseStorageTrieCursor};
use revm::{ use revm::db::states::{
db::states::{PlainStateReverts, PlainStorageChangeset, PlainStorageRevert, StateChangeset}, PlainStateReverts, PlainStorageChangeset, PlainStorageRevert, StateChangeset,
primitives::{BlockEnv, CfgEnvWithHandlerCfg},
}; };
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
@ -1648,7 +1647,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> EvmEnvProvider<HeaderTy<N>>
&self, &self,
header: &HeaderTy<N>, header: &HeaderTy<N>,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>, EvmConfig: ConfigureEvmEnv<Header = HeaderTy<N>>,
{ {

View File

@ -26,7 +26,7 @@ use reth_chain_state::{ChainInfoTracker, ForkChoiceNotifications, ForkChoiceSubs
use reth_chainspec::{ChainInfo, EthereumHardforks}; use reth_chainspec::{ChainInfo, EthereumHardforks};
use reth_db::table::Value; use reth_db::table::Value;
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_node_types::{ use reth_node_types::{
BlockTy, FullNodePrimitives, HeaderTy, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine, BlockTy, FullNodePrimitives, HeaderTy, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
ReceiptTy, TxTy, ReceiptTy, TxTy,
@ -39,7 +39,6 @@ use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_stages_types::{StageCheckpoint, StageId}; use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_api::{BlockBodyIndicesProvider, CanonChainTracker, OmmersProvider}; use reth_storage_api::{BlockBodyIndicesProvider, CanonChainTracker, OmmersProvider};
use reth_storage_errors::provider::ProviderResult; use reth_storage_errors::provider::ProviderResult;
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
ops::{RangeBounds, RangeInclusive}, ops::{RangeBounds, RangeInclusive},
@ -607,7 +606,7 @@ impl<N: TreeNodeTypes> EvmEnvProvider for BlockchainProvider<N> {
&self, &self,
header: &Header, header: &Header,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = Header>, EvmConfig: ConfigureEvmEnv<Header = Header>,
{ {

View File

@ -19,7 +19,7 @@ use parking_lot::Mutex;
use reth_chainspec::{ChainInfo, ChainSpec}; use reth_chainspec::{ChainInfo, ChainSpec};
use reth_db::mock::{DatabaseMock, TxMock}; use reth_db::mock::{DatabaseMock, TxMock};
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
use reth_evm::ConfigureEvmEnv; use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_execution_types::ExecutionOutcome; use reth_execution_types::ExecutionOutcome;
use reth_node_types::NodeTypes; use reth_node_types::NodeTypes;
use reth_primitives::{ use reth_primitives::{
@ -38,7 +38,6 @@ use reth_trie::{
MultiProofTargets, StorageMultiProof, StorageProof, TrieInput, MultiProofTargets, StorageMultiProof, StorageProof, TrieInput,
}; };
use reth_trie_db::MerklePatriciaTrie; use reth_trie_db::MerklePatriciaTrie;
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
ops::{RangeBounds, RangeInclusive}, ops::{RangeBounds, RangeInclusive},
@ -713,7 +712,7 @@ impl EvmEnvProvider for MockEthProvider {
&self, &self,
header: &Header, header: &Header,
evm_config: EvmConfig, evm_config: EvmConfig,
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)> ) -> ProviderResult<EvmEnv>
where where
EvmConfig: ConfigureEvmEnv<Header = Header>, EvmConfig: ConfigureEvmEnv<Header = Header>,
{ {

View File

@ -20,9 +20,12 @@ use reth::{
}, },
}; };
use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_evm::execute::{ use reth_evm::{
BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput, env::EvmEnv,
InternalBlockExecutionError, execute::{
BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput,
InternalBlockExecutionError,
},
}; };
use reth_evm_ethereum::EthEvmConfig; use reth_evm_ethereum::EthEvmConfig;
use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode}; use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode};
@ -131,8 +134,9 @@ where
header: &alloy_consensus::Header, header: &alloy_consensus::Header,
total_difficulty: U256, total_difficulty: U256,
) -> EnvWithHandlerCfg { ) -> EnvWithHandlerCfg {
let (cfg, block_env) = self.evm_config.cfg_and_block_env(header, total_difficulty); let evm_env = self.evm_config.cfg_and_block_env(header, total_difficulty);
EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default()) 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())
} }
} }

View File

@ -14,6 +14,7 @@ reth-node-core.workspace = true
reth-primitives.workspace = true reth-primitives.workspace = true
reth-node-ethereum = { workspace = true, features = ["test-utils"] } reth-node-ethereum = { workspace = true, features = ["test-utils"] }
reth-tracing.workspace = true reth-tracing.workspace = true
reth-evm.workspace = true
alloy-genesis.workspace = true alloy-genesis.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-consensus.workspace = true alloy-consensus.workspace = true

View File

@ -15,7 +15,7 @@ use reth::{
handler::register::EvmHandler, handler::register::EvmHandler,
inspector_handle_register, inspector_handle_register,
precompile::{Precompile, PrecompileOutput, PrecompileSpecId}, precompile::{Precompile, PrecompileOutput, PrecompileSpecId},
primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, PrecompileResult, TxEnv}, primitives::{CfgEnvWithHandlerCfg, Env, PrecompileResult, TxEnv},
ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector, ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector,
}, },
rpc::types::engine::PayloadAttributes, rpc::types::engine::PayloadAttributes,
@ -23,6 +23,7 @@ use reth::{
transaction_pool::{PoolTransaction, TransactionPool}, transaction_pool::{PoolTransaction, TransactionPool},
}; };
use reth_chainspec::{Chain, ChainSpec}; use reth_chainspec::{Chain, ChainSpec};
use reth_evm::env::EvmEnv;
use reth_evm_ethereum::EthEvmConfig; use reth_evm_ethereum::EthEvmConfig;
use reth_node_api::{ use reth_node_api::{
ConfigureEvm, ConfigureEvmEnv, FullNodeTypes, NextBlockEnvAttributes, NodeTypes, ConfigureEvm, ConfigureEvmEnv, FullNodeTypes, NextBlockEnvAttributes, NodeTypes,
@ -115,7 +116,7 @@ impl ConfigureEvmEnv for MyEvmConfig {
&self, &self,
parent: &Self::Header, parent: &Self::Header,
attributes: NextBlockEnvAttributes, attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { ) -> Result<EvmEnv, Self::Error> {
self.inner.next_cfg_and_block_env(parent, attributes) self.inner.next_cfg_and_block_env(parent, attributes)
} }
} }

View File

@ -13,6 +13,7 @@ reth-node-core.workspace = true
reth-primitives.workspace = true reth-primitives.workspace = true
reth-node-ethereum = { workspace = true, features = ["test-utils"] } reth-node-ethereum = { workspace = true, features = ["test-utils"] }
reth-tracing.workspace = true reth-tracing.workspace = true
reth-evm.workspace = true
alloy-genesis.workspace = true alloy-genesis.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-consensus.workspace = true alloy-consensus.workspace = true

View File

@ -14,14 +14,14 @@ use reth::{
inspector_handle_register, inspector_handle_register,
precompile::{Precompile, PrecompileSpecId}, precompile::{Precompile, PrecompileSpecId},
primitives::{ primitives::{
BlockEnv, CfgEnvWithHandlerCfg, Env, PrecompileResult, SpecId, StatefulPrecompileMut, CfgEnvWithHandlerCfg, Env, PrecompileResult, SpecId, StatefulPrecompileMut, TxEnv,
TxEnv,
}, },
ContextPrecompile, ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector, ContextPrecompile, ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector,
}, },
tasks::TaskManager, tasks::TaskManager,
}; };
use reth_chainspec::{Chain, ChainSpec}; use reth_chainspec::{Chain, ChainSpec};
use reth_evm::env::EvmEnv;
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, FullNodeTypes, NodeTypes}; use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, FullNodeTypes, NodeTypes};
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_node_ethereum::{ use reth_node_ethereum::{
@ -178,7 +178,7 @@ impl ConfigureEvmEnv for MyEvmConfig {
&self, &self,
parent: &Self::Header, parent: &Self::Header,
attributes: NextBlockEnvAttributes, attributes: NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { ) -> Result<EvmEnv, Self::Error> {
self.inner.next_cfg_and_block_env(parent, attributes) self.inner.next_cfg_and_block_env(parent, attributes)
} }
} }