Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: "normalize" VMKind as soon as it is parsed #9691

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions core/primitives/src/runtime/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
7 changes: 4 additions & 3 deletions core/primitives/src/runtime/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ impl TryFrom<&ParameterValue> for VMKind {

fn try_from(value: &ParameterValue) -> Result<Self, Self::Error> {
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::<VMKind>(), value.clone()))
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/vm_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down