Skip to content

Commit

Permalink
fix tests, clippy fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Feb 6, 2025
1 parent ecd57c1 commit 1d6037f
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 393 deletions.
2 changes: 1 addition & 1 deletion crates/context/interface/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ pub struct SelfDestructResult {
pub had_value: bool,
pub target_exists: bool,
pub previously_destroyed: bool,
}
}
6 changes: 3 additions & 3 deletions crates/handler/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,19 @@ fn frame_end<CTX, INTR: InterpreterTypes>(
let FrameInput::Call(i) = frame_input else {
panic!("FrameInput::Call expected");
};
inspector.call_end(context, &i, outcome);
inspector.call_end(context, i, outcome);
}
FrameResult::Create(outcome) => {
let FrameInput::Create(i) = frame_input else {
panic!("FrameInput::Create expected");
};
inspector.create_end(context, &i, outcome);
inspector.create_end(context, i, outcome);
}
FrameResult::EOFCreate(outcome) => {
let FrameInput::EOFCreate(i) = frame_input else {
panic!("FrameInput::EofCreate expected");
};
inspector.eofcreate_end(context, &i, outcome);
inspector.eofcreate_end(context, i, outcome);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/handler/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where

pub fn new(base_table: InstructionTable<WIRE, HOST>) -> Self {
// TODO make a wrapper for inspector calls.
let inspector_table = base_table.clone();
let inspector_table = base_table;
Self {
instruction_table: Rc::new(base_table),
inspector_table: Rc::new(inspector_table),
Expand Down
2 changes: 1 addition & 1 deletion crates/handler/src/precompile_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
InstructionResult::PrecompileError
};
}
Err(err @ PrecompileErrors::Fatal { .. }) => return Err(err.into()),
Err(err @ PrecompileErrors::Fatal { .. }) => return Err(err),
}
Ok(Some(result))
}
Expand Down
9 changes: 6 additions & 3 deletions crates/optimism/src/api/builder.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{evm::OpEvm, transaction::OpTxTrait, L1BlockInfo, OpSpec};
use crate::{evm::OpEvm, transaction::OpTxTrait, L1BlockInfo, OpSpec, OpTransaction};
use precompile::Log;
use revm::{
context::Cfg,
context::{BlockEnv, Cfg, CfgEnv, TxEnv},
context_interface::{Block, Journal},
handler::{instructions::EthInstructions, noop::NoOpInspector},
interpreter::interpreter::EthInterpreter,
state::EvmState,
Context, Database,
Context, Database, JournaledState,
};

pub trait OpBuilder: Sized {
Expand Down Expand Up @@ -45,3 +45,6 @@ where
OpEvm::new(self, inspector)
}
}

pub type OpContext<DB> =
Context<BlockEnv, OpTransaction<TxEnv>, CfgEnv<OpSpec>, DB, JournaledState<DB>, L1BlockInfo>;
6 changes: 4 additions & 2 deletions crates/optimism/src/api/default_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ impl DefaultOp
mod test {
use super::*;
use crate::api::builder::OpBuilder;
use revm::ExecuteEvm;
use revm::{ExecuteEvm, InspectEvm};

#[test]
fn default_than_into() {
fn default_run_op() {
let ctx = Context::op();
// convert to optimism context
let mut evm = ctx.build_op();
// execute
let _ = evm.transact_previous();
// inspect
let _ = evm.inspect_previous();
}
}
59 changes: 53 additions & 6 deletions crates/optimism/src/api/exec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::{
evm::OpEvm, handler::OpHandler, transaction::OpTxTrait, L1BlockInfo, OpHaltReason, OpSpec,
OpTransactionError,
};
use precompile::Log;
use revm::{
context_interface::{
Expand All @@ -10,12 +14,7 @@ use revm::{
},
interpreter::interpreter::EthInterpreter,
state::EvmState,
Context, DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
};

use crate::{
evm::OpEvm, handler::OpHandler, transaction::OpTxTrait, L1BlockInfo, OpHaltReason, OpSpec,
OpTransactionError,
Context, DatabaseCommit, ExecuteCommitEvm, ExecuteEvm, InspectCommitEvm, InspectEvm,
};

impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> ExecuteEvm
Expand Down Expand Up @@ -67,3 +66,51 @@ where
})
}
}

impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> InspectEvm
for OpEvm<
Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>,
INSP,
EthInstructions<EthInterpreter, Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>>,
>
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)>,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
{
type Inspector = INSP;

fn set_inspector(&mut self, inspector: Self::Inspector) {
self.data.inspector = inspector;
}

fn inspect_previous(&mut self) -> Self::Output {
let mut h = OpHandler::<_, _, EthFrame<_, _, _>>::new();
h.run(self)
}
}

impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> InspectCommitEvm
for OpEvm<
Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>,
INSP,
EthInstructions<EthInterpreter, Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>>,
>
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
DB: Database + DatabaseCommit,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)>,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
{
fn inspect_commit_previous(&mut self) -> Self::CommitOutput {
self.inspect_previous().map(|r| {
self.ctx().db().commit(r.state);
r.result
})
}
}
Loading

0 comments on commit 1d6037f

Please sign in to comment.