Trait ConfigureEvm
pub trait ConfigureEvm:
Send
+ Sync
+ Unpin
+ Clone {
type Primitives: NodePrimitives;
type Error: Error + Send + Sync + 'static;
type NextBlockEnvCtx: Debug + Clone;
type BlockExecutorFactory: BlockExecutorFactory<Transaction = <Self::Primitives as NodePrimitives>::SignedTx, Receipt = <Self::Primitives as NodePrimitives>::Receipt>
where <Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory: EvmFactory,
<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx: TransactionEnv + FromRecoveredTx<<Self::Primitives as NodePrimitives>::SignedTx>;
type BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = <Self::Primitives as NodePrimitives>::Block>;
Show 15 methods
// Required methods
fn block_executor_factory(&self) -> &Self::BlockExecutorFactory;
fn block_assembler(&self) -> &Self::BlockAssembler;
fn evm_env(
&self,
header: &<Self::Primitives as NodePrimitives>::BlockHeader,
) -> EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>;
fn next_evm_env(
&self,
parent: &<Self::Primitives as NodePrimitives>::BlockHeader,
attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>, Self::Error>;
fn context_for_block<'a>(
&self,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>;
fn context_for_next_block(
&self,
parent: &SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
attributes: Self::NextBlockEnvCtx,
) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'_>;
// Provided methods
fn tx_env(
&self,
transaction: impl IntoTxEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx>,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx { ... }
fn evm_factory(
&self,
) -> &<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory { ... }
fn evm_with_env<DB>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>
where DB: Database { ... }
fn evm_for_block<DB>(
&self,
db: DB,
header: &<Self::Primitives as NodePrimitives>::BlockHeader,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>
where DB: Database { ... }
fn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
inspector: I,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, I>
where DB: Database,
I: InspectorFor<Self, DB> { ... }
fn create_executor<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>
where DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a { ... }
fn executor_for_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB>
where DB: Database { ... }
fn create_block_builder<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives> + BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>
where DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a { ... }
fn builder_for_next_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
attributes: Self::NextBlockEnvCtx,
) -> Result<impl BlockBuilder<Primitives = Self::Primitives>, Self::Error>
where DB: Database { ... }
}
evm
only.Expand description
A complete configuration of EVM for Reth.
This trait encapsulates complete configuration required for transaction execution and block execution/building.
The EVM abstraction consists of the following layers:
- Evm
produced by EvmFactory
: The EVM implementation responsilble for executing
individual transactions and producing output for them including state changes, logs, gas
usage, etc.
- BlockExecutor
produced by BlockExecutorFactory
: Executor operates on top of
Evm
and is responsible for executing entire blocks. This is different from simply
aggregating outputs of transactions execution as it also involves higher level state
changes such as receipt building, applying block rewards, system calls, etc.
- BlockAssembler
: Encapsulates logic for assembling blocks. It operates on context and
output of BlockExecutor
, and is required to know how to assemble a next block to
include in the chain.
All of the above components need configuration environment which we are abstracting over to allow plugging EVM implementation into Reth SDK.
The abstraction is designed to serve 2 codepaths: 1. Externally provided complete block (e.g received while syncing). 2. Block building when we know parent block and some additional context obtained from payload attributes or alike.
First case is handled by ConfigureEvm::evm_env
and ConfigureEvm::context_for_block
which implement a conversion from NodePrimitives::Block
to EvmEnv
and ExecutionCtx
,
and allow configuring EVM and block execution environment at a given block.
Second case is handled by similar ConfigureEvm::next_evm_env
and
ConfigureEvm::context_for_next_block
which take parent NodePrimitives::BlockHeader
along with NextBlockEnvCtx
. NextBlockEnvCtx
is very similar to payload attributes and
simply contains context for next block that is generally received from a CL node (timestamp,
beneficiary, withdrawals, etc.).
Required Associated Types§
type Primitives: NodePrimitives
type Primitives: NodePrimitives
The primitives type used by the EVM.
type Error: Error + Send + Sync + 'static
type Error: Error + Send + Sync + 'static
The error type that is returned by Self::next_evm_env
.
type NextBlockEnvCtx: Debug + Clone
type NextBlockEnvCtx: Debug + Clone
Context required for configuring next block environment.
Contains values that can’t be derived from the parent block.
type BlockExecutorFactory: BlockExecutorFactory<Transaction = <Self::Primitives as NodePrimitives>::SignedTx, Receipt = <Self::Primitives as NodePrimitives>::Receipt>
where
<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory: EvmFactory,
<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx: TransactionEnv + FromRecoveredTx<<Self::Primitives as NodePrimitives>::SignedTx>
type BlockExecutorFactory: BlockExecutorFactory<Transaction = <Self::Primitives as NodePrimitives>::SignedTx, Receipt = <Self::Primitives as NodePrimitives>::Receipt> where <Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory: EvmFactory, <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx: TransactionEnv + FromRecoveredTx<<Self::Primitives as NodePrimitives>::SignedTx>
Configured BlockExecutorFactory
, contains EvmFactory
internally.
type BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = <Self::Primitives as NodePrimitives>::Block>
type BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = <Self::Primitives as NodePrimitives>::Block>
A type that knows how to build a block.
Required Methods§
fn block_executor_factory(&self) -> &Self::BlockExecutorFactory
fn block_executor_factory(&self) -> &Self::BlockExecutorFactory
Returns reference to the configured BlockExecutorFactory
.
fn block_assembler(&self) -> &Self::BlockAssembler
fn block_assembler(&self) -> &Self::BlockAssembler
Returns reference to the configured BlockAssembler
.
fn evm_env(
&self,
header: &<Self::Primitives as NodePrimitives>::BlockHeader,
) -> EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>
fn evm_env( &self, header: &<Self::Primitives as NodePrimitives>::BlockHeader, ) -> EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>
Creates a new EvmEnv
for the given header.
fn next_evm_env(
&self,
parent: &<Self::Primitives as NodePrimitives>::BlockHeader,
attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>, Self::Error>
fn next_evm_env( &self, parent: &<Self::Primitives as NodePrimitives>::BlockHeader, attributes: &Self::NextBlockEnvCtx, ) -> Result<EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>, Self::Error>
Returns the configured EvmEnv
for parent + 1
block.
This is intended for usage in block building after the merge and requires additional attributes that can’t be derived from the parent block: attributes that are determined by the CL, such as the timestamp, suggested fee recipient, and randomness value.
fn context_for_block<'a>(
&self,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>
fn context_for_block<'a>( &self, block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>, ) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>
Returns the configured BlockExecutorFactory::ExecutionCtx
for a given block.
fn context_for_next_block(
&self,
parent: &SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
attributes: Self::NextBlockEnvCtx,
) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'_>
fn context_for_next_block( &self, parent: &SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>, attributes: Self::NextBlockEnvCtx, ) -> <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'_>
Returns the configured BlockExecutorFactory::ExecutionCtx
for parent + 1
block.
Provided Methods§
fn tx_env(
&self,
transaction: impl IntoTxEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx>,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx
fn tx_env( &self, transaction: impl IntoTxEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx>, ) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Tx
Returns a [TxEnv
] from a transaction and [Address
].
fn evm_factory(
&self,
) -> &<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory
fn evm_factory( &self, ) -> &<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory
Provides a reference to EvmFactory
implementation.
fn evm_with_env<DB>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>where
DB: Database,
fn evm_with_env<DB>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>where
DB: Database,
Returns a new EVM with the given database configured with the given environment settings, including the spec id and transaction environment.
This will preserve any handler modifications
fn evm_for_block<DB>(
&self,
db: DB,
header: &<Self::Primitives as NodePrimitives>::BlockHeader,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>where
DB: Database,
fn evm_for_block<DB>(
&self,
db: DB,
header: &<Self::Primitives as NodePrimitives>::BlockHeader,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, NoOpInspector>where
DB: Database,
Returns a new EVM with the given database configured with cfg
and block_env
configuration derived from the given header. Relies on
ConfigureEvm::evm_env
.
§Caution
This does not initialize the tx environment.
fn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
inspector: I,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, I>where
DB: Database,
I: InspectorFor<Self, DB>,
fn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnv<<<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Spec>,
inspector: I,
) -> <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<DB, I>where
DB: Database,
I: InspectorFor<Self, DB>,
Returns a new EVM with the given database configured with the given environment settings, including the spec id.
This will use the given external inspector as the EVM external context.
This will preserve any handler modifications
fn create_executor<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>where
DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a,
fn create_executor<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>where
DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a,
Creates a strategy with given EVM and execution context.
fn executor_for_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB>where
DB: Database,
fn executor_for_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB>where
DB: Database,
Creates a strategy for execution of a given block.
fn create_block_builder<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives> + BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>where
DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a,
fn create_block_builder<'a, DB, I>(
&'a self,
evm: <<Self::BlockExecutorFactory as BlockExecutorFactory>::EvmFactory as EvmFactory>::Evm<&'a mut State<DB>, I>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives> + BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>where
DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a,
Creates a BlockBuilder
. Should be used when building a new block.
Block builder wraps an inner alloy_evm::block::BlockExecutor
and has a similar
interface. Builder collects all of the executed transactions, and once
BlockBuilder::finish
is called, it invokes the configured BlockAssembler
to
create a block.
fn builder_for_next_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
attributes: Self::NextBlockEnvCtx,
) -> Result<impl BlockBuilder<Primitives = Self::Primitives>, Self::Error>where
DB: Database,
fn builder_for_next_block<'a, DB>(
&'a self,
db: &'a mut State<DB>,
parent: &'a SealedHeader<<Self::Primitives as NodePrimitives>::BlockHeader>,
attributes: Self::NextBlockEnvCtx,
) -> Result<impl BlockBuilder<Primitives = Self::Primitives>, Self::Error>where
DB: Database,
Creates a BlockBuilder
for building of a new block. This is a helper to invoke
ConfigureEvm::create_block_builder
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.