feat: add evm_for_block helper to simplify EVM setup (#13787)

This commit is contained in:
Arsenii Kulikov
2025-01-13 19:25:37 +04:00
committed by GitHub
parent ac25fd8c18
commit 749facc477
6 changed files with 103 additions and 103 deletions

View File

@ -9,23 +9,20 @@ use alloy_sol_types::SolCall;
#[cfg(feature = "optimism")]
use reth::revm::primitives::OptimismFields;
use reth::{
api::{ConfigureEvm, ConfigureEvmEnv, NodeTypesWithEngine},
api::{ConfigureEvm, NodeTypesWithEngine},
builder::{components::ExecutorBuilder, BuilderContext, FullNodeTypes},
cli::Cli,
providers::ProviderError,
revm::{
interpreter::Host,
primitives::{address, Address, Bytes, Env, EnvWithHandlerCfg, TransactTo, TxEnv, U256},
primitives::{address, Address, Bytes, Env, TransactTo, TxEnv, U256},
Database, DatabaseCommit, Evm, State,
},
};
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_evm::{
env::EvmEnv,
execute::{
BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput,
InternalBlockExecutionError,
},
use reth_evm::execute::{
BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput,
InternalBlockExecutionError,
};
use reth_evm_ethereum::EthEvmConfig;
use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode};
@ -120,22 +117,6 @@ where
state: State<DB>,
}
impl<DB> CustomExecutorStrategy<DB>
where
DB: Database<Error: Into<ProviderError> + Display>,
{
/// Configures a new evm configuration and block environment for the given block.
///
/// # Caution
///
/// This does not initialize the tx environment.
fn evm_env_for_block(&self, header: &alloy_consensus::Header) -> EnvWithHandlerCfg {
let evm_env = self.evm_config.cfg_and_block_env(header);
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())
}
}
impl<DB> BlockExecutionStrategy for CustomExecutorStrategy<DB>
where
DB: Database<Error: Into<ProviderError> + Display>,
@ -165,8 +146,7 @@ where
block: &BlockWithSenders,
_receipts: &[Receipt],
) -> Result<Requests, Self::Error> {
let env = self.evm_env_for_block(&block.header);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);
let mut evm = self.evm_config.evm_for_block(&mut self.state, &block.header);
if let Some(withdrawals) = block.body.withdrawals.as_ref() {
apply_withdrawals_contract_call(withdrawals, &mut evm)?;