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

Support msg update params gov proposal #1247

Merged
merged 14 commits into from
Mar 15, 2023
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func NewWasmApp(
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). //This should be removed. It is still in place to avoid failures of modules that have not yet been upgraded.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Thanks for adding this

AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

Expand Down Expand Up @@ -588,7 +588,6 @@ func NewWasmApp(
app.WasmKeeper = wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
app.GetSubspace(wasm.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -602,6 +601,7 @@ func NewWasmApp(
wasmDir,
wasmConfig,
availableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)

Expand Down Expand Up @@ -678,7 +678,7 @@ func NewWasmApp(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter()),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(paramstypes.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
Expand Down
1 change: 0 additions & 1 deletion cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"

dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/log"
Expand Down
38 changes: 38 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
- [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse)
- [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig)
- [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse)
- [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#cosmwasm.wasm.v1.MsgUpdateParamsResponse)

- [Msg](#cosmwasm.wasm.v1.Msg)

Expand Down Expand Up @@ -1551,6 +1553,39 @@ MsgUpdateInstantiateConfigResponse returns empty data




<a name="cosmwasm.wasm.v1.MsgUpdateParams"></a>

### MsgUpdateParams
MsgUpdateParams is the Msg/UpdateParams request type.

Since: 0.40


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `params` | [Params](#cosmwasm.wasm.v1.Params) | | params defines the x/wasm parameters to update.

NOTE: All parameters must be supplied. |






<a name="cosmwasm.wasm.v1.MsgUpdateParamsResponse"></a>

### MsgUpdateParamsResponse
MsgUpdateParamsResponse defines the response structure for executing a
MsgUpdateParams message.

Since: 0.40





<!-- end messages -->

<!-- end enums -->
Expand All @@ -1573,6 +1608,9 @@ Msg defines the wasm Msg service.
| `UpdateAdmin` | [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin) | [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse) | UpdateAdmin sets a new admin for a smart contract | |
| `ClearAdmin` | [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin) | [MsgClearAdminResponse](#cosmwasm.wasm.v1.MsgClearAdminResponse) | ClearAdmin removes any admin stored for a smart contract | |
| `UpdateInstantiateConfig` | [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig) | [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse) | UpdateInstantiateConfig updates instantiate config for a smart contract | |
| `UpdateParams` | [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#cosmwasm.wasm.v1.MsgUpdateParamsResponse) | UpdateParams defines a governance operation for updating the x/wasm module parameters. The authority is defined in the keeper.

Since: 0.40 | |

<!-- end services -->

Expand Down
29 changes: 28 additions & 1 deletion proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "cosmwasm/wasm/v1/types.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/CosmWasm/wasmd/x/wasm/types";
option (gogoproto.goproto_getters_all) = false;
Expand Down Expand Up @@ -32,6 +33,11 @@ service Msg {
// UpdateInstantiateConfig updates instantiate config for a smart contract
rpc UpdateInstantiateConfig(MsgUpdateInstantiateConfig)
returns (MsgUpdateInstantiateConfigResponse);
// UpdateParams defines a governance operation for updating the x/wasm
// module parameters. The authority is defined in the keeper.
//
// Since: 0.40
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgStoreCode submit Wasm code to the system
Expand Down Expand Up @@ -206,4 +212,25 @@ message MsgUpdateInstantiateConfig {
}

// MsgUpdateInstantiateConfigResponse returns empty data
message MsgUpdateInstantiateConfigResponse {}
message MsgUpdateInstantiateConfigResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: 0.40
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/wasm parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 nice


// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: 0.40
message MsgUpdateParamsResponse {}
18 changes: 18 additions & 0 deletions x/wasm/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
6 changes: 5 additions & 1 deletion x/wasm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ type ValidatorSetSource interface {
// CONTRACT: all types of accounts must have been already initialized/created
func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]abci.ValidatorUpdate, error) {
contractKeeper := NewGovPermissionKeeper(keeper)
keeper.SetParams(ctx, data.Params)
err := keeper.SetParams(ctx, data.Params)
if err != nil {
return nil, errorsmod.Wrapf(err, "set params")
}

var maxCodeID uint64
for i, code := range data.Codes {
err := keeper.importCode(ctx, code.CodeID, code.CodeInfo, code.CodeBytes)
Expand Down
59 changes: 26 additions & 33 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

dbm "github.com/cometbft/cometbft-db"
Expand All @@ -21,9 +22,8 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
Expand All @@ -36,7 +36,7 @@ import (
const firstCodeID = 1

func TestGenesisExportImport(t *testing.T) {
wasmKeeper, srcCtx, srcStoreKeys := setupKeeper(t)
wasmKeeper, srcCtx := setupKeeper(t)
contractKeeper := NewGovPermissionKeeper(wasmKeeper)

wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGenesisExportImport(t *testing.T) {
require.NoError(t, err)

// setup new instances
dstKeeper, dstCtx, dstStoreKeys := setupKeeper(t)
dstKeeper, dstCtx := setupKeeper(t)

// reset contract code index in source DB for comparison with dest DB
wasmKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info wasmTypes.ContractInfo) bool {
Expand All @@ -124,23 +124,22 @@ func TestGenesisExportImport(t *testing.T) {
InitGenesis(dstCtx, dstKeeper, importState)

// compare whole DB
for j := range srcStoreKeys {
srcIT := srcCtx.KVStore(srcStoreKeys[j]).Iterator(nil, nil)
dstIT := dstCtx.KVStore(dstStoreKeys[j]).Iterator(nil, nil)

for i := 0; srcIT.Valid(); i++ {
require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %x", srcStoreKeys[j].Name(), srcIT.Key())
require.Equal(t, srcIT.Key(), dstIT.Key(), i)
require.Equal(t, srcIT.Value(), dstIT.Value(), "[%s] element (%d): %X", srcStoreKeys[j].Name(), i, srcIT.Key())
dstIT.Next()
srcIT.Next()
}
if !assert.False(t, dstIT.Valid()) {
t.Fatalf("dest Iterator still has key :%X", dstIT.Key())
}
srcIT.Close()
dstIT.Close()

srcIT := srcCtx.KVStore(wasmKeeper.storeKey).Iterator(nil, nil)
dstIT := dstCtx.KVStore(dstKeeper.storeKey).Iterator(nil, nil)

for i := 0; srcIT.Valid(); i++ {
require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %x", wasmKeeper.storeKey.Name(), srcIT.Key())
require.Equal(t, srcIT.Key(), dstIT.Key(), i)
require.Equal(t, srcIT.Value(), dstIT.Value(), "[%s] element (%d): %X", wasmKeeper.storeKey.Name(), i, srcIT.Key())
dstIT.Next()
srcIT.Next()
}
if !assert.False(t, dstIT.Valid()) {
t.Fatalf("dest Iterator still has key :%X", dstIT.Key())
}
srcIT.Close()
dstIT.Close()
}

func TestGenesisInit(t *testing.T) {
Expand Down Expand Up @@ -458,7 +457,7 @@ func TestGenesisInit(t *testing.T) {
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
keeper, ctx, _ := setupKeeper(t)
keeper, ctx := setupKeeper(t)

require.NoError(t, types.ValidateGenesis(spec.src))
_, gotErr := InitGenesis(ctx, keeper, spec.src)
Expand Down Expand Up @@ -538,7 +537,7 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
{"id_key": "BGxhc3RDb250cmFjdElk", "value": "3"}
]
}`
keeper, ctx, _ := setupKeeper(t)
keeper, ctx := setupKeeper(t)

wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
Expand Down Expand Up @@ -618,22 +617,17 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID))
}

func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []storetypes.StoreKey) {
func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {
t.Helper()
tempDir, err := os.MkdirTemp("", "wasm")
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(tempDir) })
var (
keyParams = sdk.NewKVStoreKey(paramtypes.StoreKey)
tkeyParams = sdk.NewTransientStoreKey(paramtypes.TStoreKey)
keyWasm = sdk.NewKVStoreKey(wasmTypes.StoreKey)
)

keyWasm := sdk.NewKVStoreKey(wasmTypes.StoreKey)

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(keyWasm, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, storetypes.StoreTypeTransient, db)
require.NoError(t, ms.LoadLatestVersion())

ctx := sdk.NewContext(ms, tmproto.Header{
Expand All @@ -651,12 +645,10 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []storetypes.StoreKey) {
v1beta1.RegisterInterfaces(encodingConfig.InterfaceRegistry)

wasmConfig := wasmTypes.DefaultWasmConfig()
pk := paramskeeper.NewKeeper(encodingConfig.Marshaler, encodingConfig.Amino, keyParams, tkeyParams)

srcKeeper := NewKeeper(
encodingConfig.Marshaler,
keyWasm,
pk.Subspace(wasmTypes.ModuleName).WithKeyTable(types.ParamKeyTable()),
authkeeper.AccountKeeper{},
&bankkeeper.BaseKeeper{},
stakingkeeper.Keeper{},
Expand All @@ -670,8 +662,9 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []storetypes.StoreKey) {
tempDir,
wasmConfig,
AvailableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
return &srcKeeper, ctx, []storetypes.StoreKey{keyWasm, keyParams}
return &srcKeeper, ctx
}

type StakingKeeperMock struct {
Expand Down
42 changes: 31 additions & 11 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/CosmWasm/wasmd/x/wasm/ioutils"
"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -99,34 +98,55 @@ type Keeper struct {
messenger Messenger
// queryGasLimit is the max wasmvm gas that can be spent on executing a query with a contract
queryGasLimit uint64
paramSpace paramtypes.Subspace
gasRegister GasRegister
maxQueryStackSize uint32
acceptedAccountTypes map[reflect.Type]struct{}
accountPruner AccountPruner
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
alpe marked this conversation as resolved.
Show resolved Hide resolved
}

func (k Keeper) getUploadAccessConfig(ctx sdk.Context) types.AccessConfig {
var a types.AccessConfig
k.paramSpace.Get(ctx, types.ParamStoreKeyUploadAccess, &a)
return a
return k.GetParams(ctx).CodeUploadAccess
}

func (k Keeper) getInstantiateAccessConfig(ctx sdk.Context) types.AccessType {
var a types.AccessType
k.paramSpace.Get(ctx, types.ParamStoreKeyInstantiateAccess, &a)
return a
return k.GetParams(ctx).InstantiateDefaultPermission
}

// GetParams returns the total set of wasm parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
var params types.Params
k.paramSpace.GetParamSet(ctx, &params)
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}

k.cdc.MustUnmarshal(bz, &params)
return params
}

func (k Keeper) SetParams(ctx sdk.Context, ps types.Params) {
k.paramSpace.SetParamSet(ctx, &ps)
// SetParams sets all wasm parameters.
func (k Keeper) SetParams(ctx sdk.Context, ps types.Params) error {
if err := ps.ValidateBasic(); err != nil {
return err
}

store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&ps)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)

return nil
}

// GetAuthority returns the x/wasm module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, checksum []byte, err error) {
Expand Down
Loading