chore: Use traits from reth 1.5.0

This commit is contained in:
sprites0
2025-07-03 04:18:18 +00:00
parent a11335da80
commit 6a6f993766
9 changed files with 137 additions and 140 deletions

View File

@ -1,17 +1,15 @@
use super::HlEvmInner;
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use reth_revm::context::ContextTr;
use revm::{
context::{Cfg, JournalOutput},
context_interface::{Block, JournalTr},
handler::instructions::EthInstructions,
interpreter::interpreter::EthInterpreter,
Context, Database,
context::Cfg, context_interface::Block, handler::instructions::EthInstructions,
interpreter::interpreter::EthInterpreter, Context, Database,
};
/// Trait that allows for hl HlEvm to be built.
pub trait HlBuilder: Sized {
/// Type of the context.
type Context;
type Context: ContextTr;
/// Build the hl with an inspector.
fn build_hl_with_inspector<INSP>(
@ -20,13 +18,12 @@ pub trait HlBuilder: Sized {
) -> HlEvmInner<Self::Context, INSP, EthInstructions<EthInterpreter, Self::Context>>;
}
impl<BLOCK, TX, CFG, DB, JOURNAL> HlBuilder for Context<BLOCK, TX, CFG, DB, JOURNAL>
impl<BLOCK, TX, CFG, DB> HlBuilder for Context<BLOCK, TX, CFG, DB>
where
BLOCK: Block,
TX: HlTxTr,
CFG: Cfg<Spec = HlSpecId>,
DB: Database,
JOURNAL: JournalTr<Database = DB, FinalOutput = JournalOutput>,
{
type Context = Self;

View File

@ -1,29 +1,26 @@
use super::HlEvmInner;
use crate::evm::{handler::HlHandler, spec::HlSpecId, transaction::HlTxTr};
use crate::evm::{spec::HlSpecId, transaction::HlTxTr};
use revm::{
context::{ContextSetters, JournalOutput},
context::{result::HaltReason, ContextSetters},
context_interface::{
result::{EVMError, ExecutionResult, ResultAndState},
Cfg, ContextTr, Database, JournalTr,
},
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt},
handler::{instructions::EthInstructions, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
state::EvmState,
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
};
// Type alias for HL context
pub trait HlContextTr:
ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
ContextTr<Journal: JournalTr<State = EvmState>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
{
}
impl<T> HlContextTr for T where
T: ContextTr<
Journal: JournalTr<FinalOutput = JournalOutput>,
Tx: HlTxTr,
Cfg: Cfg<Spec = HlSpecId>,
>
T: ContextTr<Journal: JournalTr<State = EvmState>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
{
}
@ -36,23 +33,32 @@ where
CTX: HlContextTr + ContextSetters,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type Output = Result<ResultAndState, HlError<CTX>>;
type ExecutionResult = ExecutionResult<HaltReason>;
type State = EvmState;
type Error = HlError<CTX>;
type Tx = <CTX as ContextTr>::Tx;
type Block = <CTX as ContextTr>::Block;
fn set_tx(&mut self, tx: Self::Tx) {
self.0.ctx.set_tx(tx);
#[inline]
fn transact_one(&mut self, tx: Self::Tx) -> Result<Self::ExecutionResult, Self::Error> {
self.0.transact_one(tx)
}
#[inline]
fn finalize(&mut self) -> Self::State {
self.0.finalize()
}
#[inline]
fn set_block(&mut self, block: Self::Block) {
self.0.ctx.set_block(block);
self.0.set_block(block);
}
fn replay(&mut self) -> Self::Output {
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
h.run(self)
#[inline]
fn replay(&mut self) -> Result<ResultAndState<HaltReason>, Self::Error> {
self.0.replay()
}
}
@ -62,13 +68,8 @@ where
CTX: HlContextTr<Db: DatabaseCommit> + ContextSetters,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type CommitOutput = Result<ExecutionResult, HlError<CTX>>;
fn replay_commit(&mut self) -> Self::CommitOutput {
self.replay().map(|r| {
self.ctx().db().commit(r.state);
r.result
})
fn commit(&mut self, state: Self::State) {
self.0.commit(state);
}
}
@ -82,12 +83,11 @@ where
type Inspector = INSP;
fn set_inspector(&mut self, inspector: Self::Inspector) {
self.0.inspector = inspector;
self.0.set_inspector(inspector);
}
fn inspect_replay(&mut self) -> Self::Output {
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
h.inspect_run(self)
fn inspect_one_tx(&mut self, tx: Self::Tx) -> Result<Self::ExecutionResult, Self::Error> {
self.0.inspect_one_tx(tx)
}
}

View File

@ -1,12 +1,13 @@
use revm::{
context::{ContextSetters, Evm as EvmCtx},
context::{ContextSetters, Evm, FrameStack},
context_interface::ContextTr,
handler::{
evm::{ContextDbError, FrameInitResult},
instructions::{EthInstructions, InstructionProvider},
EthPrecompiles, EvmTr, PrecompileProvider,
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, PrecompileProvider,
},
inspector::{InspectorEvmTr, JournalExt},
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterAction, InterpreterTypes},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
Inspector,
};
@ -14,19 +15,23 @@ pub mod builder;
pub mod ctx;
mod exec;
pub struct HlEvmInner<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = EthPrecompiles>(
pub EvmCtx<CTX, INSP, I, P>,
);
pub struct HlEvmInner<
CTX: ContextTr,
INSP,
I = EthInstructions<EthInterpreter, CTX>,
P = EthPrecompiles,
>(pub Evm<CTX, INSP, I, P, EthFrame<EthInterpreter>>);
impl<CTX: ContextTr, INSP>
HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>
{
pub fn new(ctx: CTX, inspector: INSP) -> Self {
Self(EvmCtx {
Self(Evm {
ctx,
inspector,
instruction: EthInstructions::new_mainnet(),
precompiles: EthPrecompiles::default(),
frame_stack: FrameStack::new(),
})
}
@ -42,12 +47,9 @@ impl<CTX: ContextTr, INSP>
impl<CTX, INSP, I, P> InspectorEvmTr for HlEvmInner<CTX, INSP, I, P>
where
CTX: ContextTr<Journal: JournalExt> + ContextSetters,
I: InstructionProvider<
Context = CTX,
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
>,
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
INSP: Inspector<CTX, I::InterpreterTypes>,
P: PrecompileProvider<CTX>,
P: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type Inspector = INSP;
@ -59,41 +61,29 @@ where
(&mut self.0.ctx, &mut self.0.inspector)
}
fn run_inspect_interpreter(
fn ctx_inspector_frame(
&mut self,
interpreter: &mut Interpreter<
<Self::Instructions as InstructionProvider>::InterpreterTypes,
>,
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
{
self.0.run_inspect_interpreter(interpreter)
) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame) {
(&mut self.0.ctx, &mut self.0.inspector, self.0.frame_stack.get())
}
fn ctx_inspector_frame_instructions(
&mut self,
) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame, &mut Self::Instructions) {
(&mut self.0.ctx, &mut self.0.inspector, self.0.frame_stack.get(), &mut self.0.instruction)
}
}
impl<CTX, INSP, I, P> EvmTr for HlEvmInner<CTX, INSP, I, P>
where
CTX: ContextTr,
I: InstructionProvider<
Context = CTX,
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
>,
P: PrecompileProvider<CTX>,
I: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
P: PrecompileProvider<CTX, Output = InterpreterResult>,
{
type Context = CTX;
type Instructions = I;
type Precompiles = P;
fn run_interpreter(
&mut self,
interpreter: &mut Interpreter<
<Self::Instructions as InstructionProvider>::InterpreterTypes,
>,
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
{
let context = &mut self.0.ctx;
let instructions = &mut self.0.instruction;
interpreter.run_plain(instructions.instruction_table(), context)
}
type Frame = EthFrame<EthInterpreter>;
fn ctx(&mut self) -> &mut Self::Context {
&mut self.0.ctx
@ -110,6 +100,30 @@ where
fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
(&mut self.0.ctx, &mut self.0.precompiles)
}
fn frame_stack(&mut self) -> &mut FrameStack<Self::Frame> {
&mut self.0.frame_stack
}
fn frame_init(
&mut self,
frame_input: <Self::Frame as FrameTr>::FrameInit,
) -> Result<FrameInitResult<'_, Self::Frame>, ContextDbError<Self::Context>> {
self.0.frame_init(frame_input)
}
fn frame_run(
&mut self,
) -> Result<FrameInitOrResult<Self::Frame>, ContextDbError<Self::Context>> {
self.0.frame_run()
}
fn frame_return_result(
&mut self,
result: <Self::Frame as FrameTr>::FrameResult,
) -> Result<Option<<Self::Frame as FrameTr>::FrameResult>, ContextDbError<Self::Context>> {
self.0.frame_return_result(result)
}
}
// #[cfg(test)]