From 1f474ec3e43290bce7aafd58e280088a50c76898 Mon Sep 17 00:00:00 2001 From: Simon Warta <2603011+webmaster128@users.noreply.github.com> Date: Thu, 20 Apr 2023 16:50:58 +0200 Subject: [PATCH 1/2] Don't run checkLibwasmVersion automatically on start (#1338) * Don't run checkLibwasmVersion automatically on start * Remove unused preRunFn, chainPreRuns * Add documentation to CheckLibwasmVersion * Add skip wasmvm version flag * Linter false positive * Review feedback * Pass expected version --------- Co-authored-by: Alex Peters (cherry picked from commit 09291688397078724f98f553ea251df180e53a41) # Conflicts: # x/wasm/module.go --- x/wasm/module.go | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/x/wasm/module.go b/x/wasm/module.go index 6fc956289..fbd9b88bb 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -39,9 +39,10 @@ var ( // Module init related flags const ( - flagWasmMemoryCacheSize = "wasm.memory_cache_size" - flagWasmQueryGasLimit = "wasm.query_gas_limit" - flagWasmSimulationGasLimit = "wasm.simulation_gas_limit" + flagWasmMemoryCacheSize = "wasm.memory_cache_size" + flagWasmQueryGasLimit = "wasm.query_gas_limit" + flagWasmSimulationGasLimit = "wasm.simulation_gas_limit" + flagWasmSkipWasmVMVersionCheck = "wasm.skip_wasmvm_version_check" //nolint:gosec ) // AppModuleBasic defines the basic application module used by the wasm module. @@ -230,8 +231,20 @@ func AddModuleInitFlags(startCmd *cobra.Command) { startCmd.Flags().Uint32(flagWasmMemoryCacheSize, defaults.MemoryCacheSize, "Sets the size in MiB (NOT bytes) of an in-memory cache for Wasm modules. Set to 0 to disable.") startCmd.Flags().Uint64(flagWasmQueryGasLimit, defaults.SmartQueryGasLimit, "Set the max gas that can be spent on executing a query with a Wasm contract") startCmd.Flags().String(flagWasmSimulationGasLimit, "", "Set the max gas that can be spent when executing a simulation TX") + startCmd.Flags().Bool(flagWasmSkipWasmVMVersionCheck, false, "Skip check that ensures that libwasmvm version (the Rust project) and wasmvm version (the Go project) match") - startCmd.PreRunE = chainPreRuns(checkLibwasmVersion, startCmd.PreRunE) + preCheck := func(cmd *cobra.Command, _ []string) error { + skip, err := cmd.Flags().GetBool(flagWasmSkipWasmVMVersionCheck) + if err != nil { + return fmt.Errorf("unable to read skip flag value: %w", err) + } + if skip { + cmd.Println("libwasmvm version check skipped") + return nil + } + return CheckLibwasmVersion(getExpectedLibwasmVersion()) + } + startCmd.PreRunE = chainPreRuns(preCheck, startCmd.PreRunE) } // ReadWasmConfig reads the wasm specifig configuration @@ -283,15 +296,29 @@ func getExpectedLibwasmVersion() string { return "" } +<<<<<<< HEAD func checkLibwasmVersion(_ *cobra.Command, _ []string) error { +======= +// CheckLibwasmVersion ensures that the libwasmvm version loaded at runtime matches the version +// of the github.com/CosmWasm/wasmvm dependency in go.mod. This us useful when dealing with +// shared libraries that are copied or moved from their default location, e.g. when building the node +// on one machine and deploying it to other machines. +// +// Usually the libwasmvm version (the Rust project) and wasmvm version (the Go project) match. However, +// there are situations in which this is not the case. This can be during development or if one of the +// two is patched. In such cases it is advised to not execute the check. +// +// An alternative method to obtain the libwasmvm version loaded at runtime is executing +// `wasmd query wasm libwasmvm-version`. +func CheckLibwasmVersion(wasmExpectedVersion string) error { + if wasmExpectedVersion == "" { + return fmt.Errorf("wasmvm module not exist") + } +>>>>>>> 09291688 (Don't run checkLibwasmVersion automatically on start (#1338)) wasmVersion, err := wasmvm.LibwasmvmVersion() if err != nil { return fmt.Errorf("unable to retrieve libwasmversion %w", err) } - wasmExpectedVersion := getExpectedLibwasmVersion() - if wasmExpectedVersion == "" { - return fmt.Errorf("wasmvm module not exist") - } if !strings.Contains(wasmExpectedVersion, wasmVersion) { return fmt.Errorf("libwasmversion mismatch. got: %s; expected: %s", wasmVersion, wasmExpectedVersion) } From f64cb13aedf14a6e496e904b9f968f3979c8c4de Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 21 Apr 2023 14:18:47 +0200 Subject: [PATCH 2/2] Fix conflicts --- x/wasm/module.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/wasm/module.go b/x/wasm/module.go index fbd9b88bb..423e2464f 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -296,9 +296,6 @@ func getExpectedLibwasmVersion() string { return "" } -<<<<<<< HEAD -func checkLibwasmVersion(_ *cobra.Command, _ []string) error { -======= // CheckLibwasmVersion ensures that the libwasmvm version loaded at runtime matches the version // of the github.com/CosmWasm/wasmvm dependency in go.mod. This us useful when dealing with // shared libraries that are copied or moved from their default location, e.g. when building the node @@ -314,7 +311,6 @@ func CheckLibwasmVersion(wasmExpectedVersion string) error { if wasmExpectedVersion == "" { return fmt.Errorf("wasmvm module not exist") } ->>>>>>> 09291688 (Don't run checkLibwasmVersion automatically on start (#1338)) wasmVersion, err := wasmvm.LibwasmvmVersion() if err != nil { return fmt.Errorf("unable to retrieve libwasmversion %w", err)