diff --git a/crates/inspector/Cargo.toml b/crates/inspector/Cargo.toml index e5f7ea55f6..d35174136b 100644 --- a/crates/inspector/Cargo.toml +++ b/crates/inspector/Cargo.toml @@ -44,7 +44,7 @@ database = { workspace = true, features = ["serde"] } [features] default = ["std"] -# Preserve ordeder of json +# Preserve order of json field std = ["serde?/std", "serde_json?/std", "serde_json?/preserve_order"] serde = ["dep:serde", "revm/serde", "database/serde"] serde-json = ["serde", "dep:serde_json"] diff --git a/crates/inspector/src/eip3155.rs b/crates/inspector/src/eip3155.rs index fe5ad50968..4ed1d6d769 100644 --- a/crates/inspector/src/eip3155.rs +++ b/crates/inspector/src/eip3155.rs @@ -19,7 +19,7 @@ use std::io::Write; pub struct TracerEip3155 { #[derive_where(skip)] output: Box, - gas_inspector: GasInspector, + gas_inspector: GasInspector, /// Print summary of the execution. print_summary: bool, @@ -36,6 +36,7 @@ pub struct TracerEip3155 { skip: bool, include_memory: bool, memory: Option, + _phantom: std::marker::PhantomData<(CTX, INTR)>, } // # Output @@ -153,6 +154,7 @@ where refunded: 0, mem_size: 0, skip: false, + _phantom: Default::default(), } } @@ -209,12 +211,12 @@ where type Context = CTX; type InterpreterTypes = INTR; - fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut CTX) { - self.gas_inspector.initialize_interp(interp, context); + fn initialize_interp(&mut self, interp: &mut Interpreter, _: &mut CTX) { + self.gas_inspector.initialize_interp(interp.control.gas()); } - fn step(&mut self, interp: &mut Interpreter, context: &mut CTX) { - self.gas_inspector.step(interp, context); + fn step(&mut self, interp: &mut Interpreter, _: &mut CTX) { + self.gas_inspector.step(interp.control.gas()); self.stack = interp.stack.clone_from(); self.memory = if self.include_memory { Some(hex::encode_prefixed( @@ -230,8 +232,8 @@ where self.refunded = interp.control.gas().refunded(); } - fn step_end(&mut self, interp: &mut Interpreter, context: &mut CTX) { - self.gas_inspector.step_end(interp, context); + fn step_end(&mut self, interp: &mut Interpreter, _: &mut CTX) { + self.gas_inspector.step_end(interp.control.gas()); if self.skip { self.skip = false; return; @@ -280,8 +282,8 @@ where None } - fn call_end(&mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome) { - self.gas_inspector.call_end(context, inputs, outcome); + fn call_end(&mut self, context: &mut CTX, _: &CallInputs, outcome: &mut CallOutcome) { + self.gas_inspector.call_end(outcome); self.depth -= 1; if self.depth == 0 { @@ -291,13 +293,8 @@ where } } - fn create_end( - &mut self, - context: &mut CTX, - inputs: &CreateInputs, - outcome: &mut CreateOutcome, - ) { - self.gas_inspector.create_end(context, inputs, outcome); + fn create_end(&mut self, context: &mut CTX, _: &CreateInputs, outcome: &mut CreateOutcome) { + self.gas_inspector.create_end(outcome); self.depth -= 1; if self.depth == 0 { diff --git a/crates/inspector/src/gas.rs b/crates/inspector/src/gas.rs index 697d27892f..86c2e6f313 100644 --- a/crates/inspector/src/gas.rs +++ b/crates/inspector/src/gas.rs @@ -1,27 +1,22 @@ //! GasIspector. Helper Inspector to calculate gas for others. -use crate::Inspector; -use revm::interpreter::{ - interpreter_types::LoopControl, CallInputs, CallOutcome, CreateInputs, CreateOutcome, - Interpreter, InterpreterTypes, -}; +use revm::interpreter::{CallOutcome, CreateOutcome, Gas}; /// Helper [Inspector] that keeps track of gas. #[allow(dead_code)] #[derive(Clone, Copy, Debug)] -pub struct GasInspector { +pub struct GasInspector { gas_remaining: u64, last_gas_cost: u64, - _phantom: core::marker::PhantomData<(CTX, INTR)>, } -impl Default for GasInspector { +impl Default for GasInspector { fn default() -> Self { Self::new() } } -impl GasInspector { +impl GasInspector { pub fn gas_remaining(&self) -> u64 { self.gas_remaining } @@ -34,41 +29,30 @@ impl GasInspector { Self { gas_remaining: 0, last_gas_cost: 0, - _phantom: core::marker::PhantomData, } } } -impl Inspector for GasInspector { - type Context = CTX; - type InterpreterTypes = INTR; - +impl GasInspector { #[inline] - fn initialize_interp( - &mut self, - interp: &mut Interpreter, - _: &mut Self::Context, - ) { - self.gas_remaining = interp.control.gas().limit(); + pub fn initialize_interp(&mut self, gas: &Gas) { + self.gas_remaining = gas.limit(); } #[inline] - fn step(&mut self, interp: &mut Interpreter, _: &mut Self::Context) { - self.gas_remaining = interp.control.gas().remaining(); + pub fn step(&mut self, gas: &Gas) { + self.gas_remaining = gas.remaining(); } + #[inline] - fn step_end( - &mut self, - interp: &mut Interpreter, - _: &mut Self::Context, - ) { - let remaining = interp.control.gas().remaining(); + pub fn step_end(&mut self, gas: &mut Gas) { + let remaining = gas.remaining(); self.last_gas_cost = self.gas_remaining.saturating_sub(remaining); self.gas_remaining = remaining; } #[inline] - fn call_end(&mut self, _: &mut Self::Context, _: &CallInputs, outcome: &mut CallOutcome) { + pub fn call_end(&mut self, outcome: &mut CallOutcome) { if outcome.result.result.is_error() { outcome.result.gas.spend_all(); self.gas_remaining = 0; @@ -76,7 +60,7 @@ impl Inspector for GasInspector { } #[inline] - fn create_end(&mut self, _: &mut Self::Context, _: &CreateInputs, outcome: &mut CreateOutcome) { + pub fn create_end(&mut self, outcome: &mut CreateOutcome) { if outcome.result.result.is_error() { outcome.result.gas.spend_all(); self.gas_remaining = 0;