feat: rm txmeta associated type (#8138)

This commit is contained in:
Matthias Seitz
2024-05-07 17:28:53 +02:00
committed by GitHub
parent bcb0bff382
commit 05e434eae3
7 changed files with 29 additions and 70 deletions

View File

@ -10,7 +10,7 @@ use reth_evm::{
BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput,
BlockExecutorProvider, Executor, BlockExecutorProvider, Executor,
}, },
ConfigureEvm, ConfigureEvmEnv, ConfigureEvm,
}; };
use reth_interfaces::{ use reth_interfaces::{
executor::{BlockExecutionError, BlockValidationError}, executor::{BlockExecutionError, BlockValidationError},
@ -62,7 +62,6 @@ impl<EvmConfig> EthExecutorProvider<EvmConfig> {
impl<EvmConfig> EthExecutorProvider<EvmConfig> impl<EvmConfig> EthExecutorProvider<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{ {
fn eth_executor<DB>(&self, db: DB) -> EthBlockExecutor<EvmConfig, DB> fn eth_executor<DB>(&self, db: DB) -> EthBlockExecutor<EvmConfig, DB>
where where
@ -79,7 +78,6 @@ where
impl<EvmConfig> BlockExecutorProvider for EthExecutorProvider<EvmConfig> impl<EvmConfig> BlockExecutorProvider for EthExecutorProvider<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{ {
type Executor<DB: Database<Error = ProviderError>> = EthBlockExecutor<EvmConfig, DB>; type Executor<DB: Database<Error = ProviderError>> = EthBlockExecutor<EvmConfig, DB>;
@ -117,7 +115,6 @@ struct EthEvmExecutor<EvmConfig> {
impl<EvmConfig> EthEvmExecutor<EvmConfig> impl<EvmConfig> EthEvmExecutor<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{ {
/// Executes the transactions in the block and returns the receipts. /// Executes the transactions in the block and returns the receipts.
/// ///
@ -158,7 +155,7 @@ where
.into()) .into())
} }
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender, ()); EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
// Execute transaction. // Execute transaction.
let ResultAndState { result, state } = evm.transact().map_err(move |err| { let ResultAndState { result, state } = evm.transact().map_err(move |err| {
@ -238,8 +235,6 @@ impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> {
impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
// TODO(mattsse): get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
/// Configures a new evm configuration and block environment for the given block. /// Configures a new evm configuration and block environment for the given block.
@ -353,7 +348,6 @@ where
impl<EvmConfig, DB> Executor<DB> for EthBlockExecutor<EvmConfig, DB> impl<EvmConfig, DB> Executor<DB> for EthBlockExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
@ -403,8 +397,6 @@ impl<EvmConfig, DB> EthBatchExecutor<EvmConfig, DB> {
impl<EvmConfig, DB> BatchExecutor<DB> for EthBatchExecutor<EvmConfig, DB> impl<EvmConfig, DB> BatchExecutor<DB> for EthBatchExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
// TODO(mattsse): get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;

View File

@ -12,7 +12,7 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{ use reth_primitives::{
revm::{config::revm_spec, env::fill_tx_env}, revm::{config::revm_spec, env::fill_tx_env},
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv}, revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
Address, ChainSpec, Head, Header, Transaction, U256, Address, ChainSpec, Head, Header, TransactionSigned, U256,
}; };
use reth_revm::{Database, EvmBuilder}; use reth_revm::{Database, EvmBuilder};
pub mod execute; pub mod execute;
@ -27,12 +27,7 @@ pub mod dao_fork;
pub struct EthEvmConfig; pub struct EthEvmConfig;
impl ConfigureEvmEnv for EthEvmConfig { impl ConfigureEvmEnv for EthEvmConfig {
type TxMeta = (); fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, _meta: ())
where
T: AsRef<Transaction>,
{
fill_tx_env(tx_env, transaction, sender) fill_tx_env(tx_env, transaction, sender)
} }

View File

@ -8,7 +8,9 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use reth_primitives::{revm::env::fill_block_env, Address, ChainSpec, Header, Transaction, U256}; use reth_primitives::{
revm::env::fill_block_env, Address, ChainSpec, Header, TransactionSigned, U256,
};
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector}; use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv}; use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv};
@ -92,17 +94,8 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// This represents the set of methods used to configure the EVM's environment before block /// This represents the set of methods used to configure the EVM's environment before block
/// execution. /// execution.
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static { pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
/// The type of the transaction metadata that should be used to fill fields in the transaction /// Fill transaction environment from a [TransactionSigned] and the given sender address.
/// environment. fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address);
///
/// On ethereum mainnet, this is `()`, and on optimism these are the L1 fee fields and
/// additional L1 block info.
type TxMeta;
/// Fill transaction environment from a [Transaction] and the given sender address.
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta)
where
T: AsRef<Transaction>;
/// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header /// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header
fn fill_cfg_env( fn fill_cfg_env(

View File

@ -9,15 +9,15 @@ use reth_evm::{
BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput,
BlockExecutorProvider, Executor, BlockExecutorProvider, Executor,
}, },
ConfigureEvm, ConfigureEvmEnv, ConfigureEvm,
}; };
use reth_interfaces::{ use reth_interfaces::{
executor::{BlockExecutionError, BlockValidationError}, executor::{BlockExecutionError, BlockValidationError},
provider::ProviderError, provider::ProviderError,
}; };
use reth_primitives::{ use reth_primitives::{
BlockNumber, BlockWithSenders, Bytes, ChainSpec, GotExpected, Hardfork, Header, PruneModes, BlockNumber, BlockWithSenders, ChainSpec, GotExpected, Hardfork, Header, PruneModes, Receipt,
Receipt, Receipts, TxType, Withdrawals, U256, Receipts, TxType, Withdrawals, U256,
}; };
use reth_revm::{ use reth_revm::{
batch::{BlockBatchRecord, BlockExecutorStats}, batch::{BlockBatchRecord, BlockExecutorStats},
@ -56,7 +56,6 @@ impl<EvmConfig> OpExecutorProvider<EvmConfig> {
impl<EvmConfig> OpExecutorProvider<EvmConfig> impl<EvmConfig> OpExecutorProvider<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
{ {
fn op_executor<DB>(&self, db: DB) -> OpBlockExecutor<EvmConfig, DB> fn op_executor<DB>(&self, db: DB) -> OpBlockExecutor<EvmConfig, DB>
where where
@ -73,7 +72,6 @@ where
impl<EvmConfig> BlockExecutorProvider for OpExecutorProvider<EvmConfig> impl<EvmConfig> BlockExecutorProvider for OpExecutorProvider<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
{ {
type Executor<DB: Database<Error = ProviderError>> = OpBlockExecutor<EvmConfig, DB>; type Executor<DB: Database<Error = ProviderError>> = OpBlockExecutor<EvmConfig, DB>;
@ -110,7 +108,6 @@ struct OpEvmExecutor<EvmConfig> {
impl<EvmConfig> OpEvmExecutor<EvmConfig> impl<EvmConfig> OpEvmExecutor<EvmConfig>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
{ {
/// Executes the transactions in the block and returns the receipts. /// Executes the transactions in the block and returns the receipts.
/// ///
@ -182,9 +179,7 @@ where
.transpose() .transpose()
.map_err(|_| OptimismBlockExecutionError::AccountLoadFailed(*sender))?; .map_err(|_| OptimismBlockExecutionError::AccountLoadFailed(*sender))?;
let mut buf = Vec::with_capacity(transaction.length_without_header()); EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
transaction.encode_enveloped(&mut buf);
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender, buf.into());
// Execute transaction. // Execute transaction.
let ResultAndState { result, state } = evm.transact().map_err(move |err| { let ResultAndState { result, state } = evm.transact().map_err(move |err| {
@ -274,8 +269,6 @@ impl<EvmConfig, DB> OpBlockExecutor<EvmConfig, DB> {
impl<EvmConfig, DB> OpBlockExecutor<EvmConfig, DB> impl<EvmConfig, DB> OpBlockExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
// TODO(mattsse): get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
/// Configures a new evm configuration and block environment for the given block. /// Configures a new evm configuration and block environment for the given block.
@ -375,7 +368,6 @@ where
impl<EvmConfig, DB> Executor<DB> for OpBlockExecutor<EvmConfig, DB> impl<EvmConfig, DB> Executor<DB> for OpBlockExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
@ -428,8 +420,6 @@ impl<EvmConfig, DB> OpBatchExecutor<EvmConfig, DB> {
impl<EvmConfig, DB> BatchExecutor<DB> for OpBatchExecutor<EvmConfig, DB> impl<EvmConfig, DB> BatchExecutor<DB> for OpBatchExecutor<EvmConfig, DB>
where where
EvmConfig: ConfigureEvm, EvmConfig: ConfigureEvm,
// TODO: get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = Bytes>,
DB: Database<Error = ProviderError>, DB: Database<Error = ProviderError>,
{ {
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;

View File

@ -13,7 +13,7 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{ use reth_primitives::{
revm::{config::revm_spec, env::fill_op_tx_env}, revm::{config::revm_spec, env::fill_op_tx_env},
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv}, revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
Address, Bytes, ChainSpec, Head, Header, Transaction, U256, Address, ChainSpec, Head, Header, TransactionSigned, U256,
}; };
use reth_revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector}; use reth_revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
@ -32,13 +32,10 @@ pub use error::OptimismBlockExecutionError;
pub struct OptimismEvmConfig; pub struct OptimismEvmConfig;
impl ConfigureEvmEnv for OptimismEvmConfig { impl ConfigureEvmEnv for OptimismEvmConfig {
type TxMeta = Bytes; fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
let mut buf = Vec::with_capacity(transaction.length_without_header());
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Bytes) transaction.encode_enveloped(&mut buf);
where fill_op_tx_env(tx_env, transaction, sender, buf.into());
T: AsRef<Transaction>,
{
fill_op_tx_env(tx_env, transaction, sender, meta);
} }
fn fill_cfg_env( fn fill_cfg_env(

View File

@ -2,7 +2,7 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_interfaces::provider::ProviderResult; use reth_interfaces::provider::ProviderResult;
use reth_primitives::{ use reth_primitives::{
keccak256, revm::config::revm_spec, trie::AccountProof, Account, Address, BlockNumber, keccak256, revm::config::revm_spec, trie::AccountProof, Account, Address, BlockNumber,
Bytecode, Bytes, ChainSpec, Head, Header, StorageKey, Transaction, B256, U256, Bytecode, Bytes, ChainSpec, Head, Header, StorageKey, TransactionSigned, B256, U256,
}; };
#[cfg(not(feature = "optimism"))] #[cfg(not(feature = "optimism"))]
@ -114,20 +114,17 @@ impl StateProvider for StateProviderTest {
pub struct TestEvmConfig; pub struct TestEvmConfig;
impl ConfigureEvmEnv for TestEvmConfig { impl ConfigureEvmEnv for TestEvmConfig {
#[cfg(not(feature = "optimism"))]
type TxMeta = ();
#[cfg(feature = "optimism")]
type TxMeta = Bytes;
#[allow(unused_variables)] #[allow(unused_variables)]
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta) fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
where
T: AsRef<Transaction>,
{
#[cfg(not(feature = "optimism"))] #[cfg(not(feature = "optimism"))]
fill_tx_env(tx_env, transaction, sender); fill_tx_env(tx_env, transaction, sender);
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
fill_op_tx_env(tx_env, transaction, sender, meta); {
let mut buf = Vec::with_capacity(transaction.length_without_header());
transaction.encode_enveloped(&mut buf);
fill_op_tx_env(tx_env, transaction, sender, buf.into());
}
} }
fn fill_cfg_env( fn fill_cfg_env(

View File

@ -20,7 +20,7 @@ use reth::{
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, FullNodeTypes}; use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, FullNodeTypes};
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider, EthereumNode}; use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider, EthereumNode};
use reth_primitives::{Chain, ChainSpec, Genesis, Header, Transaction}; use reth_primitives::{Chain, ChainSpec, Genesis, Header, TransactionSigned};
use reth_tracing::{RethTracer, Tracer}; use reth_tracing::{RethTracer, Tracer};
use std::sync::Arc; use std::sync::Arc;
@ -61,13 +61,8 @@ impl MyEvmConfig {
} }
impl ConfigureEvmEnv for MyEvmConfig { impl ConfigureEvmEnv for MyEvmConfig {
type TxMeta = (); fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
EthEvmConfig::fill_tx_env(tx_env, transaction, sender)
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta)
where
T: AsRef<Transaction>,
{
EthEvmConfig::fill_tx_env(tx_env, transaction, sender, meta)
} }
fn fill_cfg_env( fn fill_cfg_env(