From 053666a3f2621dd77bcbab25cc13dd76953eabd9 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 16 Oct 2023 17:03:59 +0300 Subject: [PATCH] runtime: "normalize" VMKind as soon as it is parsed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit People with M1 Macs run the neard node too, not just the test suites. Unfortunately a proper regression test for this is not obvious… I’ll think about it. (Possibly) Fixes #9665 --- core/primitives/src/runtime/config.rs | 4 +--- core/primitives/src/runtime/parameter_table.rs | 7 ++++--- runtime/near-vm-runner/src/tests.rs | 2 +- runtime/near-vm-runner/src/vm_kind.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/primitives/src/runtime/config.rs b/core/primitives/src/runtime/config.rs index 746d17515a1..81bcebe4bf0 100644 --- a/core/primitives/src/runtime/config.rs +++ b/core/primitives/src/runtime/config.rs @@ -39,10 +39,9 @@ impl RuntimeConfig { pub fn test() -> Self { let config_store = super::config_store::RuntimeConfigStore::new(None); - let mut wasm_config = near_vm_runner::logic::Config::clone( + let wasm_config = near_vm_runner::logic::Config::clone( &config_store.get_config(PROTOCOL_VERSION).wasm_config, ); - wasm_config.vm_kind = wasm_config.vm_kind.normalize(); RuntimeConfig { fees: RuntimeFeesConfig::test(), wasm_config, @@ -55,7 +54,6 @@ impl RuntimeConfig { let mut wasm_config = near_vm_runner::logic::Config::clone( &config_store.get_config(PROTOCOL_VERSION).wasm_config, ); - wasm_config.vm_kind = wasm_config.vm_kind.normalize(); wasm_config.make_free(); Self { fees: RuntimeFeesConfig::free(), diff --git a/core/primitives/src/runtime/parameter_table.rs b/core/primitives/src/runtime/parameter_table.rs index ca6724428df..d107badd176 100644 --- a/core/primitives/src/runtime/parameter_table.rs +++ b/core/primitives/src/runtime/parameter_table.rs @@ -170,9 +170,10 @@ impl TryFrom<&ParameterValue> for VMKind { fn try_from(value: &ParameterValue) -> Result { match value { - ParameterValue::String(v) => { - v.parse().map_err(|e| ValueConversionError::ParseVmKind(e, value.to_string())) - } + ParameterValue::String(v) => v + .parse() + .map(|v: VMKind| v.replace_with_wasmtime_if_unsupported()) + .map_err(|e| ValueConversionError::ParseVmKind(e, value.to_string())), _ => { Err(ValueConversionError::ParseType(std::any::type_name::(), value.clone())) } diff --git a/runtime/near-vm-runner/src/tests.rs b/runtime/near-vm-runner/src/tests.rs index 25121c587fe..346143d9ad9 100644 --- a/runtime/near-vm-runner/src/tests.rs +++ b/runtime/near-vm-runner/src/tests.rs @@ -36,7 +36,7 @@ impl crate::logic::Config { ExtVMKind::NearVm => VMKind::NearVm, ExtVMKind::Wasmtime => VMKind::Wasmtime, } - .normalize(), + .replace_with_wasmtime_if_unsupported(), disable_9393_fix: config.disable_9393_fix, storage_get_mode: match config.storage_get_mode { ExtStorageGetMode::Trie => StorageGetMode::Trie, diff --git a/runtime/near-vm-runner/src/vm_kind.rs b/runtime/near-vm-runner/src/vm_kind.rs index d66f87438f0..a472b7e67cb 100644 --- a/runtime/near-vm-runner/src/vm_kind.rs +++ b/runtime/near-vm-runner/src/vm_kind.rs @@ -32,7 +32,7 @@ pub enum VMKind { } impl VMKind { - pub fn normalize(self) -> Self { + pub fn replace_with_wasmtime_if_unsupported(self) -> Self { if cfg!(not(target_arch = "x86_64")) { Self::Wasmtime } else {