Trait ExecuteEvm

Source
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(
        &mut self,
        tx: Self::Tx,
    ) -> Result<Self::ExecutionResult, Self::Error>;
    fn finalize(&mut self) -> Self::State;
    fn replay(
        &mut self,
    ) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error>;

    // Provided methods
    fn transact_finalize(
        &mut self,
        tx: Self::Tx,
    ) -> Result<ResultAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
    fn transact_multi(
        &mut self,
        txs: impl Iterator<Item = Self::Tx>,
    ) -> Result<Vec<Self::ExecutionResult>, Self::Error> { ... }
    fn transact_multi_finalize(
        &mut self,
        txs: impl Iterator<Item = Self::Tx>,
    ) -> Result<ResultVecAndState<Self::ExecutionResult, Self::State>, Self::Error> { ... }
}
Expand description

Execute EVM transactions. Main trait for transaction execution.

Required Associated Types§

Source

type ExecutionResult

Output of transaction execution.

Source

type State

Source

type Error

Error type

Source

type Tx: Transaction

Transaction type.

Source

type Block: Block

Block type.

Required Methods§

Source

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

Set the block.

Source

fn transact( &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_finalize 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.

Source

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.

Source

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

Execute previous transaction and finalize it.

Doint it without finalization

Provided Methods§

Source

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

Transact the given transaction and finalize in a single operation.

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

§Outcome of Error

If the transaction fails, the journal is considered broken.

Source

fn transact_multi( &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.

Source

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

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

Internally calls ExecuteEvm::transact_multi 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§

Source§

impl<CTX, INSP, INST, PRECOMPILES> ExecuteEvm for Evm<CTX, INSP, INST, PRECOMPILES>
where CTX: ContextTr<Journal: JournalTr<State = EvmState>> + ContextSetters, INST: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>, PRECOMPILES: PrecompileProvider<CTX, Output = InterpreterResult>,

Source§

type ExecutionResult = ExecutionResult

Source§

type State = HashMap<Address, Account>

Source§

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

Source§

type Tx = <CTX as ContextTr>::Tx

Source§

type Block = <CTX as ContextTr>::Block

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§