-
Notifications
You must be signed in to change notification settings - Fork 442
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
Add check version wasm #1029
Add check version wasm #1029
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,10 @@ package wasm | |||||
import ( | ||||||
"context" | ||||||
"encoding/json" | ||||||
"fmt" | ||||||
"math/rand" | ||||||
"runtime/debug" | ||||||
"strings" | ||||||
|
||||||
"github.com/cosmos/cosmos-sdk/client" | ||||||
"github.com/cosmos/cosmos-sdk/codec" | ||||||
|
@@ -24,6 +27,7 @@ import ( | |||||
"github.com/CosmWasm/wasmd/x/wasm/keeper" | ||||||
"github.com/CosmWasm/wasmd/x/wasm/simulation" | ||||||
"github.com/CosmWasm/wasmd/x/wasm/types" | ||||||
wasmvm "github.com/CosmWasm/wasmvm" | ||||||
) | ||||||
|
||||||
var ( | ||||||
|
@@ -217,6 +221,8 @@ 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.PreRunE = chainPreRuns(checkLibwasmVersion, startCmd.PreRunE) | ||||||
} | ||||||
|
||||||
// ReadWasmConfig reads the wasm specifig configuration | ||||||
|
@@ -250,3 +256,50 @@ func ReadWasmConfig(opts servertypes.AppOptions) (types.WasmConfig, error) { | |||||
} | ||||||
return cfg, nil | ||||||
} | ||||||
|
||||||
func getExpectedLibwasmVersion() string { | ||||||
buildInfo, ok := debug.ReadBuildInfo() | ||||||
if !ok { | ||||||
panic("can't read build info") | ||||||
} | ||||||
for _, d := range buildInfo.Deps { | ||||||
if d.Path != "github.com/CosmWasm/wasmvm" { | ||||||
continue | ||||||
} | ||||||
if d.Replace != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent 🦅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you!!! |
||||||
return fmt.Sprintf(d.Replace.Version) | ||||||
} | ||||||
return fmt.Sprintf(d.Version) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have edited it |
||||||
} | ||||||
return "" | ||||||
} | ||||||
|
||||||
func checkLibwasmVersion(cmd *cobra.Command, args []string) error { | ||||||
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) | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
type preRunFn func(cmd *cobra.Command, args []string) error | ||||||
|
||||||
func chainPreRuns(pfns ...preRunFn) preRunFn { | ||||||
return func(cmd *cobra.Command, args []string) error { | ||||||
for _, pfn := range pfns { | ||||||
if pfn != nil { | ||||||
if err := pfn(cmd, args); err != nil { | ||||||
return err | ||||||
} | ||||||
} | ||||||
} | ||||||
return nil | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!!