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,
BlockExecutorProvider, Executor,
},
ConfigureEvm, ConfigureEvmEnv,
ConfigureEvm,
};
use reth_interfaces::{
executor::{BlockExecutionError, BlockValidationError},
@ -62,7 +62,6 @@ impl<EvmConfig> EthExecutorProvider<EvmConfig> {
impl<EvmConfig> EthExecutorProvider<EvmConfig>
where
EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{
fn eth_executor<DB>(&self, db: DB) -> EthBlockExecutor<EvmConfig, DB>
where
@ -79,7 +78,6 @@ where
impl<EvmConfig> BlockExecutorProvider for EthExecutorProvider<EvmConfig>
where
EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{
type Executor<DB: Database<Error = ProviderError>> = EthBlockExecutor<EvmConfig, DB>;
@ -117,7 +115,6 @@ struct EthEvmExecutor<EvmConfig> {
impl<EvmConfig> EthEvmExecutor<EvmConfig>
where
EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
{
/// Executes the transactions in the block and returns the receipts.
///
@ -158,7 +155,7 @@ where
.into())
}
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender, ());
EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
// Execute transaction.
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>
where
EvmConfig: ConfigureEvm,
// TODO(mattsse): get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>,
{
/// 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>
where
EvmConfig: ConfigureEvm,
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>,
{
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>
where
EvmConfig: ConfigureEvm,
// TODO(mattsse): get rid of this
EvmConfig: ConfigureEvmEnv<TxMeta = ()>,
DB: Database<Error = ProviderError>,
{
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;

View File

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

View File

@ -8,7 +8,9 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![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_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
/// execution.
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
/// The type of the transaction metadata that should be used to fill fields in the transaction
/// environment.
///
/// 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 transaction environment from a [TransactionSigned] and the given sender address.
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address);
/// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header
fn fill_cfg_env(

View File

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

View File

@ -13,7 +13,7 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{
revm::{config::revm_spec, env::fill_op_tx_env},
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};
@ -32,13 +32,10 @@ pub use error::OptimismBlockExecutionError;
pub struct OptimismEvmConfig;
impl ConfigureEvmEnv for OptimismEvmConfig {
type TxMeta = Bytes;
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Bytes)
where
T: AsRef<Transaction>,
{
fill_op_tx_env(tx_env, transaction, sender, meta);
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
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(

View File

@ -2,7 +2,7 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_interfaces::provider::ProviderResult;
use reth_primitives::{
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"))]
@ -114,20 +114,17 @@ impl StateProvider for StateProviderTest {
pub struct TestEvmConfig;
impl ConfigureEvmEnv for TestEvmConfig {
#[cfg(not(feature = "optimism"))]
type TxMeta = ();
#[cfg(feature = "optimism")]
type TxMeta = Bytes;
#[allow(unused_variables)]
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta)
where
T: AsRef<Transaction>,
{
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
#[cfg(not(feature = "optimism"))]
fill_tx_env(tx_env, transaction, sender);
#[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(

View File

@ -20,7 +20,7 @@ use reth::{
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, FullNodeTypes};
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
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 std::sync::Arc;
@ -61,13 +61,8 @@ impl MyEvmConfig {
}
impl ConfigureEvmEnv for MyEvmConfig {
type TxMeta = ();
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_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
EthEvmConfig::fill_tx_env(tx_env, transaction, sender)
}
fn fill_cfg_env(