Skip to content

Commit a98025e

Browse files
authored
fix(op): fix inspection call (#2184)
* feat: decouple first_frame_input in inspector * fix(op): fix inspection call * rm one trait requirement
1 parent a21d64e commit a98025e

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

crates/handler/src/handler.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,26 @@ impl<
3232
{
3333
}
3434

35+
/// Main logic of Ethereum Mainnet execution.
36+
///
37+
/// The starting point for execution is the `run` method. And without overriding
38+
/// any methods allows you to execute Ethereum mainnet transactions.
39+
///
40+
/// If there is a need to change parts of execution logic this can be done by changing default
41+
/// method implementation.
42+
///
43+
/// Handler logic is split in four parts:
44+
/// * Verification - loads caller account checks initial gas requirement.
45+
/// * Pre execution - loads and warms rest of accounts and deducts initial gas.
46+
/// * Execution - Executed the main frame loop. It calls [`Frame`] for sub call logic.
47+
/// * Post execution - Calculates the final refund, checks gas floor, reimburses caller and
48+
/// rewards beneficiary.
3549
pub trait Handler {
50+
/// The EVM type that contains Context, Instruction, Precompiles.
3651
type Evm: EvmTr<Context: ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>>>;
52+
/// Error that is going to be returned.
3753
type Error: EvmTrError<Self::Evm>;
54+
/// Frame type contains data for frame execution. EthFrame currently supports Call, Create and EofCreate frames.
3855
// TODO `FrameResult` should be a generic trait.
3956
// TODO `FrameInit` should be a generic.
4057
type Frame: Frame<
@@ -43,7 +60,8 @@ pub trait Handler {
4360
FrameResult = FrameResult,
4461
FrameInit = FrameInput,
4562
>;
46-
// TODO `HaltReason` should be part of the output.
63+
/// Halt reason type is part of the output
64+
/// TODO `HaltReason` should be part of the output.
4765
type HaltReason: HaltReasonTr;
4866

4967
#[inline]

crates/optimism/src/api/exec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use revm::{
99
Cfg, ContextTr, Database, JournalTr,
1010
},
1111
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
12-
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
12+
inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt},
1313
interpreter::{interpreter::EthInterpreter, InterpreterResult},
1414
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
1515
};
@@ -83,7 +83,7 @@ where
8383

8484
fn inspect_previous(&mut self) -> Self::Output {
8585
let mut h = OpHandler::<_, _, EthFrame<_, _, _>>::new();
86-
h.run(self)
86+
h.inspect_run(self)
8787
}
8888
}
8989

crates/optimism/src/evm.rs

+32
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use revm::{
66
instructions::{EthInstructions, InstructionProvider},
77
EvmTr,
88
},
9+
inspector::{InspectorEvmTr, JournalExt},
910
interpreter::{
1011
interpreter::EthInterpreter, Host, Interpreter, InterpreterAction, InterpreterTypes,
1112
},
13+
Inspector,
1214
};
1315

1416
pub struct OpEvm<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = OpPrecompiles>(
@@ -25,6 +27,36 @@ impl<CTX: Host, INSP> OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, OpP
2527
}
2628
}
2729

30+
impl<CTX: ContextSetters, INSP, I, P> InspectorEvmTr for OpEvm<CTX, INSP, I, P>
31+
where
32+
CTX: ContextTr<Journal: JournalExt>,
33+
I: InstructionProvider<
34+
Context = CTX,
35+
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
36+
>,
37+
INSP: Inspector<CTX, I::InterpreterTypes>,
38+
{
39+
type Inspector = INSP;
40+
41+
fn inspector(&mut self) -> &mut Self::Inspector {
42+
&mut self.0.data.inspector
43+
}
44+
45+
fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
46+
(&mut self.0.data.ctx, &mut self.0.data.inspector)
47+
}
48+
49+
fn run_inspect_interpreter(
50+
&mut self,
51+
interpreter: &mut Interpreter<
52+
<Self::Instructions as InstructionProvider>::InterpreterTypes,
53+
>,
54+
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
55+
{
56+
self.0.run_inspect_interpreter(interpreter)
57+
}
58+
}
59+
2860
impl<CTX: ContextSetters, INSP, I, P> ContextSetters for OpEvm<CTX, INSP, I, P> {
2961
type Tx = <CTX as ContextSetters>::Tx;
3062
type Block = <CTX as ContextSetters>::Block;

0 commit comments

Comments
 (0)