Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Jul 22, 2024
1 parent 9d01f4a commit 8bb65dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 25 deletions.
14 changes: 3 additions & 11 deletions runtime/near-vm-runner/src/logic/gas_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,10 @@ impl GasCounter {
}

/// 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
pub(crate) fn gas_counter_raw_ptr(&mut self) -> *mut FastGasCounter {
#[cfg(any(feature = "wasmer2_vm", feature = "near_vm"))]
pub(crate) fn fast_counter_raw_ptr(&mut self) -> *mut FastGasCounter {
use std::ptr;
ptr::addr_of_mut!(self.fast_counter)
}
Expand Down
16 changes: 7 additions & 9 deletions runtime/near-vm-runner/src/logic/logic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::context::VMContext;
use super::dependencies::{External, MemSlice, MemoryLike};
use super::errors::{FunctionCallError, InconsistentStateError};
use super::gas_counter::{FastGasCounter, GasCounter};
use super::gas_counter::GasCounter;
use super::recorded_storage_counter::RecordedStorageCounter;
use super::types::{PromiseIndex, PromiseResult, ReceiptIndex, ReturnData};
use super::utils::split_method_names;
Expand Down Expand Up @@ -267,11 +267,6 @@ impl<'a> VMLogic<'a> {
&self.result_state.logs
}

#[cfg(test)]
pub(super) fn gas_counter(&self) -> &GasCounter {
&self.result_state.gas_counter
}

#[cfg(test)]
pub(super) fn config(&self) -> &Config {
&self.config
Expand Down Expand Up @@ -3461,9 +3456,12 @@ impl<'a> VMLogic<'a> {
}))
}

/// Gets pointer to the fast gas counter.
pub(crate) fn gas_counter_pointer(&mut self) -> *mut FastGasCounter {
self.result_state.gas_counter.gas_counter_raw_ptr()
/// Obtain a reference to the gas counter.
///
/// This is meant for use in tests and implementation of VMs only. Implementations of host
/// functions should be using `pay_*` functions instead.
pub(crate) fn gas_counter(&mut self) -> &mut GasCounter {
&mut self.result_state.gas_counter
}

/// Properly handles gas limit exceeded error.
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner/src/near_vm_runner/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl NearVM {
offset_of!(FastGasCounter, gas_limit),
offset_of!(near_vm_types::FastGasCounter, gas_limit)
);
let gas = import.vmlogic.gas_counter_pointer() as *mut near_vm_types::FastGasCounter;
let gas = import.vmlogic.gas_counter().fast_counter_raw_ptr();
unsafe {
let instance = {
let _span = tracing::debug_span!(target: "vm", "run_method/instantiate").entered();
Expand All @@ -365,7 +365,7 @@ impl NearVM {
// by the virtue of it being contained within `import` which lives for the
// entirety of this function.
InstanceConfig::with_stack_limit(self.config.limit_config.max_stack_height)
.with_counter(gas),
.with_counter(gas.cast()),
);
let handle = match maybe_handle {
Ok(handle) => handle,
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner/src/wasmer2_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl Wasmer2VM {
offset_of!(FastGasCounter, opcode_cost),
offset_of!(wasmer_types::FastGasCounter, opcode_cost)
);
let gas = import.vmlogic.gas_counter_pointer() as *mut wasmer_types::FastGasCounter;
let gas = import.vmlogic.gas_counter().fast_counter_raw_ptr();
unsafe {
let instance = {
let _span = tracing::debug_span!(target: "vm", "run_method/instantiate").entered();
Expand All @@ -435,7 +435,7 @@ impl Wasmer2VM {
// by the virtue of it being contained within `import` which lives for the
// entirety of this function.
InstanceConfig::default()
.with_counter(gas)
.with_counter(gas.cast())
.with_stack_limit(self.config.limit_config.wasmer2_stack_limit),
);
let handle = match maybe_handle {
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) fn execute_function_call(
attached_deposit: function_call.deposit,
prepaid_gas: function_call.gas,
random_seed,
view_config: view_config.clone(),
view_config,
output_data_receivers,
};

Expand Down

0 comments on commit 8bb65dd

Please sign in to comment.