From 858be61d99bda3a64ce66a3281556273b34a684d Mon Sep 17 00:00:00 2001 From: Ekleog-NEAR <96595974+Ekleog-NEAR@users.noreply.github.com> Date: Mon, 3 Apr 2023 20:26:05 +0200 Subject: [PATCH] misc cleanups from doing #8323 (#8875) * misc cleanups from doing #8323 * cargo fmt --- chain/client/src/test_utils.rs | 3 +++ core/primitives-core/src/config.rs | 7 +++---- runtime/near-vm-logic/src/gas_counter.rs | 8 +------- runtime/near-vm-runner/src/prepare.rs | 3 +-- runtime/near-vm-runner/src/prepare/prepare_v0.rs | 5 ++++- runtime/near-vm-runner/src/runner.rs | 1 + 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/chain/client/src/test_utils.rs b/chain/client/src/test_utils.rs index f4d88c12512..365fb1b0bea 100644 --- a/chain/client/src/test_utils.rs +++ b/chain/client/src/test_utils.rs @@ -1686,6 +1686,8 @@ impl TestEnv { self.clients[id].process_tx(tx, false, false) } + /// This function will actually bump to the latest protocol version instead of the provided one. + /// See https://github.com/near/nearcore/issues/8590 for details. pub fn upgrade_protocol(&mut self, protocol_version: ProtocolVersion) { assert_eq!(self.clients.len(), 1, "at the moment, this support only a single client"); @@ -1698,6 +1700,7 @@ impl TestEnv { self.clients[0].runtime_adapter.get_block_producer(&epoch_id, tip.height).unwrap(); let mut block = self.clients[0].produce_block(tip.height + 1).unwrap().unwrap(); + eprintln!("Producing block with version {protocol_version}"); block.mut_header().set_latest_protocol_version(protocol_version); block.mut_header().resign(&create_test_signer(block_producer.as_str())); diff --git a/core/primitives-core/src/config.rs b/core/primitives-core/src/config.rs index f365d42d60e..b2276ef3bb6 100644 --- a/core/primitives-core/src/config.rs +++ b/core/primitives-core/src/config.rs @@ -35,8 +35,8 @@ pub struct VMLimitConfig { /// How tall the stack is allowed to grow? /// - /// See to find out - /// how the stack frame cost is calculated. + /// See to find out how the stack frame cost + /// is calculated. pub max_stack_height: u32, /// Whether a legacy version of stack limiting should be used, see /// [`ContractPrepareVersion`]. @@ -46,8 +46,7 @@ pub struct VMLimitConfig { /// The initial number of memory pages. /// NOTE: It's not a limiter itself, but it's a value we use for initial_memory_pages. pub initial_memory_pages: u32, - /// What is the maximal memory pages amount is allowed to have for - /// a contract. + /// What is the maximal memory pages amount is allowed to have for a contract. pub max_memory_pages: u32, /// Limit of memory used by registers. diff --git a/runtime/near-vm-logic/src/gas_counter.rs b/runtime/near-vm-logic/src/gas_counter.rs index 6f2208bc507..d2e1eec2ca7 100644 --- a/runtime/near-vm-logic/src/gas_counter.rs +++ b/runtime/near-vm-logic/src/gas_counter.rs @@ -40,7 +40,7 @@ pub struct FastGasCounter { pub burnt_gas: u64, /// Hard gas limit for execution pub gas_limit: u64, - /// Single WASM opcode cost + /// Cost for one opcode. Used only by VMs preceding near_vm. pub opcode_cost: u64, } @@ -180,11 +180,6 @@ impl GasCounter { } } - pub fn pay_wasm_gas(&mut self, opcodes: u32) -> Result<()> { - let value = Gas::from(opcodes) * self.fast_counter.opcode_cost; - self.burn_gas(value) - } - /// 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. @@ -353,7 +348,6 @@ mod tests { let mut counter = make_test_counter(MAX_GAS, MAX_GAS, false); counter.pay_base(near_primitives::config::ExtCosts::storage_write_base).unwrap(); counter.pay_per(near_primitives::config::ExtCosts::storage_write_value_byte, 10).unwrap(); - counter.pay_wasm_gas(20).unwrap(); counter .pay_action_accumulated( 100, diff --git a/runtime/near-vm-runner/src/prepare.rs b/runtime/near-vm-runner/src/prepare.rs index 146d82a778c..8bc5227fe8b 100644 --- a/runtime/near-vm-runner/src/prepare.rs +++ b/runtime/near-vm-runner/src/prepare.rs @@ -47,9 +47,8 @@ pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result Result, PrepareError> { let wasm = wat::parse_str(wat).unwrap(); diff --git a/runtime/near-vm-runner/src/prepare/prepare_v0.rs b/runtime/near-vm-runner/src/prepare/prepare_v0.rs index 73c86a42c01..6287536cad1 100644 --- a/runtime/near-vm-runner/src/prepare/prepare_v0.rs +++ b/runtime/near-vm-runner/src/prepare/prepare_v0.rs @@ -4,7 +4,10 @@ use parity_wasm_41::builder; use parity_wasm_41::elements::{self, External, MemorySection, Type}; use pwasm_utils_12 as pwasm_utils; -pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result, PrepareError> { +pub(crate) fn prepare_contract( + original_code: &[u8], + config: &VMConfig, +) -> Result, PrepareError> { ContractModule::init(original_code, config)? .standardize_mem() .ensure_no_internal_memory()? diff --git a/runtime/near-vm-runner/src/runner.rs b/runtime/near-vm-runner/src/runner.rs index 016a63d3b7f..0eaec41d675 100644 --- a/runtime/near-vm-runner/src/runner.rs +++ b/runtime/near-vm-runner/src/runner.rs @@ -61,6 +61,7 @@ pub fn run( %method_name, ?vm_kind, burnt_gas = tracing::field::Empty, + %current_protocol_version, ) .entered();