From 15191836f10c10353ce57b0c079c323a68660a6d Mon Sep 17 00:00:00 2001 From: Matt Witkowski Date: Tue, 21 May 2024 15:47:00 -0400 Subject: [PATCH] Fix deprecated wasm issues. (#1988) * Fix usage of deprecated wasm. * Add router to wasm. * Add nolint check. * Remove govv1 beta subspace. * Simplified error check for genesis. --- CHANGELOG.md | 1 + app/app.go | 5 ++--- cmd/provenanced/cmd/genesis.go | 17 ++--------------- internal/provwasm/message_encoders.go | 8 ++++---- internal/provwasm/query_plugins.go | 11 ++++++----- internal/provwasm/stargate_whitelist.go | 8 ++++---- testutil/ibc/testchain.go | 3 +-- x/ibcratelimit/keeper/msg_server.go | 2 +- 8 files changed, 21 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c47079a5e1..8f7aa146f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Add the auto-cli commands and a few others newly added by the SDK [#1971](https://github.com/provenance-io/provenance/pull/1971). * Fix unit tests for ibcratelimit [#1977](https://github.com/provenance-io/provenance/pull/1977). * Fix unit tests for ibchooks [#1980](https://github.com/provenance-io/provenance/pull/1980). +* Replace deprecated wasm features [#1988](https://github.com/provenance-io/provenance/pull/1988). * Add `UpdateParams` and `Params` query rpc endpoints to modules. * `ibcratelimit` add `UpdateParams` endpoint and deprecate `GovUpdateParams` [#1984](https://github.com/provenance-io/provenance/pull/1984). diff --git a/app/app.go b/app/app.go index 4e55e909bc..886e75b974 100644 --- a/app/app.go +++ b/app/app.go @@ -84,7 +84,6 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -763,7 +762,7 @@ func New( name.NewAppModule(appCodec, app.NameKeeper, app.AccountKeeper, app.BankKeeper), attribute.NewAppModule(appCodec, app.AttributeKeeper, app.AccountKeeper, app.BankKeeper, app.NameKeeper), msgfeesmodule.NewAppModule(appCodec, app.MsgFeesKeeper, app.interfaceRegistry), - wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil, app.GetSubspace(wasmtypes.ModuleName)), // TODO[1760]: Need to pass message router instead of nil + wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), triggermodule.NewAppModule(appCodec, app.TriggerKeeper, app.AccountKeeper, app.BankKeeper), oracleModule, holdmodule.NewAppModule(appCodec, app.HoldKeeper), @@ -1376,7 +1375,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(minttypes.ModuleName) paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable()) + paramsKeeper.Subspace(govtypes.ModuleName) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(wasmtypes.ModuleName) diff --git a/cmd/provenanced/cmd/genesis.go b/cmd/provenanced/cmd/genesis.go index a5b97a9618..5445cf6650 100644 --- a/cmd/provenanced/cmd/genesis.go +++ b/cmd/provenanced/cmd/genesis.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -553,7 +552,8 @@ func AddGenesisMsgFeeCmd(defaultNodeHome string) *cobra.Command { msgType = "/" + msgType } - if err := checkMsgTypeValid(cdc.InterfaceRegistry(), msgType); err != nil { + _, err := cdc.InterfaceRegistry().Resolve(msgType) + if err != nil { return err } @@ -604,19 +604,6 @@ func AddGenesisMsgFeeCmd(defaultNodeHome string) *cobra.Command { return cmd } -func checkMsgTypeValid(registry types.InterfaceRegistry, msgTypeURL string) error { - msg, err := registry.Resolve(msgTypeURL) - if err != nil { - return err - } - - _, ok := msg.(sdk.Msg) - if !ok { - return fmt.Errorf("message type is not a sdk message: %v", msgTypeURL) - } - return err -} - // AddGenesisDefaultMarketCmd returns add-default-market cobra command. func AddGenesisDefaultMarketCmd(defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ diff --git a/internal/provwasm/message_encoders.go b/internal/provwasm/message_encoders.go index ddcc4214f5..7c8e3dc355 100644 --- a/internal/provwasm/message_encoders.go +++ b/internal/provwasm/message_encoders.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "cosmossdk.io/log" @@ -40,14 +40,14 @@ func (qr *EncoderRegistry) RegisterEncoder(route string, encoder Encoder) { } // MessageEncoders provides provenance message encoding support for smart contracts. -func MessageEncoders(registry *EncoderRegistry, logger log.Logger) *wasm.MessageEncoders { - return &wasm.MessageEncoders{ +func MessageEncoders(registry *EncoderRegistry, logger log.Logger) *wasmkeeper.MessageEncoders { + return &wasmkeeper.MessageEncoders{ Custom: customEncoders(registry, logger), } } // Custom provenance encoders for CosmWasm integration. -func customEncoders(registry *EncoderRegistry, logger log.Logger) wasm.CustomEncoder { +func customEncoders(registry *EncoderRegistry, logger log.Logger) wasmkeeper.CustomEncoder { return func(contract sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) { req := EncodeRequest{} if err := json.Unmarshal(msg, &req); err != nil { diff --git a/internal/provwasm/query_plugins.go b/internal/provwasm/query_plugins.go index c182bb5bee..6a3129b7e0 100644 --- a/internal/provwasm/query_plugins.go +++ b/internal/provwasm/query_plugins.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmvmtypes "github.com/CosmWasm/wasmvm/types" abci "github.com/cometbft/cometbft/abci/types" @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/gogoproto/proto" ) // The maximum querier result size allowed, ~10MB. @@ -43,15 +44,15 @@ func (qr *QuerierRegistry) RegisterQuerier(route string, querier Querier) { } // QueryPlugins provides provenance query support for smart contracts. -func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter, codec codec.Codec) *wasm.QueryPlugins { - return &wasm.QueryPlugins{ +func QueryPlugins(registry *QuerierRegistry, queryRouter baseapp.GRPCQueryRouter, codec codec.Codec) *wasmkeeper.QueryPlugins { + return &wasmkeeper.QueryPlugins{ Custom: customPlugins(registry), Stargate: StargateQuerier(queryRouter, codec), } } // Custom provenance queriers for CosmWasm integration. -func customPlugins(registry *QuerierRegistry) wasm.CustomQuerier { +func customPlugins(registry *QuerierRegistry) wasmkeeper.CustomQuerier { return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { req := QueryRequest{} if err := json.Unmarshal(request, &req); err != nil { @@ -114,7 +115,7 @@ func StargateQuerier(queryRouter baseapp.GRPCQueryRouter, cdc codec.Codec) func( // ConvertProtoToJsonMarshal unmarshals the given bytes into a proto message and then marshals it to json. // This is done so that clients calling stargate queries do not need to define their own proto unmarshalers, // being able to use response directly by json marshaling, which is supported in cosmwasm. -func ConvertProtoToJSONMarshal(protoResponseType codec.ProtoMarshaler, bz []byte, cdc codec.Codec) ([]byte, error) { +func ConvertProtoToJSONMarshal(protoResponseType proto.Message, bz []byte, cdc codec.Codec) ([]byte, error) { // unmarshal binary into stargate response data structure err := cdc.Unmarshal(bz, protoResponseType) if err != nil { diff --git a/internal/provwasm/stargate_whitelist.go b/internal/provwasm/stargate_whitelist.go index a6ba4cd870..5c294bc6d4 100644 --- a/internal/provwasm/stargate_whitelist.go +++ b/internal/provwasm/stargate_whitelist.go @@ -6,13 +6,13 @@ import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" - "github.com/cosmos/cosmos-sdk/codec" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/gogoproto/proto" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" attributetypes "github.com/provenance-io/provenance/x/attribute/types" @@ -141,19 +141,19 @@ func init() { // GetWhitelistedQuery returns the whitelisted query at the provided path. // If the query does not exist, or it was setup wrong by the chain, this returns an error. -func GetWhitelistedQuery(queryPath string) (codec.ProtoMarshaler, error) { +func GetWhitelistedQuery(queryPath string) (proto.Message, error) { protoResponseAny, isWhitelisted := stargateWhitelist.Load(queryPath) if !isWhitelisted { return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("'%s' path is not allowed from the contract", queryPath)} } - protoResponseType, ok := protoResponseAny.(codec.ProtoMarshaler) + protoResponseType, ok := protoResponseAny.(proto.Message) if !ok { return nil, wasmvmtypes.Unknown{} } return protoResponseType, nil } -func setWhitelistedQuery(queryPath string, protoType codec.ProtoMarshaler) { +func setWhitelistedQuery(queryPath string, protoType proto.Message) { stargateWhitelist.Store(queryPath, protoType) } diff --git a/testutil/ibc/testchain.go b/testutil/ibc/testchain.go index ea7d984bcd..503813cb20 100644 --- a/testutil/ibc/testchain.go +++ b/testutil/ibc/testchain.go @@ -160,9 +160,8 @@ func SignAndDeliver( txCfg client.TxConfig, app *baseapp.BaseApp, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, _ bool, blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey, ) (*abci.ResponseFinalizeBlock, error) { - // tb.Helper() tx, err := simtestutil.GenSignedMockTx( - rand.New(rand.NewSource(time.Now().UnixNano())), + rand.New(rand.NewSource(1)), txCfg, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, diff --git a/x/ibcratelimit/keeper/msg_server.go b/x/ibcratelimit/keeper/msg_server.go index 62535cc2dc..4162d7a751 100644 --- a/x/ibcratelimit/keeper/msg_server.go +++ b/x/ibcratelimit/keeper/msg_server.go @@ -24,7 +24,7 @@ var _ ibcratelimit.MsgServer = MsgServer{} // GovUpdateParams is a governance proposal endpoint for updating the ibcratelimit module's params. // -//lint:ignore SA1019 Suppress warning for deprecated MsgGovUpdateParamsRequest usage +//nolint:staticcheck // SA1019 Suppress warning for deprecated MsgGovUpdateParamsRequest usage func (k MsgServer) GovUpdateParams(_ context.Context, _ *ibcratelimit.MsgGovUpdateParamsRequest) (*ibcratelimit.MsgGovUpdateParamsResponse, error) { return nil, errors.New("deprecated and unusable") }