From 62c33ecf18bee5ace16747dcde0a5184c7fe5347 Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 17 Dec 2024 10:51:43 +0100 Subject: [PATCH] chore: add depth to GasInspector (#1922) * chore: Simplify GasInspector * fmt * chore: add depth to GasInspector * rm doc --- crates/inspector/src/gas.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/inspector/src/gas.rs b/crates/inspector/src/gas.rs index 86c2e6f313..5913f2251d 100644 --- a/crates/inspector/src/gas.rs +++ b/crates/inspector/src/gas.rs @@ -1,13 +1,14 @@ //! GasIspector. Helper Inspector to calculate gas for others. - use revm::interpreter::{CallOutcome, CreateOutcome, Gas}; -/// Helper [Inspector] that keeps track of gas. +/// Helper that keeps track of gas. #[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub struct GasInspector { gas_remaining: u64, last_gas_cost: u64, + /// depth + depth: usize, } impl Default for GasInspector { @@ -29,11 +30,10 @@ impl GasInspector { Self { gas_remaining: 0, last_gas_cost: 0, + depth: 0, } } -} -impl GasInspector { #[inline] pub fn initialize_interp(&mut self, gas: &Gas) { self.gas_remaining = gas.limit(); @@ -66,6 +66,24 @@ impl GasInspector { self.gas_remaining = 0; } } + + /// Returns depth + #[inline] + pub fn depth(&self) -> usize { + self.depth + } + + /// Increment depth + #[inline] + pub fn incr_depth(&mut self) { + self.depth += 1; + } + + /// Decrement depth + #[inline] + pub fn decr_depth(&mut self) { + self.depth -= 1; + } } // #[cfg(test)]