From 3379b43e3208133b7b93e0dbb46e4ebe6ec3f452 Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 12:56:55 +0200 Subject: [PATCH 01/14] chore: Make inspector use generics, rm associated types --- crates/inspector/src/eip3155.rs | 5 +- crates/inspector/src/inspector.rs | 82 ++++++++----------------------- crates/inspector/src/noop.rs | 9 +--- 3 files changed, 24 insertions(+), 72 deletions(-) diff --git a/crates/inspector/src/eip3155.rs b/crates/inspector/src/eip3155.rs index aa19fac330..53a3b7d05b 100644 --- a/crates/inspector/src/eip3155.rs +++ b/crates/inspector/src/eip3155.rs @@ -197,14 +197,11 @@ impl CloneStack for Stack { } } -impl Inspector for TracerEip3155 +impl Inspector for TracerEip3155 where CTX: CfgGetter + TransactionGetter + JournalStateGetter, INTR: InterpreterTypes, { - type Context = CTX; - type InterpreterTypes = INTR; - fn initialize_interp(&mut self, interp: &mut Interpreter, _: &mut CTX) { self.gas_inspector.initialize_interp(interp.control.gas()); } diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index a1d41a5a19..da7f6e2f8b 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -36,20 +36,13 @@ use std::{rc::Rc, vec::Vec}; /// EVM [Interpreter] callbacks. #[auto_impl(&mut, Box)] -pub trait Inspector { - type Context; - type InterpreterTypes: InterpreterTypes; - +pub trait Inspector { /// Called before the interpreter is initialized. /// /// If `interp.instruction_result` is set to anything other than [revm::interpreter::InstructionResult::Continue] then the execution of the interpreter /// is skipped. #[inline] - fn initialize_interp( - &mut self, - interp: &mut Interpreter, - context: &mut Self::Context, - ) { + fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut CTX) { let _ = interp; let _ = context; } @@ -63,11 +56,7 @@ pub trait Inspector { /// /// To get the current opcode, use `interp.current_opcode()`. #[inline] - fn step( - &mut self, - interp: &mut Interpreter, - context: &mut Self::Context, - ) { + fn step(&mut self, interp: &mut Interpreter, context: &mut CTX) { let _ = interp; let _ = context; } @@ -77,23 +66,14 @@ pub trait Inspector { /// Setting `interp.instruction_result` to anything other than [revm::interpreter::InstructionResult::Continue] alters the execution /// of the interpreter. #[inline] - fn step_end( - &mut self, - interp: &mut Interpreter, - context: &mut Self::Context, - ) { + fn step_end(&mut self, interp: &mut Interpreter, context: &mut CTX) { let _ = interp; let _ = context; } /// Called when a log is emitted. #[inline] - fn log( - &mut self, - interp: &mut Interpreter, - context: &mut Self::Context, - log: &Log, - ) { + fn log(&mut self, interp: &mut Interpreter, context: &mut CTX, log: &Log) { let _ = interp; let _ = context; let _ = log; @@ -103,11 +83,7 @@ pub trait Inspector { /// /// InstructionResulting anything other than [revm::interpreter::InstructionResult::Continue] overrides the result of the call. #[inline] - fn call( - &mut self, - context: &mut Self::Context, - inputs: &mut CallInputs, - ) -> Option { + fn call(&mut self, context: &mut CTX, inputs: &mut CallInputs) -> Option { let _ = context; let _ = inputs; None @@ -119,12 +95,7 @@ pub trait Inspector { /// /// This allows the inspector to modify the given `result` before returning it. #[inline] - fn call_end( - &mut self, - context: &mut Self::Context, - inputs: &CallInputs, - outcome: &mut CallOutcome, - ) { + fn call_end(&mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome) { let _ = context; let _ = inputs; let _ = outcome; @@ -136,11 +107,7 @@ pub trait Inspector { /// /// If this returns `None` then the creation proceeds as normal. #[inline] - fn create( - &mut self, - context: &mut Self::Context, - inputs: &mut CreateInputs, - ) -> Option { + fn create(&mut self, context: &mut CTX, inputs: &mut CreateInputs) -> Option { let _ = context; let _ = inputs; None @@ -153,7 +120,7 @@ pub trait Inspector { #[inline] fn create_end( &mut self, - context: &mut Self::Context, + context: &mut CTX, inputs: &CreateInputs, outcome: &mut CreateOutcome, ) { @@ -167,7 +134,7 @@ pub trait Inspector { /// This can happen from create TX or from EOFCREATE opcode. fn eofcreate( &mut self, - context: &mut Self::Context, + context: &mut CTX, inputs: &mut EOFCreateInputs, ) -> Option { let _ = context; @@ -178,7 +145,7 @@ pub trait Inspector { /// Called when eof creating has ended. fn eofcreate_end( &mut self, - context: &mut Self::Context, + context: &mut CTX, inputs: &EOFCreateInputs, outcome: &mut CreateOutcome, ) { @@ -197,10 +164,9 @@ pub trait Inspector { } /// Provides access to an `Inspector` instance. -pub trait GetInspector { - type Inspector: Inspector; +pub trait GetInspector { /// Returns the associated `Inspector`. - fn get_inspector(&mut self) -> &mut Self::Inspector; + fn get_inspector(&mut self) -> &mut impl Inspector; } pub trait InspectorCtx { @@ -215,10 +181,9 @@ pub trait InspectorCtx { fn inspector_log(&mut self, interp: &mut Interpreter, log: &Log); } -impl GetInspector for INSP { - type Inspector = INSP; +impl> GetInspector for INSP { #[inline] - fn get_inspector(&mut self) -> &mut Self::Inspector { + fn get_inspector(&mut self) -> &mut impl Inspector { self } } @@ -259,7 +224,7 @@ impl< } impl< - INSP: GetInspector, + INSP: GetInspector, EthInterpreter>, BLOCK: Block, TX: Transaction, CFG: Cfg, @@ -342,12 +307,7 @@ impl< impl, CHAIN> InspectorCtx for InspectorContext where - INSP: GetInspector< - Inspector: Inspector< - Context = Context, - InterpreterTypes = EthInterpreter, - >, - >, + INSP: GetInspector, EthInterpreter>, { type IT = EthInterpreter<()>; @@ -735,7 +695,7 @@ where type FrameResult = FrameResult; fn init_first( - context: &mut Self::Context, + context: &mut CTX, mut frame_input: Self::FrameInit, ) -> Result, Self::Error> { if let Some(output) = context.frame_start(&mut frame_input) { @@ -759,7 +719,7 @@ where fn init( &self, - context: &mut Self::Context, + context: &mut CTX, mut frame_input: Self::FrameInit, ) -> Result, Self::Error> { if let Some(output) = context.frame_start(&mut frame_input) { @@ -781,14 +741,14 @@ where fn run( &mut self, - context: &mut Self::Context, + context: &mut CTX, ) -> Result, Self::Error> { self.eth_frame.run(context) } fn return_result( &mut self, - context: &mut Self::Context, + context: &mut CTX, mut result: Self::FrameResult, ) -> Result<(), Self::Error> { context.frame_end(&mut result); diff --git a/crates/inspector/src/noop.rs b/crates/inspector/src/noop.rs index f79cff76a1..8119182bda 100644 --- a/crates/inspector/src/noop.rs +++ b/crates/inspector/src/noop.rs @@ -4,11 +4,6 @@ use crate::Inspector; /// Dummy [Inspector], helpful as standalone replacement. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct NoOpInspector { - _phantom: core::marker::PhantomData<(CTX, INTR)>, -} +pub struct NoOpInspector {} -impl Inspector for NoOpInspector { - type Context = CTX; - type InterpreterTypes = INTR; -} +impl Inspector for NoOpInspector {} From e95e05e28d8d041c68d9ba9e9215e0c541e58c2d Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 13:05:45 +0200 Subject: [PATCH 02/14] prev context --- crates/inspector/src/lib.rs | 2 ++ crates/inspector/src/prev_inspector.rs | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 crates/inspector/src/prev_inspector.rs diff --git a/crates/inspector/src/lib.rs b/crates/inspector/src/lib.rs index 66e6f7084a..8143932549 100644 --- a/crates/inspector/src/lib.rs +++ b/crates/inspector/src/lib.rs @@ -10,8 +10,10 @@ mod eip3155; mod gas; mod inspector; mod noop; +mod prev_inspector; pub use inspector::*; +pub use prev_inspector::PrevContext; /// [Inspector] implementations. pub mod inspectors { diff --git a/crates/inspector/src/prev_inspector.rs b/crates/inspector/src/prev_inspector.rs new file mode 100644 index 0000000000..19c6c0fa4b --- /dev/null +++ b/crates/inspector/src/prev_inspector.rs @@ -0,0 +1,9 @@ +use crate::Inspector; +use revm::{ + context::{BlockEnv, CfgEnv, TxEnv}, + interpreter::interpreter::EthInterpreter, + Context, +}; + +/// Helper type for easier integration with previous version of inspector. +pub type PrevContext = Context; From f84bfb58e58fef7b580d3dc77465995e5e3c88bc Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 13:19:53 +0200 Subject: [PATCH 03/14] default impl for ImputsImpl --- crates/interpreter/src/interpreter/input.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/interpreter/src/interpreter/input.rs b/crates/interpreter/src/interpreter/input.rs index d3f2e21e56..5b148c6497 100644 --- a/crates/interpreter/src/interpreter/input.rs +++ b/crates/interpreter/src/interpreter/input.rs @@ -4,6 +4,7 @@ use primitives::{Address, Bytes, U256}; use serde::{Deserialize, Serialize}; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct InputsImpl { pub target_address: Address, pub caller_address: Address, From ab62fe1aced10aa4a4c898220eadceb16fe9d75b Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 16:54:12 +0200 Subject: [PATCH 04/14] ContextWire and Wiring --- crates/context/src/context_wire.rs | 21 +++++++++++++++++++++ crates/context/src/lib.rs | 2 ++ crates/inspector/src/prev_inspector.rs | 2 -- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 crates/context/src/context_wire.rs diff --git a/crates/context/src/context_wire.rs b/crates/context/src/context_wire.rs new file mode 100644 index 0000000000..2be292ce7d --- /dev/null +++ b/crates/context/src/context_wire.rs @@ -0,0 +1,21 @@ +use crate::Context; +use context_interface::{Block, Cfg, Database, Journal, Transaction}; + +/// Helper trait for wiring up the context with generic Database. +pub trait ContextWiring { + type Block: Block; + type Tx: Transaction; + type Cfg: Cfg; + type Journal: Journal; + type Chain; +} + +/// Type that bind [`Context`] with the [`ContextWiring`]. +pub type ContextWire = Context< + >::Block, + >::Tx, + >::Cfg, + DB, + >::Journal, + >::Chain, +>; diff --git a/crates/context/src/lib.rs b/crates/context/src/lib.rs index 44a5b394c0..3fa8a1c204 100644 --- a/crates/context/src/lib.rs +++ b/crates/context/src/lib.rs @@ -8,11 +8,13 @@ extern crate alloc as std; pub mod block; pub mod cfg; pub mod context; +pub mod context_wire; pub mod journaled_state; pub mod tx; pub use block::BlockEnv; pub use cfg::{Cfg, CfgEnv}; pub use context::*; +pub use context_wire::{ContextWire, ContextWiring}; pub use journaled_state::*; pub use tx::TxEnv; diff --git a/crates/inspector/src/prev_inspector.rs b/crates/inspector/src/prev_inspector.rs index 19c6c0fa4b..10dec4c4d3 100644 --- a/crates/inspector/src/prev_inspector.rs +++ b/crates/inspector/src/prev_inspector.rs @@ -1,7 +1,5 @@ -use crate::Inspector; use revm::{ context::{BlockEnv, CfgEnv, TxEnv}, - interpreter::interpreter::EthInterpreter, Context, }; From 67219443f5641a3bc1d7228cc72b7f7794bb1b44 Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 17:52:43 +0200 Subject: [PATCH 05/14] rename and few cleanup --- .../context/interface/src/journaled_state.rs | 22 +++++++++++----- crates/context/interface/src/lib.rs | 2 +- crates/context/src/context.rs | 12 ++++++--- crates/context/src/context_wire.rs | 21 --------------- crates/context/src/default.rs | 3 --- crates/context/src/lib.rs | 2 -- crates/handler/src/execution.rs | 16 ++++++------ crates/handler/src/frame.rs | 14 +++++----- crates/handler/src/lib.rs | 8 +++--- crates/handler/src/post_execution.rs | 12 ++++----- crates/handler/src/pre_execution.rs | 18 ++++++------- crates/handler/src/validation.rs | 16 ++++++------ crates/inspector/src/eip3155.rs | 4 +-- crates/inspector/src/inspector.rs | 26 ++++++++++++++----- crates/inspector/src/lib.rs | 2 -- crates/inspector/src/prev_inspector.rs | 7 ----- crates/revm/src/evm.rs | 22 ++++++++-------- 17 files changed, 100 insertions(+), 107 deletions(-) delete mode 100644 crates/context/src/context_wire.rs delete mode 100644 crates/context/src/default.rs delete mode 100644 crates/inspector/src/prev_inspector.rs diff --git a/crates/context/interface/src/journaled_state.rs b/crates/context/interface/src/journaled_state.rs index b6cec51aac..b3bffa0288 100644 --- a/crates/context/interface/src/journaled_state.rs +++ b/crates/context/interface/src/journaled_state.rs @@ -284,28 +284,38 @@ impl Eip7702CodeLoad { } } -/// Helper that extracts database error from [`JournalStateGetter`]. -pub type JournalStateGetterDBError = - <<::Journal as Journal>::Database as Database>::Error; +/// Helper that extracts database error from [`JournalGetter`]. +pub type JournalDBError = + <<::Journal as Journal>::Database as Database>::Error; -pub trait JournalStateGetter: DatabaseGetter { +pub trait JournalGetter: DatabaseGetter { type Journal: Journal::Database>; fn journal(&mut self) -> &mut Self::Journal; + + fn journal_ref(&self) -> &Self::Journal; } -impl JournalStateGetter for &mut T { +impl JournalGetter for &mut T { type Journal = T::Journal; fn journal(&mut self) -> &mut Self::Journal { T::journal(*self) } + + fn journal_ref(&self) -> &Self::Journal { + T::journal_ref(*self) + } } -impl JournalStateGetter for Box { +impl JournalGetter for Box { type Journal = T::Journal; fn journal(&mut self) -> &mut Self::Journal { T::journal(self.as_mut()) } + + fn journal_ref(&self) -> &Self::Journal { + T::journal_ref(self.as_ref()) + } } diff --git a/crates/context/interface/src/lib.rs b/crates/context/interface/src/lib.rs index 7272d38768..85d6dc511e 100644 --- a/crates/context/interface/src/lib.rs +++ b/crates/context/interface/src/lib.rs @@ -17,5 +17,5 @@ pub use block::{Block, BlockGetter}; pub use cfg::{Cfg, CfgGetter, CreateScheme, TransactTo}; pub use database_interface::{DBErrorMarker, Database, DatabaseGetter}; pub use errors::ErrorGetter; -pub use journaled_state::{Journal, JournalStateGetter, JournalStateGetterDBError}; +pub use journaled_state::{Journal, JournalGetter, JournalDBError}; pub use transaction::{Transaction, TransactionGetter, TransactionType}; diff --git a/crates/context/src/context.rs b/crates/context/src/context.rs index 7a356695bb..05327c73bd 100644 --- a/crates/context/src/context.rs +++ b/crates/context/src/context.rs @@ -5,7 +5,7 @@ use context_interface::{ journaled_state::{AccountLoad, Eip7702CodeLoad}, result::EVMError, transaction::TransactionSetter, - Block, BlockGetter, Cfg, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalStateGetter, + Block, BlockGetter, Cfg, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalGetter, Transaction, TransactionGetter, }; use database_interface::{Database, EmptyDB}; @@ -24,10 +24,10 @@ pub struct Context< JOURNAL: Journal = JournaledState, CHAIN = (), > { - /// Transaction information. - pub tx: TX, /// Block information. pub block: BLOCK, + /// Transaction information. + pub tx: TX, /// Configurations. pub cfg: CFG, /// EVM State with journaling support and database. @@ -498,7 +498,7 @@ impl, CHAIN> } } -impl JournalStateGetter +impl JournalGetter for Context where DB: Database, @@ -509,6 +509,10 @@ where fn journal(&mut self) -> &mut Self::Journal { &mut self.journaled_state } + + fn journal_ref(&self) -> &Self::Journal { + &self.journaled_state + } } impl DatabaseGetter diff --git a/crates/context/src/context_wire.rs b/crates/context/src/context_wire.rs deleted file mode 100644 index 2be292ce7d..0000000000 --- a/crates/context/src/context_wire.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::Context; -use context_interface::{Block, Cfg, Database, Journal, Transaction}; - -/// Helper trait for wiring up the context with generic Database. -pub trait ContextWiring { - type Block: Block; - type Tx: Transaction; - type Cfg: Cfg; - type Journal: Journal; - type Chain; -} - -/// Type that bind [`Context`] with the [`ContextWiring`]. -pub type ContextWire = Context< - >::Block, - >::Tx, - >::Cfg, - DB, - >::Journal, - >::Chain, ->; diff --git a/crates/context/src/default.rs b/crates/context/src/default.rs deleted file mode 100644 index 79e4dd0892..0000000000 --- a/crates/context/src/default.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod block; -pub mod cfg; -pub mod tx; diff --git a/crates/context/src/lib.rs b/crates/context/src/lib.rs index 3fa8a1c204..44a5b394c0 100644 --- a/crates/context/src/lib.rs +++ b/crates/context/src/lib.rs @@ -8,13 +8,11 @@ extern crate alloc as std; pub mod block; pub mod cfg; pub mod context; -pub mod context_wire; pub mod journaled_state; pub mod tx; pub use block::BlockEnv; pub use cfg::{Cfg, CfgEnv}; pub use context::*; -pub use context_wire::{ContextWire, ContextWiring}; pub use journaled_state::*; pub use tx::TxEnv; diff --git a/crates/handler/src/execution.rs b/crates/handler/src/execution.rs index 0238feabed..ff8bc50848 100644 --- a/crates/handler/src/execution.rs +++ b/crates/handler/src/execution.rs @@ -1,8 +1,8 @@ use super::{frame_data::FrameResult, EthFrame, EthPrecompileProvider}; use bytecode::EOF_MAGIC_BYTES; use context_interface::{ - result::InvalidTransaction, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalStateGetter, - JournalStateGetterDBError, Transaction, TransactionGetter, + result::InvalidTransaction, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, + JournalDBError, Transaction, TransactionGetter, }; use handler_interface::{util::FrameOrFrameResult, ExecutionHandler, Frame as FrameTrait}; use interpreter::{ @@ -125,7 +125,7 @@ impl EthExecution { } pub trait EthExecutionContext: - TransactionGetter + ErrorGetter + BlockGetter + JournalStateGetter + CfgGetter + TransactionGetter + ErrorGetter + BlockGetter + JournalGetter + CfgGetter { } @@ -134,20 +134,20 @@ impl< T: TransactionGetter + ErrorGetter + BlockGetter - + JournalStateGetter + + JournalGetter + CfgGetter, > EthExecutionContext for T { } -pub trait EthExecutionError: - From + From> +pub trait EthExecutionError: + From + From> { } impl< - CTX: JournalStateGetter, - T: From + From>, + CTX: JournalGetter, + T: From + From>, > EthExecutionError for T { } diff --git a/crates/handler/src/frame.rs b/crates/handler/src/frame.rs index 6bbac9354d..2f1a93e835 100644 --- a/crates/handler/src/frame.rs +++ b/crates/handler/src/frame.rs @@ -2,7 +2,7 @@ use super::frame_data::*; use bytecode::{Eof, EOF_MAGIC_BYTES}; use context_interface::{ journaled_state::{Journal, JournalCheckpoint}, - BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalStateGetter, JournalStateGetterDBError, + BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, Transaction, TransactionGetter, }; use core::{cell::RefCell, cmp::min}; @@ -45,7 +45,7 @@ pub struct EthFrame impl EthFrame where - CTX: JournalStateGetter, + CTX: JournalGetter, IW: InterpreterTypes, { pub fn new( @@ -792,7 +792,7 @@ pub fn return_eofcreate( } pub trait EthFrameContext: - TransactionGetter + Host + ErrorGetter + BlockGetter + JournalStateGetter + CfgGetter + TransactionGetter + Host + ErrorGetter + BlockGetter + JournalGetter + CfgGetter { } @@ -801,19 +801,19 @@ impl< CTX: TransactionGetter + ErrorGetter + BlockGetter - + JournalStateGetter + + JournalGetter + CfgGetter + Host, > EthFrameContext for CTX { } -pub trait EthFrameError: - From> + From +pub trait EthFrameError: + From> + From { } -impl> + From> +impl> + From> EthFrameError for T { } diff --git a/crates/handler/src/lib.rs b/crates/handler/src/lib.rs index 2435b47861..c8d8e491e3 100644 --- a/crates/handler/src/lib.rs +++ b/crates/handler/src/lib.rs @@ -42,7 +42,7 @@ use context_interface::{ result::{HaltReason, InvalidHeader, InvalidTransaction}, }; use context_interface::{ - BlockGetter, CfgGetter, ErrorGetter, JournalStateGetter, JournalStateGetterDBError, + BlockGetter, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, TransactionGetter, }; use handler_interface::{ @@ -102,14 +102,14 @@ impl Handler where CTX: TransactionGetter + BlockGetter - + JournalStateGetter + + JournalGetter + CfgGetter + ErrorGetter - + JournalStateGetter)>> + + JournalGetter)>> + Host, ERROR: From + From - + From> + + From> + From, VAL: ValidationHandler, PREEXEC: PreExecutionHandler, diff --git a/crates/handler/src/post_execution.rs b/crates/handler/src/post_execution.rs index 69dabe9e83..b8952f6609 100644 --- a/crates/handler/src/post_execution.rs +++ b/crates/handler/src/post_execution.rs @@ -1,7 +1,7 @@ use context_interface::{ journaled_state::Journal, result::{ExecutionResult, HaltReasonTrait, ResultAndState}, - Block, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalStateGetter, JournalStateGetterDBError, + Block, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, Transaction, TransactionGetter, }; use handler_interface::PostExecutionHandler; @@ -170,7 +170,7 @@ pub trait EthPostExecutionContext: TransactionGetter + ErrorGetter + BlockGetter - + JournalStateGetter)>> + + JournalGetter)>> + CfgGetter { } @@ -180,18 +180,18 @@ impl< CTX: TransactionGetter + ErrorGetter + BlockGetter - + JournalStateGetter)>> + + JournalGetter)>> + CfgGetter, > EthPostExecutionContext for CTX { } -pub trait EthPostExecutionError: - From> +pub trait EthPostExecutionError: + From> { } -impl>> +impl>> EthPostExecutionError for ERROR { } diff --git a/crates/handler/src/pre_execution.rs b/crates/handler/src/pre_execution.rs index daa22a2529..43ca73b2fb 100644 --- a/crates/handler/src/pre_execution.rs +++ b/crates/handler/src/pre_execution.rs @@ -9,7 +9,7 @@ use context_interface::{ transaction::{ eip7702::Authorization, AccessListTrait, Eip4844Tx, Eip7702Tx, Transaction, TransactionType, }, - Block, BlockGetter, Cfg, CfgGetter, JournalStateGetter, JournalStateGetterDBError, + Block, BlockGetter, Cfg, CfgGetter, JournalGetter, JournalDBError, TransactionGetter, }; use handler_interface::PreExecutionHandler; @@ -121,8 +121,8 @@ where /// Apply EIP-7702 auth list and return number gas refund on already created accounts. #[inline] pub fn apply_eip7702_auth_list< - CTX: TransactionGetter + JournalStateGetter + CfgGetter, - ERROR: From + From>, + CTX: TransactionGetter + JournalGetter + CfgGetter, + ERROR: From + From>, >( context: &mut CTX, ) -> Result { @@ -203,23 +203,23 @@ pub fn apply_eip7702_auth_list< } pub trait EthPreExecutionContext: - TransactionGetter + BlockGetter + JournalStateGetter + CfgGetter + TransactionGetter + BlockGetter + JournalGetter + CfgGetter { } -impl EthPreExecutionContext +impl EthPreExecutionContext for CTX { } -pub trait EthPreExecutionError: - From + From> +pub trait EthPreExecutionError: + From + From> { } impl< - CTX: JournalStateGetter, - T: From + From>, + CTX: JournalGetter, + T: From + From>, > EthPreExecutionError for T { } diff --git a/crates/handler/src/validation.rs b/crates/handler/src/validation.rs index 0e24809e4b..e9f8ebc563 100644 --- a/crates/handler/src/validation.rs +++ b/crates/handler/src/validation.rs @@ -5,7 +5,7 @@ use context_interface::{ eip7702::Authorization, Eip1559CommonTxFields, Eip2930Tx, Eip4844Tx, Eip7702Tx, LegacyTx, Transaction, TransactionType, }, - Block, BlockGetter, Cfg, CfgGetter, JournalStateGetter, JournalStateGetterDBError, + Block, BlockGetter, Cfg, CfgGetter, JournalGetter, JournalDBError, TransactionGetter, }; use core::cmp::{self, Ordering}; @@ -43,7 +43,7 @@ impl EthValidation { impl ValidationHandler for EthValidation where CTX: EthValidationContext, - ERROR: From + From + From>, + ERROR: From + From + From>, { type Context = CTX; type Error = ERROR; @@ -385,24 +385,24 @@ where /// Helper trait that summarizes ValidationHandler requirements from Context. pub trait EthValidationContext: - TransactionGetter + BlockGetter + JournalStateGetter + CfgGetter + TransactionGetter + BlockGetter + JournalGetter + CfgGetter { } -impl EthValidationContext +impl EthValidationContext for T { } /// Helper trait that summarizes all possible requirements by EthValidation. -pub trait EthValidationError: - From + From + From> +pub trait EthValidationError: + From + From + From> { } impl< - CTX: JournalStateGetter, - T: From + From + From>, + CTX: JournalGetter, + T: From + From + From>, > EthValidationError for T { } diff --git a/crates/inspector/src/eip3155.rs b/crates/inspector/src/eip3155.rs index 53a3b7d05b..2c6898e9e9 100644 --- a/crates/inspector/src/eip3155.rs +++ b/crates/inspector/src/eip3155.rs @@ -3,7 +3,7 @@ use derive_where::derive_where; use revm::{ bytecode::opcode::OpCode, context::Cfg, - context_interface::{CfgGetter, Journal, JournalStateGetter, Transaction, TransactionGetter}, + context_interface::{CfgGetter, Journal, JournalGetter, Transaction, TransactionGetter}, interpreter::{ interpreter_types::{Jumps, LoopControl, MemoryTrait, StackTrait}, CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult, @@ -199,7 +199,7 @@ impl CloneStack for Stack { impl Inspector for TracerEip3155 where - CTX: CfgGetter + TransactionGetter + JournalStateGetter, + CTX: CfgGetter + TransactionGetter + JournalGetter, INTR: InterpreterTypes, { fn initialize_interp(&mut self, interp: &mut Interpreter, _: &mut CTX) { diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index da7f6e2f8b..60423e6566 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -9,8 +9,8 @@ use revm::{ journaled_state::{AccountLoad, Eip7702CodeLoad}, result::EVMError, transaction::TransactionSetter, - Block, BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalStateGetter, - JournalStateGetterDBError, Transaction, TransactionGetter, + Block, BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalDBError, + JournalGetter, Transaction, TransactionGetter, }, database_interface::{Database, EmptyDB}, handler::{ @@ -399,7 +399,7 @@ impl, C } } -impl, CHAIN> JournalStateGetter +impl, CHAIN> JournalGetter for InspectorContext { type Journal = JOURNAL; @@ -407,6 +407,10 @@ impl, CHAIN> fn journal(&mut self) -> &mut Self::Journal { &mut self.inner.journaled_state } + + fn journal_ref(&self) -> &Self::Journal { + &self.inner.journaled_state + } } impl, CHAIN> DatabaseGetter @@ -482,6 +486,16 @@ impl< } } +impl + JournalExt, CHAIN> + JournalExtGetter for Context +{ + type JournalExt = JOURNAL; + + fn journal_ext(&self) -> &Self::JournalExt { + &self.journaled_state + } +} + #[derive(Clone)] pub struct InspectorInstruction { pub instruction: fn(&mut Interpreter, &mut HOST), @@ -561,7 +575,7 @@ pub trait JournalExtGetter { impl InstructionProvider for InspectorInstructionProvider where WIRE: InterpreterTypes, - HOST: Host + JournalExtGetter + JournalStateGetter + InspectorCtx, + HOST: Host + JournalExtGetter + JournalGetter + InspectorCtx, { type WIRE = WIRE; type Host = HOST; @@ -681,12 +695,12 @@ where CTX: TransactionGetter + ErrorGetter + BlockGetter - + JournalStateGetter + + JournalGetter + CfgGetter + JournalExtGetter + Host + InspectorCtx, - ERROR: From> + From, + ERROR: From> + From, PRECOMPILE: PrecompileProvider, { type Context = CTX; diff --git a/crates/inspector/src/lib.rs b/crates/inspector/src/lib.rs index 8143932549..66e6f7084a 100644 --- a/crates/inspector/src/lib.rs +++ b/crates/inspector/src/lib.rs @@ -10,10 +10,8 @@ mod eip3155; mod gas; mod inspector; mod noop; -mod prev_inspector; pub use inspector::*; -pub use prev_inspector::PrevContext; /// [Inspector] implementations. pub mod inspectors { diff --git a/crates/inspector/src/prev_inspector.rs b/crates/inspector/src/prev_inspector.rs deleted file mode 100644 index 10dec4c4d3..0000000000 --- a/crates/inspector/src/prev_inspector.rs +++ /dev/null @@ -1,7 +0,0 @@ -use revm::{ - context::{BlockEnv, CfgEnv, TxEnv}, - Context, -}; - -/// Helper type for easier integration with previous version of inspector. -pub type PrevContext = Context; diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index ab51a204b6..cedeefe4ec 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -8,8 +8,8 @@ use context_interface::{ ResultAndState, }, transaction::TransactionSetter, - BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, JournalStateGetter, - JournalStateGetterDBError, Transaction, TransactionGetter, + BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, JournalGetter, + JournalDBError, Transaction, TransactionGetter, }; use database_interface::{Database, DatabaseCommit}; use handler::{EthHandler, FrameResult}; @@ -45,11 +45,11 @@ impl EvmCommit where CTX: TransactionSetter + BlockSetter - + JournalStateGetter + + JournalGetter + CfgGetter + DatabaseGetter + ErrorGetter - + JournalStateGetter< + + JournalGetter< Journal: Journal< FinalOutput = (EvmState, Vec), Database = ::Database, @@ -57,7 +57,7 @@ where > + Host, ERROR: From + From - + From> + + From> + From, VAL: ValidationHandler, PREEXEC: PreExecutionHandler, @@ -92,11 +92,11 @@ impl EvmExec where CTX: TransactionSetter + BlockSetter - + JournalStateGetter + + JournalGetter + CfgGetter + DatabaseGetter + ErrorGetter - + JournalStateGetter< + + JournalGetter< Journal: Journal< FinalOutput = (EvmState, Vec), Database = ::Database, @@ -104,7 +104,7 @@ where > + Host, ERROR: From + From - + From> + + From> + From, VAL: ValidationHandler, PREEXEC: PreExecutionHandler, @@ -150,11 +150,11 @@ impl where CTX: TransactionGetter + BlockGetter - + JournalStateGetter + + JournalGetter + CfgGetter + DatabaseGetter + ErrorGetter - + JournalStateGetter< + + JournalGetter< Journal: Journal< FinalOutput = (EvmState, Vec), Database = ::Database, @@ -162,7 +162,7 @@ where > + Host, ERROR: From + From - + From> + + From> + From, VAL: ValidationHandler, PREEXEC: PreExecutionHandler, From 235ad5c81516f1632ad5362c56d71527870f345f Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 20 Dec 2024 18:04:12 +0200 Subject: [PATCH 06/14] fmt/clippy --- crates/context/interface/src/lib.rs | 2 +- crates/handler/src/execution.rs | 16 +++++----------- crates/handler/src/frame.rs | 8 ++++---- crates/handler/src/lib.rs | 3 +-- crates/handler/src/post_execution.rs | 14 ++++---------- crates/handler/src/pre_execution.rs | 9 +++------ crates/handler/src/validation.rs | 8 ++------ crates/revm/src/evm.rs | 4 ++-- 8 files changed, 22 insertions(+), 42 deletions(-) diff --git a/crates/context/interface/src/lib.rs b/crates/context/interface/src/lib.rs index 85d6dc511e..8176798392 100644 --- a/crates/context/interface/src/lib.rs +++ b/crates/context/interface/src/lib.rs @@ -17,5 +17,5 @@ pub use block::{Block, BlockGetter}; pub use cfg::{Cfg, CfgGetter, CreateScheme, TransactTo}; pub use database_interface::{DBErrorMarker, Database, DatabaseGetter}; pub use errors::ErrorGetter; -pub use journaled_state::{Journal, JournalGetter, JournalDBError}; +pub use journaled_state::{Journal, JournalDBError, JournalGetter}; pub use transaction::{Transaction, TransactionGetter, TransactionType}; diff --git a/crates/handler/src/execution.rs b/crates/handler/src/execution.rs index ff8bc50848..7b8bed606b 100644 --- a/crates/handler/src/execution.rs +++ b/crates/handler/src/execution.rs @@ -1,8 +1,8 @@ use super::{frame_data::FrameResult, EthFrame, EthPrecompileProvider}; use bytecode::EOF_MAGIC_BYTES; use context_interface::{ - result::InvalidTransaction, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, - JournalDBError, Transaction, TransactionGetter, + result::InvalidTransaction, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalDBError, + JournalGetter, Transaction, TransactionGetter, }; use handler_interface::{util::FrameOrFrameResult, ExecutionHandler, Frame as FrameTrait}; use interpreter::{ @@ -131,11 +131,7 @@ pub trait EthExecutionContext: impl< ERROR, - T: TransactionGetter - + ErrorGetter - + BlockGetter - + JournalGetter - + CfgGetter, + T: TransactionGetter + ErrorGetter + BlockGetter + JournalGetter + CfgGetter, > EthExecutionContext for T { } @@ -145,10 +141,8 @@ pub trait EthExecutionError: { } -impl< - CTX: JournalGetter, - T: From + From>, - > EthExecutionError for T +impl + From>> + EthExecutionError for T { } diff --git a/crates/handler/src/frame.rs b/crates/handler/src/frame.rs index 2f1a93e835..f529e031da 100644 --- a/crates/handler/src/frame.rs +++ b/crates/handler/src/frame.rs @@ -2,8 +2,8 @@ use super::frame_data::*; use bytecode::{Eof, EOF_MAGIC_BYTES}; use context_interface::{ journaled_state::{Journal, JournalCheckpoint}, - BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, - Transaction, TransactionGetter, + BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalDBError, JournalGetter, Transaction, + TransactionGetter, }; use core::{cell::RefCell, cmp::min}; use handler_interface::{Frame, FrameOrResultGen, PrecompileProvider}; @@ -813,7 +813,7 @@ pub trait EthFrameError: { } -impl> + From> - EthFrameError for T +impl> + From> EthFrameError + for T { } diff --git a/crates/handler/src/lib.rs b/crates/handler/src/lib.rs index c8d8e491e3..c7967abcbd 100644 --- a/crates/handler/src/lib.rs +++ b/crates/handler/src/lib.rs @@ -42,8 +42,7 @@ use context_interface::{ result::{HaltReason, InvalidHeader, InvalidTransaction}, }; use context_interface::{ - BlockGetter, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, - TransactionGetter, + BlockGetter, CfgGetter, ErrorGetter, JournalDBError, JournalGetter, TransactionGetter, }; use handler_interface::{ ExecutionHandler, Handler, PostExecutionHandler, PreExecutionHandler, ValidationHandler, diff --git a/crates/handler/src/post_execution.rs b/crates/handler/src/post_execution.rs index b8952f6609..6ea5655543 100644 --- a/crates/handler/src/post_execution.rs +++ b/crates/handler/src/post_execution.rs @@ -1,8 +1,8 @@ use context_interface::{ journaled_state::Journal, result::{ExecutionResult, HaltReasonTrait, ResultAndState}, - Block, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalGetter, JournalDBError, - Transaction, TransactionGetter, + Block, BlockGetter, Cfg, CfgGetter, ErrorGetter, JournalDBError, JournalGetter, Transaction, + TransactionGetter, }; use handler_interface::PostExecutionHandler; use interpreter::SuccessOrHalt; @@ -186,12 +186,6 @@ impl< { } -pub trait EthPostExecutionError: - From> -{ -} +pub trait EthPostExecutionError: From> {} -impl>> - EthPostExecutionError for ERROR -{ -} +impl>> EthPostExecutionError for ERROR {} diff --git a/crates/handler/src/pre_execution.rs b/crates/handler/src/pre_execution.rs index 43ca73b2fb..d1361b34c8 100644 --- a/crates/handler/src/pre_execution.rs +++ b/crates/handler/src/pre_execution.rs @@ -9,8 +9,7 @@ use context_interface::{ transaction::{ eip7702::Authorization, AccessListTrait, Eip4844Tx, Eip7702Tx, Transaction, TransactionType, }, - Block, BlockGetter, Cfg, CfgGetter, JournalGetter, JournalDBError, - TransactionGetter, + Block, BlockGetter, Cfg, CfgGetter, JournalDBError, JournalGetter, TransactionGetter, }; use handler_interface::PreExecutionHandler; use primitives::{Address, BLOCKHASH_STORAGE_ADDRESS, U256}; @@ -217,9 +216,7 @@ pub trait EthPreExecutionError: { } -impl< - CTX: JournalGetter, - T: From + From>, - > EthPreExecutionError for T +impl + From>> + EthPreExecutionError for T { } diff --git a/crates/handler/src/validation.rs b/crates/handler/src/validation.rs index e9f8ebc563..581dde4b94 100644 --- a/crates/handler/src/validation.rs +++ b/crates/handler/src/validation.rs @@ -5,8 +5,7 @@ use context_interface::{ eip7702::Authorization, Eip1559CommonTxFields, Eip2930Tx, Eip4844Tx, Eip7702Tx, LegacyTx, Transaction, TransactionType, }, - Block, BlockGetter, Cfg, CfgGetter, JournalGetter, JournalDBError, - TransactionGetter, + Block, BlockGetter, Cfg, CfgGetter, JournalDBError, JournalGetter, TransactionGetter, }; use core::cmp::{self, Ordering}; use handler_interface::ValidationHandler; @@ -389,10 +388,7 @@ pub trait EthValidationContext: { } -impl EthValidationContext - for T -{ -} +impl EthValidationContext for T {} /// Helper trait that summarizes all possible requirements by EthValidation. pub trait EthValidationError: diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index cedeefe4ec..2f6a2e836f 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -8,8 +8,8 @@ use context_interface::{ ResultAndState, }, transaction::TransactionSetter, - BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, JournalGetter, - JournalDBError, Transaction, TransactionGetter, + BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, JournalDBError, JournalGetter, + Transaction, TransactionGetter, }; use database_interface::{Database, DatabaseCommit}; use handler::{EthHandler, FrameResult}; From f3213ac9336512d704941c14f7913b71defc7471 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Dec 2024 13:01:11 +0100 Subject: [PATCH 07/14] simplify context --- crates/inspector/src/inspector.rs | 198 +++++++++++++----------------- crates/optimism/src/evm.rs | 7 +- 2 files changed, 92 insertions(+), 113 deletions(-) diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index 60423e6566..97066591c4 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -1,16 +1,14 @@ use auto_impl::auto_impl; use core::mem::MaybeUninit; -use derive_where::derive_where; use revm::{ bytecode::opcode::OpCode, - context::{block::BlockEnv, cfg::CfgEnv, tx::TxEnv, Cfg, JournaledState}, + context::JournaledState, context_interface::{ block::BlockSetter, journaled_state::{AccountLoad, Eip7702CodeLoad}, - result::EVMError, transaction::TransactionSetter, Block, BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalDBError, - JournalGetter, Transaction, TransactionGetter, + JournalGetter, TransactionGetter, }, database_interface::{Database, EmptyDB}, handler::{ @@ -29,7 +27,6 @@ use revm::{ }, precompile::PrecompileErrors, primitives::{Address, Bytes, Log, B256, U256}, - specification::hardfork::SpecId, Context, Error, Evm, JournalEntry, }; use std::{rc::Rc, vec::Vec}; @@ -189,32 +186,28 @@ impl> GetInspector::Error)] -pub struct InspectorContext< - INSP, - BLOCK = BlockEnv, - TX = TxEnv, - CFG = CfgEnv, - DB: Database = EmptyDB, - JOURNAL: Journal = JournaledState, - CHAIN = (), -> { - pub inner: Context, +#[derive(Clone, Debug)] +pub struct InspectorContext +where + CTX: DatabaseGetter, +{ pub inspector: INSP, + pub inner: CTX, pub frame_input_stack: Vec, } -impl< - INSP, - BLOCK: Block, - TX: Transaction, - CFG: Cfg, - DB: Database, - JOURNAL: Journal, - CHAIN, - > InspectorContext +impl InspectorContext +where + CTX: BlockGetter + + TransactionGetter + + CfgGetter + + DatabaseGetter + + JournalGetter + + ErrorGetter + + Host + + ErrorGetter, { - pub fn new(inner: Context, inspector: INSP) -> Self { + pub fn new(inner: CTX, inspector: INSP) -> Self { Self { inner, inspector, @@ -223,30 +216,24 @@ impl< } } -impl< - INSP: GetInspector, EthInterpreter>, - BLOCK: Block, - TX: Transaction, - CFG: Cfg, - DB: Database, - JOURNAL: Journal, - CHAIN, - > Host for InspectorContext +impl, DB, CTX> Host for InspectorContext +where + CTX: Host + DatabaseGetter, { - type BLOCK = BLOCK; - type TX = TX; - type CFG = CFG; + type BLOCK = ::BLOCK; + type TX = ::TX; + type CFG = ::CFG; fn tx(&self) -> &Self::TX { - &self.inner.tx + self.inner.tx() } fn block(&self) -> &Self::BLOCK { - &self.inner.block + self.inner.block() } fn cfg(&self) -> &Self::CFG { - &self.inner.cfg + self.inner.cfg() } fn block_hash(&mut self, requested_number: u64) -> Option { @@ -262,12 +249,11 @@ impl< } fn code(&mut self, address: Address) -> Option> { - // TODO remove duplicated function name. - as Host>::code(&mut self.inner, address) + self.inner.code(address) } fn code_hash(&mut self, address: Address) -> Option> { - as Host>::code_hash(&mut self.inner, address) + self.inner.code_hash(address) } fn sload(&mut self, address: Address, index: U256) -> Option> { @@ -304,10 +290,10 @@ impl< } } -impl, CHAIN> InspectorCtx - for InspectorContext +impl InspectorCtx for InspectorContext where - INSP: GetInspector, EthInterpreter>, + INSP: GetInspector, + CTX: DatabaseGetter, { type IT = EthInterpreter<()>; @@ -389,100 +375,104 @@ where } } -impl, CHAIN> CfgGetter - for InspectorContext +impl CfgGetter for InspectorContext +where + CTX: CfgGetter + DatabaseGetter, { - type Cfg = CFG; + type Cfg = ::Cfg; fn cfg(&self) -> &Self::Cfg { - &self.inner.cfg + self.inner.cfg() } } -impl, CHAIN> JournalGetter - for InspectorContext +impl JournalGetter for InspectorContext +where + CTX: JournalGetter + DatabaseGetter, + DB: Database, { - type Journal = JOURNAL; + type Journal = ::Journal; fn journal(&mut self) -> &mut Self::Journal { - &mut self.inner.journaled_state + self.inner.journal() } fn journal_ref(&self) -> &Self::Journal { - &self.inner.journaled_state + self.inner.journal_ref() } } -impl, CHAIN> DatabaseGetter - for InspectorContext +impl DatabaseGetter for InspectorContext +where + CTX: DatabaseGetter, + DB: Database, { - type Database = DB; + type Database = ::Database; fn db(&mut self) -> &mut Self::Database { - self.inner.journaled_state.db_mut() + self.inner.db() } } -impl, CHAIN> - ErrorGetter for InspectorContext +impl ErrorGetter for InspectorContext +where + CTX: ErrorGetter + DatabaseGetter, { - type Error = EVMError; + type Error = ::Error; fn take_error(&mut self) -> Result<(), Self::Error> { - core::mem::replace(&mut self.inner.error, Ok(())).map_err(EVMError::Database) + self.inner.take_error() } } -impl, CHAIN> - TransactionGetter for InspectorContext +impl TransactionGetter for InspectorContext +where + CTX: TransactionGetter + DatabaseGetter, { - type Transaction = TX; + type Transaction = ::Transaction; fn tx(&self) -> &Self::Transaction { - &self.inner.tx + self.inner.tx() } } -impl, CHAIN> - TransactionSetter for InspectorContext +impl TransactionSetter for InspectorContext +where + CTX: TransactionSetter + DatabaseGetter, { fn set_tx(&mut self, tx: ::Transaction) { - self.inner.tx = tx; + self.inner.set_tx(tx); } } -impl, CHAIN> BlockGetter - for InspectorContext +impl BlockGetter for InspectorContext +where + CTX: BlockGetter + DatabaseGetter, { - type Block = BLOCK; + type Block = ::Block; fn block(&self) -> &Self::Block { - &self.inner.block + self.inner.block() } } -impl, CHAIN> BlockSetter - for InspectorContext +impl BlockSetter for InspectorContext +where + CTX: BlockSetter + DatabaseGetter, { fn set_block(&mut self, block: ::Block) { - self.inner.block = block; + self.inner.set_block(block); } } -impl< - INSP, - BLOCK: Block, - TX, - CFG, - DB: Database, - JOURNAL: Journal + JournalExt, - CHAIN, - > JournalExtGetter for InspectorContext +impl JournalExtGetter for InspectorContext +where + CTX: JournalExtGetter + DatabaseGetter, { - type JournalExt = JOURNAL; + type JournalExt = ::JournalExt; fn journal_ext(&self) -> &Self::JournalExt { - &self.inner.journaled_state + self.inner.journal_ext() } } @@ -770,31 +760,17 @@ where } } -pub type InspCtxType< - INSP, - DB, - BLOCK = BlockEnv, - TX = TxEnv, - CFG = CfgEnv, - JOURNAL = JournaledState, -> = InspectorContext; - -pub type InspectorMainEvm< - DB, - INSP, - BLOCK = BlockEnv, - TX = TxEnv, - CFG = CfgEnv, - JOURNAL = JournaledState, -> = Evm< +pub type InspCtxType = InspectorContext; + +pub type InspectorMainEvm = Evm< Error, - InspCtxType, + InspCtxType, EthHandler< - InspCtxType, + InspCtxType, Error, - EthValidation, Error>, - EthPreExecution, Error>, - InspectorEthExecution, Error>, + EthValidation, Error>, + EthPreExecution, Error>, + InspectorEthExecution, Error>, >, >; diff --git a/crates/optimism/src/evm.rs b/crates/optimism/src/evm.rs index 424889b1a0..410cde36a4 100644 --- a/crates/optimism/src/evm.rs +++ b/crates/optimism/src/evm.rs @@ -21,8 +21,11 @@ pub type OpContext = Context, CfgEnv, /// Optimism EVM type. pub type OpEvm = Evm, OpContext, OpHandler, OpError>>; -pub type InspCtxType = - InspectorContext, DB, JournaledState, L1BlockInfo>; +pub type InspCtxType = InspectorContext< + INSP, + DB, + Context, DB, JournaledState, L1BlockInfo>, +>; pub type InspectorOpEvm = Evm< OpError, From ebc479de6297c36e4554aba037d4fb9d391c3e9d Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Dec 2024 13:06:45 +0100 Subject: [PATCH 08/14] auto_impl on error getter trait --- crates/context/interface/src/errors.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/context/interface/src/errors.rs b/crates/context/interface/src/errors.rs index 731f438f61..a3a58eaeb9 100644 --- a/crates/context/interface/src/errors.rs +++ b/crates/context/interface/src/errors.rs @@ -1,4 +1,6 @@ -/// TODO change name of the trait +use auto_impl::auto_impl; +/// Trait to get error from context. +#[auto_impl(&mut, Box)] pub trait ErrorGetter { type Error; From 0366c407437ee5964a5112584a79c28230268254 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Dec 2024 13:12:37 +0100 Subject: [PATCH 09/14] simpify host --- crates/context/interface/src/host.rs | 20 +++----------- crates/context/interface/src/host/dummy.rs | 31 +++++++++++++--------- crates/context/src/context.rs | 16 ----------- crates/inspector/src/inspector.rs | 16 ----------- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/crates/context/interface/src/host.rs b/crates/context/interface/src/host.rs index 81f6277864..a6ce22aec0 100644 --- a/crates/context/interface/src/host.rs +++ b/crates/context/interface/src/host.rs @@ -5,27 +5,15 @@ pub use dummy::DummyHost; use crate::{ journaled_state::{AccountLoad, Eip7702CodeLoad}, - Block, Cfg, Transaction, + BlockGetter, CfgGetter, TransactionGetter, }; +use auto_impl::auto_impl; use primitives::{Address, Bytes, Log, B256, U256}; /// EVM context host. /// TODO move to context-interface -pub trait Host { - /// Chain specification. - type BLOCK: Block; - type TX: Transaction; - type CFG: Cfg; - - /// Returns a reference to the environment. - fn tx(&self) -> &Self::TX; - - /// Returns a mutable reference to the environment. - fn block(&self) -> &Self::BLOCK; - - /// TODO make it generic in future - fn cfg(&self) -> &Self::CFG; - +#[auto_impl(&mut, Box)] +pub trait Host: TransactionGetter + BlockGetter + CfgGetter { /// Load an account code. fn load_account_delegated(&mut self, address: Address) -> Option; diff --git a/crates/context/interface/src/host/dummy.rs b/crates/context/interface/src/host/dummy.rs index da19a89c62..41781d5373 100644 --- a/crates/context/interface/src/host/dummy.rs +++ b/crates/context/interface/src/host/dummy.rs @@ -1,5 +1,5 @@ use super::{Host, SStoreResult, SelfDestructResult}; -use crate::{Block, Cfg, Transaction}; +use crate::{Block, BlockGetter, Cfg, CfgGetter, Transaction, TransactionGetter}; use primitives::{hash_map::Entry, Address, Bytes, HashMap, Log, B256, KECCAK_EMPTY, U256}; use std::vec::Vec; @@ -48,26 +48,31 @@ where } } -impl Host for DummyHost { - type TX = TX; - type BLOCK = BLOCK; - type CFG = CFG; +impl BlockGetter for DummyHost { + type Block = BLOCK; - #[inline] - fn tx(&self) -> &Self::TX { - &self.tx + fn block(&self) -> &Self::Block { + &self.block } +} - #[inline] - fn block(&self) -> &Self::BLOCK { - &self.block +impl TransactionGetter for DummyHost { + type Transaction = TX; + + fn tx(&self) -> &Self::Transaction { + &self.tx } +} - #[inline] - fn cfg(&self) -> &Self::CFG { +impl CfgGetter for DummyHost { + type Cfg = CFG; + + fn cfg(&self) -> &Self::Cfg { &self.cfg } +} +impl Host for DummyHost { #[inline] fn load_account_delegated(&mut self, _address: Address) -> Option { Some(AccountLoad::default()) diff --git a/crates/context/src/context.rs b/crates/context/src/context.rs index 05327c73bd..c98b02ad44 100644 --- a/crates/context/src/context.rs +++ b/crates/context/src/context.rs @@ -380,22 +380,6 @@ where DB: Database, JOURNAL: Journal, { - type BLOCK = BLOCK; - type TX = TX; - type CFG = CFG; - - fn tx(&self) -> &Self::TX { - &self.tx - } - - fn block(&self) -> &Self::BLOCK { - &self.block - } - - fn cfg(&self) -> &Self::CFG { - &self.cfg - } - fn block_hash(&mut self, requested_number: u64) -> Option { let block_number = as_u64_saturated!(*self.block().number()); diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index 97066591c4..491534092b 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -220,22 +220,6 @@ impl, DB, CTX> Host for InspectorContext where CTX: Host + DatabaseGetter, { - type BLOCK = ::BLOCK; - type TX = ::TX; - type CFG = ::CFG; - - fn tx(&self) -> &Self::TX { - self.inner.tx() - } - - fn block(&self) -> &Self::BLOCK { - self.inner.block() - } - - fn cfg(&self) -> &Self::CFG { - self.inner.cfg() - } - fn block_hash(&mut self, requested_number: u64) -> Option { self.inner.block_hash(requested_number) } From 0d987e4c969fba9128d99b0e15ea99dd0e4cfd21 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Dec 2024 13:30:33 +0100 Subject: [PATCH 10/14] impl &mut and Box over setter traits --- crates/context/interface/src/block.rs | 12 ++++++++++++ crates/context/interface/src/transaction.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/context/interface/src/block.rs b/crates/context/interface/src/block.rs index fb8d996d01..6743bbba7f 100644 --- a/crates/context/interface/src/block.rs +++ b/crates/context/interface/src/block.rs @@ -79,3 +79,15 @@ pub trait BlockGetter { pub trait BlockSetter: BlockGetter { fn set_block(&mut self, block: ::Block); } + +impl BlockSetter for &mut T { + fn set_block(&mut self, block: ::Block) { + (**self).set_block(block) + } +} + +impl BlockSetter for Box { + fn set_block(&mut self, block: ::Block) { + (**self).set_block(block) + } +} diff --git a/crates/context/interface/src/transaction.rs b/crates/context/interface/src/transaction.rs index db59b2bd17..c13f8712eb 100644 --- a/crates/context/interface/src/transaction.rs +++ b/crates/context/interface/src/transaction.rs @@ -164,3 +164,15 @@ pub trait TransactionGetter { pub trait TransactionSetter: TransactionGetter { fn set_tx(&mut self, tx: ::Transaction); } + +impl TransactionSetter for &mut T { + fn set_tx(&mut self, block: ::Transaction) { + (**self).set_tx(block) + } +} + +impl TransactionSetter for Box { + fn set_tx(&mut self, block: ::Transaction) { + (**self).set_tx(block) + } +} From 16d369c73223319a6879d624bb8a7e3bad68a366 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Dec 2024 13:43:37 +0100 Subject: [PATCH 11/14] relax JournalExt --- crates/inspector/src/inspector.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/inspector/src/inspector.rs b/crates/inspector/src/inspector.rs index a4c3fe59af..be25d415b3 100644 --- a/crates/inspector/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -7,7 +7,7 @@ use revm::{ block::BlockSetter, journaled_state::{AccountLoad, Eip7702CodeLoad}, transaction::TransactionSetter, - Block, BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalDBError, + BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, Journal, JournalDBError, JournalGetter, TransactionGetter, }, database_interface::{Database, EmptyDB}, @@ -460,7 +460,7 @@ where } } -impl + JournalExt, CHAIN> +impl + JournalExt, CHAIN> JournalExtGetter for Context { type JournalExt = JOURNAL; From da97732f86c687ec12486b636fa5ab433de506a0 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 24 Dec 2024 11:17:20 +0100 Subject: [PATCH 12/14] compile no std --- crates/context/interface/src/transaction.rs | 1 + crates/database/interface/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/context/interface/src/transaction.rs b/crates/context/interface/src/transaction.rs index c13f8712eb..dc70c29010 100644 --- a/crates/context/interface/src/transaction.rs +++ b/crates/context/interface/src/transaction.rs @@ -20,6 +20,7 @@ use auto_impl::auto_impl; use core::cmp::min; use core::fmt::Debug; use primitives::{TxKind, U256}; +use std::boxed::Box; /// Transaction validity error types. pub trait TransactionError: Debug + core::error::Error {} diff --git a/crates/database/interface/src/lib.rs b/crates/database/interface/src/lib.rs index 9e2fc53fa3..db2b73f7d6 100644 --- a/crates/database/interface/src/lib.rs +++ b/crates/database/interface/src/lib.rs @@ -28,6 +28,7 @@ pub trait DBErrorMarker {} /// Implement marker for `()`. impl DBErrorMarker for () {} impl DBErrorMarker for Infallible {} +impl DBErrorMarker for String {} /// EVM database interface. #[auto_impl(&mut, Box)] From e2da72cdaef1c053a3351f688054921814ae8685 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 24 Dec 2024 11:25:48 +0100 Subject: [PATCH 13/14] string --- crates/database/interface/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/database/interface/src/lib.rs b/crates/database/interface/src/lib.rs index db2b73f7d6..d1678b6be5 100644 --- a/crates/database/interface/src/lib.rs +++ b/crates/database/interface/src/lib.rs @@ -10,6 +10,7 @@ use core::convert::Infallible; use auto_impl::auto_impl; use primitives::{Address, HashMap, B256, U256}; use state::{Account, AccountInfo, Bytecode}; +use std::string::String; #[cfg(feature = "asyncdb")] pub mod async_db; From 741a8643920c56724f1d4cdb40b11e628d47ce34 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 24 Dec 2024 11:31:03 +0100 Subject: [PATCH 14/14] box --- crates/context/interface/src/block.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/context/interface/src/block.rs b/crates/context/interface/src/block.rs index 6743bbba7f..956d6dfe60 100644 --- a/crates/context/interface/src/block.rs +++ b/crates/context/interface/src/block.rs @@ -4,6 +4,7 @@ pub use blob::{calc_blob_gasprice, calc_excess_blob_gas, BlobExcessGasAndPrice}; use auto_impl::auto_impl; use primitives::{Address, B256, U256}; +use std::boxed::Box; /// Trait for retrieving block information required for execution. #[auto_impl(&, &mut, Box, Arc)]