Trait BlockExecutor

pub trait BlockExecutor {
    type Transaction;
    type Receipt;
    type Evm: Evm
       where <Self::Evm as Evm>::Tx: FromRecoveredTx<Self::Transaction> + FromTxWithEncoded<Self::Transaction>;

    // Required methods
    fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError>;
    fn execute_transaction_with_commit_condition(
        &mut self,
        tx: impl ExecutableTx<Self>,
        f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
    ) -> Result<Option<u64>, BlockExecutionError>;
    fn finish(
        self,
    ) -> Result<(Self::Evm, BlockExecutionResult<Self::Receipt>), BlockExecutionError>;
    fn set_state_hook(&mut self, hook: Option<Box<dyn OnStateHook>>);
    fn evm_mut(&mut self) -> &mut Self::Evm;
    fn evm(&self) -> &Self::Evm;

    // Provided methods
    fn execute_transaction(
        &mut self,
        tx: impl ExecutableTx<Self>,
    ) -> Result<u64, BlockExecutionError> { ... }
    fn execute_transaction_with_result_closure(
        &mut self,
        tx: impl ExecutableTx<Self>,
        f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>),
    ) -> Result<u64, BlockExecutionError> { ... }
    fn apply_post_execution_changes(
        self,
    ) -> Result<BlockExecutionResult<Self::Receipt>, BlockExecutionError>
       where Self: Sized { ... }
    fn with_state_hook(self, hook: Option<Box<dyn OnStateHook>>) -> Self
       where Self: Sized { ... }
    fn execute_block(
        self,
        transactions: impl IntoIterator<Item = impl ExecutableTx<Self>>,
    ) -> Result<BlockExecutionResult<Self::Receipt>, BlockExecutionError>
       where Self: Sized { ... }
}
Expand description

A type that knows how to execute a single block.

The current abstraction assumes that block execution consists of the following steps:

  1. Apply pre-execution changes. Those might include system calls, irregular state transitions (DAO fork), etc.
  2. Apply block transactions to the state.
  3. Apply post-execution changes and finalize the state. This might include other system calls, block rewards, etc.

The output of BlockExecutor::finish is a BlockExecutionResult which contains all relevant information about the block execution.

Required Associated Types§

type Transaction

Input transaction type.

type Receipt

Receipt type this executor produces.

type Evm: Evm where <Self::Evm as Evm>::Tx: FromRecoveredTx<Self::Transaction> + FromTxWithEncoded<Self::Transaction>

EVM used by the executor.

Required Methods§

fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError>

Applies any necessary changes before executing the block’s transactions.

fn execute_transaction_with_commit_condition( &mut self, tx: impl ExecutableTx<Self>, f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges, ) -> Result<Option<u64>, BlockExecutionError>

Executes a single transaction and applies execution result to internal state. Invokes the given closure with an internal ExecutionResult produced by the EVM, and commits the transaction to the state on CommitChanges::Yes.

Returns None if transaction was skipped via CommitChanges::No.

fn finish( self, ) -> Result<(Self::Evm, BlockExecutionResult<Self::Receipt>), BlockExecutionError>

Applies any necessary changes after executing the block’s transactions, completes execution and returns the underlying EVM along with execution result.

fn set_state_hook(&mut self, hook: Option<Box<dyn OnStateHook>>)

Sets a hook to be called after each state change during execution.

fn evm_mut(&mut self) -> &mut Self::Evm

Exposes mutable reference to EVM.

fn evm(&self) -> &Self::Evm

Exposes immutable reference to EVM.

Provided Methods§

fn execute_transaction( &mut self, tx: impl ExecutableTx<Self>, ) -> Result<u64, BlockExecutionError>

Executes a single transaction and applies execution result to internal state.

Returns the gas used by the transaction.

fn execute_transaction_with_result_closure( &mut self, tx: impl ExecutableTx<Self>, f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>), ) -> Result<u64, BlockExecutionError>

Executes a single transaction and applies execution result to internal state. Invokes the given closure with an internal ExecutionResult produced by the EVM.

fn apply_post_execution_changes( self, ) -> Result<BlockExecutionResult<Self::Receipt>, BlockExecutionError>
where Self: Sized,

A helper to invoke BlockExecutor::finish returning only the BlockExecutionResult.

fn with_state_hook(self, hook: Option<Box<dyn OnStateHook>>) -> Self
where Self: Sized,

A builder-style helper to invoke BlockExecutor::set_state_hook.

fn execute_block( self, transactions: impl IntoIterator<Item = impl ExecutableTx<Self>>, ) -> Result<BlockExecutionResult<Self::Receipt>, BlockExecutionError>
where Self: Sized,

Executes all transactions in a block, applying pre and post execution changes.

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.

Implementations on Foreign Types§

§

impl<'db, DB, E, Spec, R, C> BlockExecutor for SeismicBlockExecutor<'_, E, Spec, R, C>
where DB: Database + 'db, E: Evm<DB = &'db mut State<DB>>, <E as Evm>::Tx: FromRecoveredTx<<R as ReceiptBuilder>::Transaction> + FromTxWithEncoded<<R as ReceiptBuilder>::Transaction>, Spec: EthExecutorSpec, R: ReceiptBuilder, <R as ReceiptBuilder>::Transaction: Transaction + Encodable2718 + InputDecryptionElements, <R as ReceiptBuilder>::Receipt: TxReceipt<Log = Log>, C: SyncEnclaveApiClient,

§

type Transaction = <R as ReceiptBuilder>::Transaction

§

type Receipt = <R as ReceiptBuilder>::Receipt

§

type Evm = E

§

fn apply_pre_execution_changes(&mut self) -> Result<(), BlockExecutionError>

§

fn execute_transaction_with_commit_condition( &mut self, tx: impl ExecutableTx<SeismicBlockExecutor<'_, E, Spec, R, C>>, f: impl FnOnce(&ExecutionResult<<<SeismicBlockExecutor<'_, E, Spec, R, C> as BlockExecutor>::Evm as Evm>::HaltReason>) -> CommitChanges, ) -> Result<Option<u64>, BlockExecutionError>

§

fn execute_transaction_with_result_closure( &mut self, tx: impl ExecutableTx<SeismicBlockExecutor<'_, E, Spec, R, C>>, f: impl FnOnce(&ExecutionResult<<<SeismicBlockExecutor<'_, E, Spec, R, C> as BlockExecutor>::Evm as Evm>::HaltReason>), ) -> Result<u64, BlockExecutionError>

§

fn finish( self, ) -> Result<(<SeismicBlockExecutor<'_, E, Spec, R, C> as BlockExecutor>::Evm, BlockExecutionResult<<R as ReceiptBuilder>::Receipt>), BlockExecutionError>

§

fn set_state_hook(&mut self, hook: Option<Box<dyn OnStateHook>>)

§

fn evm_mut( &mut self, ) -> &mut <SeismicBlockExecutor<'_, E, Spec, R, C> as BlockExecutor>::Evm

§

fn evm( &self, ) -> &<SeismicBlockExecutor<'_, E, Spec, R, C> as BlockExecutor>::Evm

Implementors§

§

impl<'db, DB, E, Spec, R> BlockExecutor for EthBlockExecutor<'_, E, Spec, R>
where DB: Database + 'db, E: Evm<DB = &'db mut State<DB>>, <E as Evm>::Tx: FromRecoveredTx<<R as ReceiptBuilder>::Transaction> + FromTxWithEncoded<<R as ReceiptBuilder>::Transaction>, Spec: EthExecutorSpec, R: ReceiptBuilder, <R as ReceiptBuilder>::Transaction: Transaction + Encodable2718, <R as ReceiptBuilder>::Receipt: TxReceipt<Log = Log>,