Struct near_vm_logic::gas_counter::GasCounter
source · pub struct GasCounter { /* private fields */ }
Expand description
Gas counter (a part of VMlogic)
Implementations§
source§impl GasCounter
impl GasCounter
pub fn new( ext_costs_config: ExtCostsConfig, max_gas_burnt: Gas, opcode_cost: u32, prepaid_gas: Gas, is_view: bool ) -> Self
sourcepub fn burn_gas(&mut self, gas_burnt: Gas) -> Result<(), VMLogicError>
pub fn burn_gas(&mut self, gas_burnt: Gas) -> Result<(), VMLogicError>
Simpler version of deduct_gas()
for when no promises are involved.
Return an error if there are arithmetic overflows.
pub fn process_gas_limit( &mut self, new_burnt_gas: Gas, new_used_gas: Gas ) -> HostError
pub fn pay_wasm_gas(&mut self, opcodes: u32) -> Result<(), VMLogicError>
sourcepub fn gas_counter_raw_ptr(&mut self) -> *mut FastGasCounter
pub fn gas_counter_raw_ptr(&mut self) -> *mut FastGasCounter
Very special function to get the gas counter pointer for generated machine code.
Please do not use, unless fully understand Rust aliasing and other consequences.
Can be used to emit inlined code like pay_wasm_gas()
, i.e.
mov base, gas_counter_raw_ptr
mov rax, [base + 0] ; current burnt gas
mov rcx, [base + 16] ; opcode cost
imul rcx, block_ops_count ; block cost
add rax, rcx ; new burnt gas
jo emit_integer_overflow
cmp rax, [base + 8] ; unsigned compare with burnt limit
mov [base + 0], rax
ja emit_gas_exceeded
sourcepub fn pay_per(&mut self, cost: ExtCosts, num: u64) -> Result<(), VMLogicError>
pub fn pay_per(&mut self, cost: ExtCosts, num: u64) -> Result<(), VMLogicError>
A helper function to pay a multiple of a cost.
sourcepub fn pay_base(&mut self, cost: ExtCosts) -> Result<(), VMLogicError>
pub fn pay_base(&mut self, cost: ExtCosts) -> Result<(), VMLogicError>
A helper function to pay base cost gas.
sourcepub fn pay_action_accumulated(
&mut self,
burn_gas: Gas,
use_gas: Gas,
action: ActionCosts
) -> Result<(), VMLogicError>
pub fn pay_action_accumulated( &mut self, burn_gas: Gas, use_gas: Gas, action: ActionCosts ) -> Result<(), VMLogicError>
A helper function to pay base cost gas fee for batching an action.
Args:
burn_gas
: amount of gas to burn;use_gas
: amount of gas to reserve;action
: what kind of action is charged for;
pub fn add_trie_fees( &mut self, count: &TrieNodesCount ) -> Result<(), VMLogicError>
pub fn prepay_gas(&mut self, use_gas: Gas) -> Result<(), VMLogicError>
pub fn burnt_gas(&self) -> Gas
sourcepub fn unused_gas(&self) -> Gas
pub fn unused_gas(&self) -> Gas
Remaining gas based on the amount of prepaid gas not yet used.
pub fn profile_data(&self) -> ProfileDataV3
Auto Trait Implementations§
impl RefUnwindSafe for GasCounter
impl Send for GasCounter
impl Sync for GasCounter
impl Unpin for GasCounter
impl UnwindSafe for GasCounter
Blanket Implementations§
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request