From 02f06d1c844296d9b7ea01289ea9e1842f404dd1 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Tue, 17 Oct 2023 07:09:16 +0000 Subject: [PATCH 1/2] runtime: "normalize" VMKind as soon as it is parsed (#9691) 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 { From 2f16f45a04eb7d3b0aa75c1415a11765f72b0f16 Mon Sep 17 00:00:00 2001 From: Akhilesh Singhania Date: Tue, 17 Oct 2023 14:47:18 +0200 Subject: [PATCH 2/2] nit: use correct type (#9696) Even though the types are just aliases, still use correct type definitions. --- chain/chain/src/test_utils/kv_runtime.rs | 2 +- chain/epoch-manager/src/adapter.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/chain/src/test_utils/kv_runtime.rs b/chain/chain/src/test_utils/kv_runtime.rs index c00f15cd294..844e7796eed 100644 --- a/chain/chain/src/test_utils/kv_runtime.rs +++ b/chain/chain/src/test_utils/kv_runtime.rs @@ -414,7 +414,7 @@ impl EpochManagerAdapter for MockEpochManager { self.hash_to_valset.write().unwrap().contains_key(epoch_id) } - fn num_shards(&self, _epoch_id: &EpochId) -> Result { + fn num_shards(&self, _epoch_id: &EpochId) -> Result { Ok(self.num_shards) } diff --git a/chain/epoch-manager/src/adapter.rs b/chain/epoch-manager/src/adapter.rs index 5df2deddf8d..a4674e33590 100644 --- a/chain/epoch-manager/src/adapter.rs +++ b/chain/epoch-manager/src/adapter.rs @@ -31,7 +31,7 @@ pub trait EpochManagerAdapter: Send + Sync { fn epoch_exists(&self, epoch_id: &EpochId) -> bool; /// Get current number of shards. - fn num_shards(&self, epoch_id: &EpochId) -> Result; + fn num_shards(&self, epoch_id: &EpochId) -> Result; /// Number of Reed-Solomon parts we split each chunk into. ///