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

Fix deprecated wasm issues. #1988

Merged
merged 12 commits into from
May 21, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 2 additions & 15 deletions cmd/provenanced/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions internal/provwasm/message_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions internal/provwasm/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/provwasm/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions testutil/ibc/testchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
2 changes: 1 addition & 1 deletion x/ibcratelimit/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Loading