pub trait ConfigureEvm:
Clone
+ Debug
+ Send
+ Sync
+ Unpin {
type Primitives: NodePrimitives;
type Error: Error + Send + Sync + 'static;
type NextBlockEnvCtx: Debug + Clone;
type BlockExecutorFactory: BlockExecutorFactory<Transaction = TxTy<Self::Primitives>, Receipt = ReceiptTy<Self::Primitives>, EvmFactory: EvmFactory<Tx: TransactionEnv + FromRecoveredTx<TxTy<Self::Primitives>> + FromTxWithEncoded<TxTy<Self::Primitives>>>>;
type BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = BlockTy<Self::Primitives>>;
Show 15 methods
// Required methods
fn block_executor_factory(&self) -> &Self::BlockExecutorFactory;
fn block_assembler(&self) -> &Self::BlockAssembler;
fn evm_env(&self, header: &HeaderTy<Self::Primitives>) -> EvmEnvFor<Self>;
fn next_evm_env(
&self,
parent: &HeaderTy<Self::Primitives>,
attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnvFor<Self>, Self::Error>;
fn context_for_block<'a>(
&self,
block: &'a SealedBlock<BlockTy<Self::Primitives>>,
) -> ExecutionCtxFor<'a, Self>;
fn context_for_next_block(
&self,
parent: &SealedHeader<HeaderTy<Self::Primitives>>,
attributes: Self::NextBlockEnvCtx,
) -> ExecutionCtxFor<'_, Self>;
// Provided methods
fn tx_env(
&self,
transaction: impl IntoTxEnv<TxEnvFor<Self>>,
) -> TxEnvFor<Self> { ... }
fn evm_factory(&self) -> &EvmFactoryFor<Self> { ... }
fn evm_with_env<DB: Database>(
&self,
db: DB,
evm_env: EvmEnvFor<Self>,
) -> EvmFor<Self, DB> { ... }
fn evm_for_block<DB: Database>(
&self,
db: DB,
header: &HeaderTy<Self::Primitives>,
) -> EvmFor<Self, DB> { ... }
fn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnvFor<Self>,
inspector: I,
) -> EvmFor<Self, DB, I>
where DB: Database,
I: InspectorFor<Self, DB> { ... }
fn create_executor<'a, DB, I>(
&'a self,
evm: EvmFor<Self, &'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: Database>(
&'a self,
db: &'a mut State<DB>,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB> { ... }
fn create_block_builder<'a, DB, I>(
&'a self,
evm: EvmFor<Self, &'a mut State<DB>, I>,
parent: &'a SealedHeader<HeaderTy<Self::Primitives>>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives, Executor: BlockExecutorFor<'a, Self::BlockExecutorFactory, DB, I>>
where DB: Database,
I: InspectorFor<Self, &'a mut State<DB>> + 'a { ... }
fn builder_for_next_block<'a, DB: Database>(
&'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> { ... }
}
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§
Sourcetype Primitives: NodePrimitives
type Primitives: NodePrimitives
The primitives type used by the EVM.
Sourcetype Error: Error + Send + Sync + 'static
type Error: Error + Send + Sync + 'static
The error type that is returned by Self::next_evm_env
.
Sourcetype 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.
Sourcetype BlockExecutorFactory: BlockExecutorFactory<Transaction = TxTy<Self::Primitives>, Receipt = ReceiptTy<Self::Primitives>, EvmFactory: EvmFactory<Tx: TransactionEnv + FromRecoveredTx<TxTy<Self::Primitives>> + FromTxWithEncoded<TxTy<Self::Primitives>>>>
type BlockExecutorFactory: BlockExecutorFactory<Transaction = TxTy<Self::Primitives>, Receipt = ReceiptTy<Self::Primitives>, EvmFactory: EvmFactory<Tx: TransactionEnv + FromRecoveredTx<TxTy<Self::Primitives>> + FromTxWithEncoded<TxTy<Self::Primitives>>>>
Configured BlockExecutorFactory
, contains EvmFactory
internally.
Sourcetype BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = BlockTy<Self::Primitives>>
type BlockAssembler: BlockAssembler<Self::BlockExecutorFactory, Block = BlockTy<Self::Primitives>>
A type that knows how to build a block.
Required Methods§
Sourcefn block_executor_factory(&self) -> &Self::BlockExecutorFactory
fn block_executor_factory(&self) -> &Self::BlockExecutorFactory
Returns reference to the configured BlockExecutorFactory
.
Sourcefn block_assembler(&self) -> &Self::BlockAssembler
fn block_assembler(&self) -> &Self::BlockAssembler
Returns reference to the configured BlockAssembler
.
Sourcefn evm_env(&self, header: &HeaderTy<Self::Primitives>) -> EvmEnvFor<Self>
fn evm_env(&self, header: &HeaderTy<Self::Primitives>) -> EvmEnvFor<Self>
Creates a new EvmEnv
for the given header.
Sourcefn next_evm_env(
&self,
parent: &HeaderTy<Self::Primitives>,
attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnvFor<Self>, Self::Error>
fn next_evm_env( &self, parent: &HeaderTy<Self::Primitives>, attributes: &Self::NextBlockEnvCtx, ) -> Result<EvmEnvFor<Self>, 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.
Sourcefn context_for_block<'a>(
&self,
block: &'a SealedBlock<BlockTy<Self::Primitives>>,
) -> ExecutionCtxFor<'a, Self>
fn context_for_block<'a>( &self, block: &'a SealedBlock<BlockTy<Self::Primitives>>, ) -> ExecutionCtxFor<'a, Self>
Returns the configured BlockExecutorFactory::ExecutionCtx
for a given block.
Sourcefn context_for_next_block(
&self,
parent: &SealedHeader<HeaderTy<Self::Primitives>>,
attributes: Self::NextBlockEnvCtx,
) -> ExecutionCtxFor<'_, Self>
fn context_for_next_block( &self, parent: &SealedHeader<HeaderTy<Self::Primitives>>, attributes: Self::NextBlockEnvCtx, ) -> ExecutionCtxFor<'_, Self>
Returns the configured BlockExecutorFactory::ExecutionCtx
for parent + 1
block.
Provided Methods§
Sourcefn tx_env(&self, transaction: impl IntoTxEnv<TxEnvFor<Self>>) -> TxEnvFor<Self>
fn tx_env(&self, transaction: impl IntoTxEnv<TxEnvFor<Self>>) -> TxEnvFor<Self>
Returns a [TxEnv
] from a transaction and [Address
].
Sourcefn evm_factory(&self) -> &EvmFactoryFor<Self>
fn evm_factory(&self) -> &EvmFactoryFor<Self>
Provides a reference to EvmFactory
implementation.
Sourcefn evm_with_env<DB: Database>(
&self,
db: DB,
evm_env: EvmEnvFor<Self>,
) -> EvmFor<Self, DB>
fn evm_with_env<DB: Database>( &self, db: DB, evm_env: EvmEnvFor<Self>, ) -> EvmFor<Self, DB>
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
Sourcefn evm_for_block<DB: Database>(
&self,
db: DB,
header: &HeaderTy<Self::Primitives>,
) -> EvmFor<Self, DB>
fn evm_for_block<DB: Database>( &self, db: DB, header: &HeaderTy<Self::Primitives>, ) -> EvmFor<Self, DB>
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.
Sourcefn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnvFor<Self>,
inspector: I,
) -> EvmFor<Self, DB, I>where
DB: Database,
I: InspectorFor<Self, DB>,
fn evm_with_env_and_inspector<DB, I>(
&self,
db: DB,
evm_env: EvmEnvFor<Self>,
inspector: I,
) -> EvmFor<Self, 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
Sourcefn create_executor<'a, DB, I>(
&'a self,
evm: EvmFor<Self, &'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: EvmFor<Self, &'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.
Sourcefn executor_for_block<'a, DB: Database>(
&'a self,
db: &'a mut State<DB>,
block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>,
) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB>
fn executor_for_block<'a, DB: Database>( &'a self, db: &'a mut State<DB>, block: &'a SealedBlock<<Self::Primitives as NodePrimitives>::Block>, ) -> impl BlockExecutorFor<'a, Self::BlockExecutorFactory, DB>
Creates a strategy for execution of a given block.
Sourcefn create_block_builder<'a, DB, I>(
&'a self,
evm: EvmFor<Self, &'a mut State<DB>, I>,
parent: &'a SealedHeader<HeaderTy<Self::Primitives>>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives, Executor: 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: EvmFor<Self, &'a mut State<DB>, I>,
parent: &'a SealedHeader<HeaderTy<Self::Primitives>>,
ctx: <Self::BlockExecutorFactory as BlockExecutorFactory>::ExecutionCtx<'a>,
) -> impl BlockBuilder<Primitives = Self::Primitives, Executor: 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.
Sourcefn builder_for_next_block<'a, DB: Database>(
&'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>
fn builder_for_next_block<'a, DB: Database>( &'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>
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.