Struct GasTracker
pub struct GasTracker { /* private fields */ }Expand description
Tracker for gas during execution.
This is used to track the gas during execution.
Implementations§
§impl GasTracker
impl GasTracker
pub const fn new(gas_limit: u64, remaining: u64, reservoir: u64) -> GasTracker
pub const fn new(gas_limit: u64, remaining: u64, reservoir: u64) -> GasTracker
Creates a new GasTracker with the given remaining gas and reservoir.
pub const fn new_used_gas(
gas_limit: u64,
used_gas: u64,
reservoir: u64,
) -> GasTracker
pub const fn new_used_gas( gas_limit: u64, used_gas: u64, reservoir: u64, ) -> GasTracker
Creates a new GasTracker with the given used gas and reservoir.
pub const fn set_remaining(&mut self, val: u64)
pub const fn set_remaining(&mut self, val: u64)
Sets the remaining gas.
pub const fn set_reservoir(&mut self, val: u64)
pub const fn set_reservoir(&mut self, val: u64)
Sets the reservoir gas.
pub const fn state_gas_spent(&self) -> i64
pub const fn state_gas_spent(&self) -> i64
Returns the state gas spent.
pub const fn set_state_gas_spent(&mut self, val: i64)
pub const fn set_state_gas_spent(&mut self, val: i64)
Sets the state gas spent.
pub const fn state_gas_spilled(&self) -> u64
pub const fn state_gas_spilled(&self) -> u64
Returns the state gas drawn from regular gas (remaining) because the
reservoir was empty (EIP-8037’s state_gas_from_gas_left).
pub const fn set_state_gas_spilled(&mut self, val: u64)
pub const fn set_state_gas_spilled(&mut self, val: u64)
Sets the spilled state gas.
pub const fn add_state_gas_spilled(&mut self, delta: u64)
pub const fn add_state_gas_spilled(&mut self, delta: u64)
Adds delta to the spilled state gas, saturating.
Used to merge a successful child frame’s spilled state gas into this (parent) frame so a later parent rollback can return it.
pub const fn set_refunded(&mut self, val: i64)
pub const fn set_refunded(&mut self, val: i64)
Sets the refunded gas.
pub const fn record_regular_cost(&mut self, cost: u64) -> bool
pub const fn record_regular_cost(&mut self, cost: u64) -> bool
Records a regular gas cost.
Deducts from remaining. Returns false if insufficient gas.
pub const fn record_state_cost(&mut self, cost: u64) -> bool
pub const fn record_state_cost(&mut self, cost: u64) -> bool
Records a state gas cost (EIP-8037 reservoir model).
State gas charges deduct from the reservoir first. If the reservoir is exhausted,
remaining charges spill into remaining (requiring remaining >= cost).
Tracks state gas spent.
Returns false if total remaining gas is insufficient.
pub const fn rollback_state_gas(&mut self)
pub const fn rollback_state_gas(&mut self)
Rolls back this frame’s state-gas charges on revert or exceptional halt (EIP-8037).
The state gas charged within the frame is refilled in last-in-first-out
order: the spilled portion is credited back to remaining (the pool
charged last) and the rest restores the reservoir to its frame-start
value. Concretely, remaining gains state_gas_spilled and the reservoir
becomes reservoir + state_gas_spent - state_gas_spilled, which is exactly
the reservoir the frame inherited. Both state-gas counters are then reset.
On revert the resulting remaining (including the refilled spill) is
returned to the parent; on halt the caller additionally zeroes remaining
so the spilled gas is consumed while the reservoir is left untouched.
pub const fn refill_reservoir(&mut self, amount: u64)
pub const fn refill_reservoir(&mut self, amount: u64)
Refills the reservoir with state gas that is returned by 0→x→0 storage restoration (EIP-8037 issue #2).
Per the spec, when a storage slot is restored to its original zero value within the same transaction, the state gas charged for the initial 0→x transition is directly restored to the reservoir rather than routed through the capped refund counter.
state_gas_spent is decremented by the full amount and may become
negative if the matching 0→x charge was made by a parent frame (so this
frame’s state_gas_spilled is zero and the whole refill lands in the
reservoir); the parent’s total is reconciled on frame return.
Because charges deduct from the reservoir first and from regular gas
(remaining) last, the refill credits the pool charged last first:
remaining is credited up to state_gas_spilled and any remainder tops
up the reservoir.
pub const fn record_refund(&mut self, refund: i64)
pub const fn record_refund(&mut self, refund: i64)
Records a refund value.
pub const fn erase_cost(&mut self, returned: u64)
pub const fn erase_cost(&mut self, returned: u64)
Erases a gas cost from remaining (returns gas from child frame).
pub const fn spend_all(&mut self)
pub const fn spend_all(&mut self)
Spends all remaining gas excluding the reservoir.
Trait Implementations§
§impl Clone for GasTracker
impl Clone for GasTracker
§fn clone(&self) -> GasTracker
fn clone(&self) -> GasTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for GasTracker
§impl Debug for GasTracker
impl Debug for GasTracker
§impl Default for GasTracker
impl Default for GasTracker
§fn default() -> GasTracker
fn default() -> GasTracker
§impl<'de> Deserialize<'de> for GasTracker
impl<'de> Deserialize<'de> for GasTracker
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GasTracker, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GasTracker, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for GasTracker
§impl Hash for GasTracker
impl Hash for GasTracker
§impl PartialEq for GasTracker
impl PartialEq for GasTracker
§impl Serialize for GasTracker
impl Serialize for GasTracker
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for GasTracker
Auto Trait Implementations§
impl Freeze for GasTracker
impl RefUnwindSafe for GasTracker
impl Send for GasTracker
impl Sync for GasTracker
impl Unpin for GasTracker
impl UnsafeUnpin for GasTracker
impl UnwindSafe for GasTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.