Skip to content

Commit

Permalink
make a protocol change for the wasmer bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekleog-NEAR committed Jan 17, 2023
1 parent 92f8711 commit 0721823
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ fn wasmer2_stack_limit_default() -> i32 {
pub enum StackLimiterVersion {
/// Old, buggy version, don't use it unless specifically to support old protocol version.
V0,
/// What we use in today's protocol.
/// What we used in the wasmer2 era.
V1,
/// What we use in today's protocol.
V2,
}

impl StackLimiterVersion {
Expand Down Expand Up @@ -208,7 +210,7 @@ impl VMLimitConfig {
// NOTE: Stack height has to be 16K, otherwise Wasmer produces non-deterministic results.
// For experimentation try `test_stack_overflow`.
max_stack_height: 16 * 1024, // 16Kib of stack.
stack_limiter_version: StackLimiterVersion::V1,
stack_limiter_version: StackLimiterVersion::V2,
initial_memory_pages: 2u32.pow(10), // 64Mib of memory.
max_memory_pages: 2u32.pow(11), // 128Mib of memory.

Expand Down
1 change: 1 addition & 0 deletions core/primitives/res/runtime_configs/58.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stack_limiter_version: 1 -> 2
1 change: 1 addition & 0 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
// set read_cached_trie_node cost, decrease storage key limit
(53, include_config!("53.txt")),
(57, include_config!("57.txt")),
(58, include_config!("58.txt")),
];

/// Testnet parameters for versions <= 29, which (incorrectly) differed from mainnet parameters
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub const PEER_MIN_ALLOWED_PROTOCOL_VERSION: ProtocolVersion = STABLE_PROTOCOL_V
/// Current protocol version used on the mainnet.
/// Some features (e. g. FixStorageUsage) require that there is at least one epoch with exactly
/// the corresponding version
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 57;
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 58;

/// Largest protocol version supported by the current binary.
pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "nightly_protocol") {
Expand Down
9 changes: 7 additions & 2 deletions runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result<Vec<u
near_vm_logic::StackLimiterVersion::V1 => ContractModule::init(original_code, config)?
.scan_imports()?
.standardize_mem()
.ensure_no_internal_memory()?/* TODO: re-enable on non-wasmer2
.ensure_no_internal_memory()?
.inject_gas_metering()?
.inject_stack_height_metering()?// */
.inject_stack_height_metering()?
.into_wasm_code(),
near_vm_logic::StackLimiterVersion::V2 => ContractModule::init(original_code, config)? // TODO: completely get rid of pwasm-utils
.scan_imports()?
.standardize_mem()
.ensure_no_internal_memory()?
.into_wasm_code(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/tests/compile_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn test_limit_locals_global() {
])
.expects(&[
expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 8344766023 used gas 8344766023
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 8358752859 used gas 8358752859
"#]],
expect![[r#"
VMOutcome: balance 4 storage_usage 12 return data None burnt gas 0 used gas 0
Expand Down

0 comments on commit 0721823

Please sign in to comment.