feat: generic TxEnv (#13957)

This commit is contained in:
Arsenii Kulikov
2025-01-24 14:48:44 +04:00
committed by GitHub
parent 1296bacb87
commit 006eea0c34
18 changed files with 271 additions and 244 deletions

View File

@ -19,7 +19,7 @@ use reth_evm::{
},
state_change::post_block_balance_increments,
system_calls::{OnStateHook, SystemCaller},
ConfigureEvmFor, Evm, TxEnvOverrides,
ConfigureEvmFor, Evm,
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::validate_block_post_execution;
@ -104,8 +104,6 @@ where
chain_spec: Arc<OpChainSpec>,
/// How to create an EVM.
evm_config: EvmConfig,
/// Optional overrides for the transactions environment.
tx_env_overrides: Option<Box<dyn TxEnvOverrides>>,
/// Current state for block execution.
state: State<DB>,
/// Utility to call system smart contracts.
@ -127,14 +125,7 @@ where
receipt_builder: Arc<dyn OpReceiptBuilder<N::SignedTx, Receipt = N::Receipt>>,
) -> Self {
let system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone());
Self {
state,
chain_spec,
evm_config,
system_caller,
tx_env_overrides: None,
receipt_builder,
}
Self { state, chain_spec, evm_config, system_caller, receipt_builder }
}
}
@ -152,10 +143,6 @@ where
type Primitives = N;
type Error = BlockExecutionError;
fn init(&mut self, tx_env_overrides: Box<dyn TxEnvOverrides>) {
self.tx_env_overrides = Some(tx_env_overrides);
}
fn apply_pre_execution_changes(
&mut self,
block: &RecoveredBlock<N::Block>,
@ -223,11 +210,7 @@ where
.transpose()
.map_err(|_| OpBlockExecutionError::AccountLoadFailed(*sender))?;
let mut tx_env = self.evm_config.tx_env(transaction, *sender);
if let Some(tx_env_overrides) = &mut self.tx_env_overrides {
tx_env_overrides.apply(&mut tx_env);
}
let tx_env = self.evm_config.tx_env(transaction, *sender);
// Execute transaction.
let result_and_state = evm.transact(tx_env).map_err(move |err| {

View File

@ -157,6 +157,7 @@ impl ConfigureEvmEnv for OpEvmConfig {
type Header = Header;
type Transaction = OpTransactionSigned;
type Error = EIP1559ParamError;
type TxEnv = TxEnv;
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &OpTransactionSigned, sender: Address) {
transaction.fill_tx_env(tx_env, sender);

View File

@ -9,7 +9,7 @@ use crate::{
use op_alloy_consensus::OpPooledTransaction;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_chainspec::{EthChainSpec, Hardforks};
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvmFor};
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvmEnv, ConfigureEvmFor};
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo};
use reth_node_api::{AddOnsContext, FullNodeComponents, NodeAddOns, PrimitivesTy, TxTy};
use reth_node_builder::{
@ -43,6 +43,7 @@ use reth_transaction_pool::{
TransactionValidationTaskExecutor,
};
use reth_trie_db::MerklePatriciaTrie;
use revm::primitives::TxEnv;
use std::sync::Arc;
/// Storage implementation for Optimism.
@ -190,6 +191,7 @@ where
Storage = OpStorage,
Engine = OpEngineTypes,
>,
Evm: ConfigureEvmEnv<TxEnv = TxEnv>,
>,
{
type Handle = RpcHandle<N, OpEthApi<N>>;
@ -239,6 +241,7 @@ where
Storage = OpStorage,
Engine = OpEngineTypes,
>,
Evm: ConfigureEvmEnv<TxEnv = TxEnv>,
>,
{
type EthApi = OpEthApi<N>;

View File

@ -28,7 +28,8 @@ where
impl<N> Call for OpEthApi<N>
where
Self: LoadState<Evm: ConfigureEvm<Header = ProviderHeader<Self::Provider>>> + SpawnBlocking,
Self: LoadState<Evm: ConfigureEvm<Header = ProviderHeader<Self::Provider>, TxEnv = TxEnv>>
+ SpawnBlocking,
Self::Error: From<OpEthApiError>,
N: OpNodeCore,
{