Trait ExecuteEvm

pub trait ExecuteEvm {
    type ExecutionResult;
    type State;
    type Error;
    type Tx: Transaction;
    type Block: Block;

    // Required methods
    fn set_block(&mut self, block: Self::Block);
    fn transact_one(
        &mut self,
        tx: Self::Tx,
    ) -> Result<Self::ExecutionResult, Self::Error>;
    fn finalize(&mut self) -> Self::State;
    fn replay(
        &mut self,
    ) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>;

    // Provided methods
    fn transact(
        &mut self,
        tx: Self::Tx,
    ) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
    fn transact_many(
        &mut self,
        txs: impl Iterator<Item = Self::Tx>,
    ) -> Result<Vec<Self::ExecutionResult>, Self::Error> { ... }
    fn transact_many_finalize(
        &mut self,
        txs: impl Iterator<Item = Self::Tx>,
    ) -> Result<ExecResultAndState<Vec<Self::ExecutionResult>, Self::State>, Self::Error> { ... }
}
Expand description

Execute EVM transactions. Main trait for transaction execution.

Required Associated Types§

type ExecutionResult

Output of transaction execution.

type State

Output state type representing changes after execution.

type Error

Error type

type Tx: Transaction

Transaction type.

type Block: Block

Block type.

Required Methods§

fn set_block(&mut self, block: Self::Block)

Set the block.

fn transact_one( &mut self, tx: Self::Tx, ) -> Result<Self::ExecutionResult, Self::Error>

Execute transaction and store state inside journal. Returns output of transaction execution.

§Return Value

Returns only the execution result

§Error Handling

If the transaction fails, the journal will revert all changes of given transaction. For quicker error handling, use ExecuteEvm::transact that will drop the journal.

§State Management

State changes are stored in the internal journal. To retrieve the state, call ExecuteEvm::finalize after transaction execution.

§History Note

Previously this function returned both output and state. Now it follows a two-step process: execute then finalize.

fn finalize(&mut self) -> Self::State

Finalize execution, clearing the journal and returning the accumulated state changes.

§State Management

Journal is cleared and can be used for next transaction.

fn replay( &mut self, ) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>

Execute previous transaction and finalize it.

Provided Methods§

fn transact( &mut self, tx: Self::Tx, ) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error>

Transact the given transaction and finalize in a single operation.

Internally calls ExecuteEvm::transact_one followed by ExecuteEvm::finalize.

§Outcome of Error

If the transaction fails, the journal is considered broken.

fn transact_many( &mut self, txs: impl Iterator<Item = Self::Tx>, ) -> Result<Vec<Self::ExecutionResult>, Self::Error>

Execute multiple transactions without finalizing the state.

Returns a vector of execution results. State changes are accumulated in the journal but not finalized. Call ExecuteEvm::finalize after execution to retrieve state changes.

§Outcome of Error

If any transaction fails, the journal is finalized and the last error is returned.

TODO add tx index to the error.

fn transact_many_finalize( &mut self, txs: impl Iterator<Item = Self::Tx>, ) -> Result<ExecResultAndState<Vec<Self::ExecutionResult>, Self::State>, Self::Error>

Execute multiple transactions and finalize the state in a single operation.

Internally calls ExecuteEvm::transact_many followed by ExecuteEvm::finalize.

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<CTX, INSP, PRECOMPILE> ExecuteEvm for OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
where CTX: OpContextTr + ContextSetters, PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,

§

type Tx = <CTX as ContextTr>::Tx

§

type Block = <CTX as ContextTr>::Block

§

type State = HashMap<Address, Account, RandomState>

§

type Error = EVMError<<<CTX as ContextTr>::Db as Database>::Error, OpTransactionError>

§

type ExecutionResult = ExecutionResult<OpHaltReason>

§

fn set_block( &mut self, block: <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::Block, )

§

fn transact_one( &mut self, tx: <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::Tx, ) -> Result<<OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::ExecutionResult, <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::Error>

§

fn finalize( &mut self, ) -> <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::State

§

fn replay( &mut self, ) -> Result<ExecResultAndState<<OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::ExecutionResult, <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::State>, <OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE> as ExecuteEvm>::Error>

Implementors§

§

impl<CTX, INSP, INST, PRECOMPILES> ExecuteEvm for Evm<CTX, INSP, INST, PRECOMPILES, EthFrame>
where CTX: ContextTr + ContextSetters, <CTX as ContextTr>::Journal: JournalTr<State = HashMap<Address, Account, RandomState>>, INST: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>, PRECOMPILES: PrecompileProvider<CTX, Output = InterpreterResult>,