diff --git a/crates/handler/src/handler.rs b/crates/handler/src/handler.rs index 32078dd961..2779d77138 100644 --- a/crates/handler/src/handler.rs +++ b/crates/handler/src/handler.rs @@ -32,9 +32,26 @@ impl< { } +/// Main logic of Ethereum Mainnet execution. +/// +/// The starting point for execution is the `run` method. And without overriding +/// any methods allows you to execute Ethereum mainnet transactions. +/// +/// If there is a need to change parts of execution logic this can be done by changing default +/// method implementation. +/// +/// Handler logic is split in four parts: +/// * Verification - loads caller account checks initial gas requirement. +/// * Pre execution - loads and warms rest of accounts and deducts initial gas. +/// * Execution - Executed the main frame loop. It calls [`Frame`] for sub call logic. +/// * Post execution - Calculates the final refund, checks gas floor, reimburses caller and +/// rewards beneficiary. pub trait Handler { + /// The EVM type that contains Context, Instruction, Precompiles. type Evm: EvmTr>>; + /// Error that is going to be returned. type Error: EvmTrError; + /// Frame type contains data for frame execution. EthFrame currently supports Call, Create and EofCreate frames. // TODO `FrameResult` should be a generic trait. // TODO `FrameInit` should be a generic. type Frame: Frame< @@ -43,7 +60,8 @@ pub trait Handler { FrameResult = FrameResult, FrameInit = FrameInput, >; - // TODO `HaltReason` should be part of the output. + /// Halt reason type is part of the output + /// TODO `HaltReason` should be part of the output. type HaltReason: HaltReasonTr; #[inline] diff --git a/crates/optimism/src/api/exec.rs b/crates/optimism/src/api/exec.rs index f82c4a0017..ecbf58d5af 100644 --- a/crates/optimism/src/api/exec.rs +++ b/crates/optimism/src/api/exec.rs @@ -9,7 +9,7 @@ use revm::{ Cfg, ContextTr, Database, JournalTr, }, handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider}, - inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt}, + inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt}, interpreter::{interpreter::EthInterpreter, InterpreterResult}, DatabaseCommit, ExecuteCommitEvm, ExecuteEvm, }; @@ -83,7 +83,7 @@ where fn inspect_previous(&mut self) -> Self::Output { let mut h = OpHandler::<_, _, EthFrame<_, _, _>>::new(); - h.run(self) + h.inspect_run(self) } } diff --git a/crates/optimism/src/evm.rs b/crates/optimism/src/evm.rs index 6aecd23f22..81c2da424a 100644 --- a/crates/optimism/src/evm.rs +++ b/crates/optimism/src/evm.rs @@ -6,9 +6,11 @@ use revm::{ instructions::{EthInstructions, InstructionProvider}, EvmTr, }, + inspector::{InspectorEvmTr, JournalExt}, interpreter::{ interpreter::EthInterpreter, Host, Interpreter, InterpreterAction, InterpreterTypes, }, + Inspector, }; pub struct OpEvm, P = OpPrecompiles>( @@ -25,6 +27,36 @@ impl OpEvm, OpP } } +impl InspectorEvmTr for OpEvm +where + CTX: ContextTr, + I: InstructionProvider< + Context = CTX, + InterpreterTypes: InterpreterTypes, + >, + INSP: Inspector, +{ + type Inspector = INSP; + + fn inspector(&mut self) -> &mut Self::Inspector { + &mut self.0.data.inspector + } + + fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) { + (&mut self.0.data.ctx, &mut self.0.data.inspector) + } + + fn run_inspect_interpreter( + &mut self, + interpreter: &mut Interpreter< + ::InterpreterTypes, + >, + ) -> <::InterpreterTypes as InterpreterTypes>::Output + { + self.0.run_inspect_interpreter(interpreter) + } +} + impl ContextSetters for OpEvm { type Tx = ::Tx; type Block = ::Block;