Skip to content

Commit

Permalink
misc cleanups from doing #8323 (#8875)
Browse files Browse the repository at this point in the history
* misc cleanups from doing #8323

* cargo fmt
  • Loading branch information
Ekleog-NEAR authored and nikurt committed Apr 28, 2023
1 parent 79353d4 commit 858be61
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
3 changes: 3 additions & 0 deletions chain/client/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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()));

Expand Down
7 changes: 3 additions & 4 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct VMLimitConfig {

/// How tall the stack is allowed to grow?
///
/// See <https://wiki.parity.io/WebAssembly-StackHeight> to find out
/// how the stack frame cost is calculated.
/// See <https://wiki.parity.io/WebAssembly-StackHeight> 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`].
Expand All @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions runtime/near-vm-logic/src/gas_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result<Vec<u

#[cfg(test)]
mod tests {
use assert_matches::assert_matches;

use super::*;
use assert_matches::assert_matches;

fn parse_and_prepare_wat(wat: &str) -> Result<Vec<u8>, PrepareError> {
let wasm = wat::parse_str(wat).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion runtime/near-vm-runner/src/prepare/prepare_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>, PrepareError> {
pub(crate) fn prepare_contract(
original_code: &[u8],
config: &VMConfig,
) -> Result<Vec<u8>, PrepareError> {
ContractModule::init(original_code, config)?
.standardize_mem()
.ensure_no_internal_memory()?
Expand Down
1 change: 1 addition & 0 deletions runtime/near-vm-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub fn run(
%method_name,
?vm_kind,
burnt_gas = tracing::field::Empty,
%current_protocol_version,
)
.entered();

Expand Down

0 comments on commit 858be61

Please sign in to comment.