Skip to content

Commit

Permalink
chore: update wasmvm from 1.3 to 1.4 (#2310)
Browse files Browse the repository at this point in the history
* update wasmvm from 1.3 to 1.4

* fix the tests
  • Loading branch information
gsk967 authored Nov 2, 2023
1 parent 0a6a513 commit 27838da
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 139 deletions.
42 changes: 16 additions & 26 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -220,7 +221,7 @@ func init() {
icatypes.ModuleName: nil,

leveragetypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasm.ModuleName: {authtypes.Burner},
wasmtypes.ModuleName: {authtypes.Burner},

incentive.ModuleName: nil,
oracletypes.ModuleName: nil,
Expand Down Expand Up @@ -266,7 +267,7 @@ type UmeeApp struct {
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
WasmKeeper wasm.Keeper
WasmKeeper wasmkeeper.Keeper

IBCTransferKeeper ibctransferkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
Expand Down Expand Up @@ -295,7 +296,7 @@ type UmeeApp struct {
configurator module.Configurator

// wasm
wasmCfg wasm.Config
wasmCfg wasmtypes.WasmConfig
}

func init() {
Expand All @@ -316,8 +317,7 @@ func New(
homePath string,
invCheckPeriod uint,
appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *UmeeApp {
encCfg := MakeEncodingConfig()
Expand All @@ -340,7 +340,7 @@ func New(
ibcexported.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey,
leveragetypes.StoreKey, oracletypes.StoreKey,
uibc.StoreKey, ugov.StoreKey,
wasm.StoreKey,
wasmtypes.StoreKey,
incentive.StoreKey,
metoken.StoreKey,
consensusparamstypes.StoreKey, crisistypes.StoreKey,
Expand Down Expand Up @@ -389,7 +389,7 @@ func New(
app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
app.ScopedWasmKeeper = app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.ScopedWasmKeeper = app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
Expand Down Expand Up @@ -623,11 +623,6 @@ func New(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

// The wasm gov proposal types can be individually enabled
if len(wasmEnabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, wasmEnabledProposals))
}

govConfig := govtypes.DefaultConfig()
govConfig.MaxMetadataLen = 800
app.GovKeeper = govkeeper.NewKeeper(
Expand All @@ -645,20 +640,15 @@ func New(
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
// default available capabilities https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,umee"

// Register umee custom plugin to wasm
wasmOpts = append(uwasm.RegisterCustomPlugins(app.LeverageKeeper, app.OracleKeeper, app.IncentiveKeeper,
app.MetokenKeeperB), wasmOpts...)
// Register stargate queries
wasmOpts = append(wasmOpts, uwasm.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec)...)

app.WasmKeeper = wasm.NewKeeper(
availableCapabilities := strings.Join(AllCapabilities(), ",")
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand Down Expand Up @@ -760,7 +750,7 @@ func New(
oracletypes.ModuleName,
uibc.ModuleName,
ugov.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
incentive.ModuleName,
metoken.ModuleName,
}
Expand All @@ -778,7 +768,7 @@ func New(
leveragetypes.ModuleName,
uibc.ModuleName,
ugov.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
incentive.ModuleName,
metoken.ModuleName,
}
Expand All @@ -802,7 +792,7 @@ func New(
leveragetypes.ModuleName,
uibc.ModuleName,
ugov.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
incentive.ModuleName,
metoken.ModuleName,
}
Expand All @@ -818,7 +808,7 @@ func New(
leveragetypes.ModuleName,
uibc.ModuleName,
ugov.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
incentive.ModuleName,
metoken.ModuleName,
}
Expand Down Expand Up @@ -883,7 +873,7 @@ func New(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(txConfig, &app.wasmCfg, keys[wasm.StoreKey])
app.setAnteHandler(txConfig, &app.wasmCfg, keys[wasmtypes.StoreKey])
// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down Expand Up @@ -1148,7 +1138,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(leveragetypes.ModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)

return paramsKeeper
}
Expand Down
2 changes: 0 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func setup(withGenesis bool, invCheckPeriod uint) (*UmeeApp, GenesisState) {
DefaultNodeHome,
invCheckPeriod,
EmptyAppOptions{},
GetWasmEnabledProposals(),
EmptyWasmOpts,
)
if withGenesis {
Expand Down Expand Up @@ -411,7 +410,6 @@ func NewTestNetworkFixture() network.TestFixture {
val.GetCtx().Config.RootDir,
0,
EmptyAppOptions{},
GetWasmEnabledProposals(),
EmptyWasmOpts,
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
Expand Down
5 changes: 2 additions & 3 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cometbft/cometbft/libs/log"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icagenesis "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
Expand Down Expand Up @@ -63,7 +62,7 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
app.registerUpgrade("v4.2", upgradeInfo, uibc.ModuleName)
app.registerUpgrade4_3(upgradeInfo)
app.registerUpgrade("v4.4", upgradeInfo)
app.registerUpgrade("v5.0", upgradeInfo, ugov.ModuleName, wasm.ModuleName)
app.registerUpgrade("v5.0", upgradeInfo, ugov.ModuleName, wasmtypes.ModuleName)
app.registerUpgrade5_1(upgradeInfo)
app.registerUpgrade("v5.2", upgradeInfo) // v5.2 migration is not compatible with v6, so leaving default here.
app.registerUpgrade6(upgradeInfo)
Expand Down Expand Up @@ -96,7 +95,7 @@ func (app *UmeeApp) registerUpgrade6_2(upgradeInfo upgradetypes.Plan) {
keyTable = govv1.ParamKeyTable() //nolint: staticcheck // deprecated but required for upgrade
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint: staticcheck // deprecated but required for upgrade
case wasm.ModuleName:
case wasmtypes.ModuleName:
keyTable = wasmtypes.ParamKeyTable() //nolint: staticcheck // deprecated but required for upgrade
default:
// subspace not handled
Expand Down
51 changes: 15 additions & 36 deletions app/wasm.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
package app

import (
"strings"

"github.com/CosmWasm/wasmd/x/wasm"
)

// WasmProposalsEnabled enables all x/wasm proposals when it's value is "true"
// and EnableSpecificWasmProposals is empty. Otherwise, all x/wasm proposals
// are disabled.
const WasmProposalsEnabled = "true"
import wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

var (
// EnableSpecificWasmProposals, if set, must be comma-separated list of values
// that are all a subset of "EnableAllProposals", which takes precedence over
// WasmProposalsEnabled.
//
// See: https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificWasmProposals = ""

// EmptyWasmOpts defines a type alias for a list of wasm options.
EmptyWasmOpts []wasm.Option
EmptyWasmOpts []wasmkeeper.Option
)

// GetWasmEnabledProposals parses the WasmProposalsEnabled and
// EnableSpecificWasmProposals values to produce a list of enabled proposals to
// pass into the application.
func GetWasmEnabledProposals() []wasm.ProposalType {
if EnableSpecificWasmProposals == "" {
if WasmProposalsEnabled == "true" {
return wasm.EnableAllProposals
}
return wasm.DisableAllProposals
// AllCapabilities returns all capabilities available with the current wasmvm
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
// This functionality is going to be moved upstream: https://github.com/CosmWasm/wasmvm/issues/425
func AllCapabilities() []string {
return []string{
"iterator",
"staking",
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
"umee",
}

chunks := strings.Split(EnableSpecificWasmProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}

return proposals
}
3 changes: 1 addition & 2 deletions app/wasm/custom_plugins.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wasm

import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -28,7 +27,7 @@ func RegisterCustomPlugins(

messagePluginOpt := wasmkeeper.WithMessageHandlerDecorator(msg.NewMessagePlugin(leverageKeeper))

return []wasm.Option{
return []wasmkeeper.Option{
queryPluginOpt,
messagePluginOpt,
}
Expand Down
22 changes: 6 additions & 16 deletions app/wasm/test/cw20_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"gotest.tools/v3/assert"
Expand Down Expand Up @@ -129,9 +128,8 @@ type IntegrationTestSuite struct {
ctx sdk.Context
app *umeeapp.UmeeApp

wasmMsgServer wasmtypes.MsgServer
wasmQueryClient wasmtypes.QueryClient
wasmProposalHandler govv1.Handler
wasmMsgServer wasmtypes.MsgServer
wasmQueryClient wasmtypes.QueryClient

codeID uint64
contractAddr string
Expand Down Expand Up @@ -162,7 +160,6 @@ func (s *IntegrationTestSuite) SetupTest(t *testing.T) {
grpc := wasmkeeper.Querier(&app.WasmKeeper)
wasmtypes.RegisterQueryServer(queryHelper, grpc)
s.wasmQueryClient = wasmtypes.NewQueryClient(queryHelper)
s.wasmProposalHandler = wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, umeeapp.GetWasmEnabledProposals())
s.encfg = umeeapp.MakeEncodingConfig()
}

Expand All @@ -180,22 +177,15 @@ func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey
func (s *IntegrationTestSuite) cw20StoreCode(sender sdk.AccAddress, cwArtifacePath string) (codeId uint64) {
cw20Code, err := os.ReadFile(cwArtifacePath)
assert.NilError(s.T, err)
storeCodeProposal := wasmtypes.StoreCodeProposal{
Title: cwArtifacePath,
Description: cwArtifacePath,
RunAs: sender.String(),
storeCodeMsg := wasmtypes.MsgStoreCode{
Sender: sender.String(),
WASMByteCode: cw20Code,
InstantiatePermission: &wasmtypes.AllowEverybody,
}

err = s.wasmProposalHandler(s.ctx, &storeCodeProposal)
resp, err := s.wasmMsgServer.StoreCode(sdk.WrapSDKContext(s.ctx), &storeCodeMsg)
assert.NilError(s.T, err)

codes, err := s.wasmQueryClient.PinnedCodes(sdk.WrapSDKContext(s.ctx), &wasmtypes.QueryPinnedCodesRequest{})
assert.NilError(s.T, err)
assert.Equal(s.T, true, len(codes.CodeIDs) > 0)

return codes.CodeIDs[len(codes.CodeIDs)-1]
return resp.CodeID
}

func (s *IntegrationTestSuite) transfer(contracAddr string, amount uint64, from, to sdk.AccAddress) {
Expand Down
5 changes: 1 addition & 4 deletions cmd/umeed/cmd/app_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
stdlog "log"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (a appCreator) newApp(
minGasPrices := cast.ToString(appOpts.Get(server.FlagMinGasPrices))
mustMinUmeeGasPrice(minGasPrices)

var wasmOpts []wasm.Option
var wasmOpts []wasmkeeper.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}
Expand All @@ -97,7 +96,6 @@ func (a appCreator) newApp(
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
appOpts,
umeeapp.GetWasmEnabledProposals(),
wasmOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(minGasPrices),
Expand Down Expand Up @@ -153,7 +151,6 @@ func (a appCreator) appExport(
homePath,
uint(1),
appOpts,
umeeapp.GetWasmEnabledProposals(),
umeeapp.EmptyWasmOpts,
)

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.1.2
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.40.2
github.com/CosmWasm/wasmvm v1.3.0
github.com/CosmWasm/wasmd v0.43.0
github.com/CosmWasm/wasmvm v1.4.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
Expand Down Expand Up @@ -104,7 +104,7 @@ require (
github.com/containerd/continuity v0.3.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
Expand Down
Loading

0 comments on commit 27838da

Please sign in to comment.