Skip to content

Commit

Permalink
chore: add depth to GasInspector (#1922)
Browse files Browse the repository at this point in the history
* chore: Simplify GasInspector

* fmt

* chore: add depth to GasInspector

* rm doc
  • Loading branch information
rakita authored Dec 17, 2024
1 parent 3774f6e commit 62c33ec
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions crates/inspector/src/gas.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 62c33ec

Please sign in to comment.