Skip to content

Commit

Permalink
feat: rm txmeta associated type (paradigmxyz#8138)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored May 7, 2024
1 parent bcb0bff commit 05e434e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 70 deletions.
12 changes: 2 additions & 10 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_evm::{
BatchBlockExecutionOutput, BatchExecutor, BlockExecutionInput, BlockExecutionOutput,
BlockExecutorProvider, Executor,
},
ConfigureEvm, ConfigureEvmEnv,
ConfigureEvm,
};
use reth_interfaces::{
executor::{BlockExecutionError, BlockValidationError},
Expand Down Expand Up @@ -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
Expand All @@ -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>;

Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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>;
Expand Down
9 changes: 2 additions & 7 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
}

Expand Down
17 changes: 5 additions & 12 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(
Expand Down
18 changes: 4 additions & 14 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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>;

Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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>;
Expand Down
13 changes: 5 additions & 8 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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(
Expand Down
19 changes: 8 additions & 11 deletions crates/revm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 3 additions & 8 deletions examples/custom-evm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 05e434e

Please sign in to comment.