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

Don't run checkLibwasmVersion automatically on start #1338

Merged
merged 7 commits into from
Apr 20, 2023
Merged
Changes from 5 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
31 changes: 26 additions & 5 deletions x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,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.
Expand Down Expand Up @@ -227,8 +228,9 @@ 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)
startCmd.PreRunE = chainPreRuns(CheckLibwasmVersion, startCmd.PreRunE)
}

// ReadWasmConfig reads the wasm specifig configuration
Expand Down Expand Up @@ -280,7 +282,26 @@ func getExpectedLibwasmVersion() string {
return ""
}

func checkLibwasmVersion(cmd *cobra.Command, args []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(cmd *cobra.Command, args []string) error {
webmaster128 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this back to private or leave it available to folks building their own AddModuleInitFlags?

skip, err := cmd.Flags().GetBool(flagWasmSkipWasmVMVersionCheck)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be nicer to move this switch to the caller code? Then CheckLibwasmVersion always performs a check (when called)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I went for the quickest solution. But with the method public, you have a point. The skip condition should be outside and the expected version passed.

if err != nil {
return fmt.Errorf("unable to read skip flag value: %w", err)
}
if skip {
cmd.Println("libwasmvm version check skipped")
return nil
}
wasmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
return fmt.Errorf("unable to retrieve libwasmversion %w", err)
Expand Down