From e6213f139df2c46efbc6d4d0c05cfb46c9232243 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 22 Jul 2024 14:01:22 +0300 Subject: [PATCH] Fix CI --- runtime/near-vm-runner/src/logic/gas_counter.rs | 14 +++----------- runtime/near-vm-runner/src/logic/logic.rs | 17 ++++++++--------- .../near-vm-runner/src/near_vm_runner/runner.rs | 4 ++-- runtime/near-vm-runner/src/wasmer2_runner.rs | 4 ++-- runtime/runtime/src/actions.rs | 2 +- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/runtime/near-vm-runner/src/logic/gas_counter.rs b/runtime/near-vm-runner/src/logic/gas_counter.rs index f850f603bd8..50030358f6f 100644 --- a/runtime/near-vm-runner/src/logic/gas_counter.rs +++ b/runtime/near-vm-runner/src/logic/gas_counter.rs @@ -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) } diff --git a/runtime/near-vm-runner/src/logic/logic.rs b/runtime/near-vm-runner/src/logic/logic.rs index 3cd80965cef..39f694686b4 100644 --- a/runtime/near-vm-runner/src/logic/logic.rs +++ b/runtime/near-vm-runner/src/logic/logic.rs @@ -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; @@ -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 @@ -3461,9 +3456,13 @@ 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. + #[cfg(any(test, feature = "wasmer2_vm", feature = "near_vm"))] + pub(crate) fn gas_counter(&mut self) -> &mut GasCounter { + &mut self.result_state.gas_counter } /// Properly handles gas limit exceeded error. diff --git a/runtime/near-vm-runner/src/near_vm_runner/runner.rs b/runtime/near-vm-runner/src/near_vm_runner/runner.rs index 494efb707a5..cc0603292a8 100644 --- a/runtime/near-vm-runner/src/near_vm_runner/runner.rs +++ b/runtime/near-vm-runner/src/near_vm_runner/runner.rs @@ -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(); @@ -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, diff --git a/runtime/near-vm-runner/src/wasmer2_runner.rs b/runtime/near-vm-runner/src/wasmer2_runner.rs index 33209a11db8..3557e82d093 100644 --- a/runtime/near-vm-runner/src/wasmer2_runner.rs +++ b/runtime/near-vm-runner/src/wasmer2_runner.rs @@ -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(); @@ -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 { diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index a463b20eef8..6cc9807ed53 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -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, };