Skip to content

Commit

Permalink
register the key tables in the app.go
Browse files Browse the repository at this point in the history
  • Loading branch information
charleenfei committed Sep 25, 2023
1 parent 18cd60d commit d803655
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error {
// MigrateParams migrates the controller submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
if m.keeper != nil {
// set KeyTable if it has not already been set
if !m.keeper.legacySubspace.HasKeyTable() {
m.keeper.legacySubspace = m.keeper.legacySubspace.WithKeyTable(controllertypes.ParamKeyTable())
}

var params controllertypes.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package keeper_test

import (
"fmt"
"reflect"

"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/codec"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
Expand Down Expand Up @@ -93,15 +87,8 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
"success: default params",
func() {
params := icacontrollertypes.DefaultParams()
sk := suite.chainA.GetSimApp().GetKey(paramtypes.StoreKey)
store := suite.chainA.GetContext().KVStore(sk)
controllerStore := prefix.NewStore(store, append([]byte(icacontrollertypes.SubModuleName), '/'))
enabled := reflect.Indirect(reflect.ValueOf(params.ControllerEnabled)).Interface()
aminoCodec := codec.NewLegacyAmino()
enabledBz, err := aminoCodec.MarshalJSON(enabled)
suite.Require().NoError(err)

controllerStore.Set(icacontrollertypes.KeyControllerEnabled, enabledBz)
subspace := suite.chainA.GetSimApp().GetSubspace(icacontrollertypes.SubModuleName) // get subspace
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
icacontrollertypes.DefaultParams(),
},
Expand Down
4 changes: 0 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ func NewMigrator(k *Keeper) Migrator {
// MigrateParams migrates the host submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
if m.keeper != nil {
if !m.keeper.legacySubspace.HasKeyTable() {
m.keeper.legacySubspace = m.keeper.legacySubspace.WithKeyTable(types.ParamKeyTable())
}

var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

Expand Down
23 changes: 2 additions & 21 deletions modules/apps/27-interchain-accounts/host/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package keeper_test

import (
"fmt"
"reflect"

"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/codec"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -23,21 +17,8 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
"success: default params",
func() {
params := icahosttypes.DefaultParams()
sk := suite.chainA.GetSimApp().GetKey(paramtypes.StoreKey)
store := suite.chainA.GetContext().KVStore(sk)
hostStore := prefix.NewStore(store, append([]byte(icahosttypes.SubModuleName), '/'))
enabled := reflect.Indirect(reflect.ValueOf(params.HostEnabled)).Interface()
aminoCodec := codec.NewLegacyAmino()
enabledBz, err := aminoCodec.MarshalJSON(enabled)
suite.Require().NoError(err)

hostStore.Set(icahosttypes.KeyHostEnabled, enabledBz)

allowList := reflect.Indirect(reflect.ValueOf(params.AllowMessages)).Interface()
allowListBz, err := aminoCodec.MarshalJSON(allowList)
suite.Require().NoError(err)

hostStore.Set(icahosttypes.KeyAllowMessages, allowListBz)
subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
icahosttypes.DefaultParams(),
},
Expand Down
5 changes: 0 additions & 5 deletions modules/apps/transfer/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func NewMigrator(keeper Keeper) Migrator {

// MigrateParams migrates the transfer module's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
// set KeyTable if it has not already been set
if !m.keeper.legacySubspace.HasKeyTable() {
m.keeper.legacySubspace = m.keeper.legacySubspace.WithKeyTable(types.ParamKeyTable())
}

var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

Expand Down
21 changes: 2 additions & 19 deletions modules/apps/transfer/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package keeper_test

import (
"fmt"
"reflect"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

transferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand All @@ -28,21 +24,8 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
"success: default params",
func() {
params := transfertypes.DefaultParams()
sk := suite.chainA.GetSimApp().GetKey(paramtypes.StoreKey)
store := suite.chainA.GetContext().KVStore(sk)
transferStore := prefix.NewStore(store, append([]byte(transfertypes.ModuleName), '/'))
receiveEnabled := reflect.Indirect(reflect.ValueOf(params.ReceiveEnabled)).Interface()
aminoCodec := codec.NewLegacyAmino()
receiveEnabledBz, err := aminoCodec.MarshalJSON(receiveEnabled)
suite.Require().NoError(err)

transferStore.Set(transfertypes.KeyReceiveEnabled, receiveEnabledBz)

sendEnabled := reflect.Indirect(reflect.ValueOf(params.SendEnabled)).Interface()
sendEnabledBz, err := aminoCodec.MarshalJSON(sendEnabled)
suite.Require().NoError(err)

transferStore.Set(transfertypes.KeySendEnabled, sendEnabledBz)
subspace := suite.chainA.GetSimApp().GetSubspace(transfertypes.ModuleName)
subspace.SetParamSet(suite.chainA.GetContext(), &params) // set params
},
transfertypes.DefaultParams(),
},
Expand Down
5 changes: 0 additions & 5 deletions modules/core/02-client/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
// This migration takes the parameters that are currently stored and managed by x/params
// and stores them directly in the ibc module's state.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
// set KeyTable if it has not already been set
if !m.keeper.legacySubspace.HasKeyTable() {
m.keeper.legacySubspace = m.keeper.legacySubspace.WithKeyTable(types.ParamKeyTable())
}

var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)
if err := params.Validate(); err != nil {
Expand Down
18 changes: 2 additions & 16 deletions modules/core/02-client/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package keeper_test

import (
"reflect"

"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/codec"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand All @@ -24,15 +17,8 @@ func (suite *KeeperTestSuite) TestMigrateParams() {
"success: default params",
func() {
params := types.DefaultParams()
sk := suite.chainA.GetSimApp().GetKey(paramtypes.StoreKey)
store := suite.chainA.GetContext().KVStore(sk)
clientStore := prefix.NewStore(store, append([]byte(ibcexported.ModuleName), '/'))
v := reflect.Indirect(reflect.ValueOf(params.AllowedClients)).Interface()
aminoCodec := codec.NewLegacyAmino()
bz, err := aminoCodec.MarshalJSON(v)
suite.Require().NoError(err)

clientStore.Set(types.KeyAllowedClients, bz)
subspace := suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName)
subspace.SetParamSet(suite.chainA.GetContext(), &params)
},
types.DefaultParams(),
},
Expand Down
5 changes: 0 additions & 5 deletions modules/core/03-connection/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
// This migration takes the parameters that are currently stored and managed by x/params
// and stores them directly in the ibc module's state.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
// set KeyTable if it has not already been set
if !m.keeper.legacySubspace.HasKeyTable() {
m.keeper.legacySubspace = m.keeper.legacySubspace.WithKeyTable(types.ParamKeyTable())
}

var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)
if err := params.Validate(); err != nil {
Expand Down
19 changes: 2 additions & 17 deletions modules/core/03-connection/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package keeper_test

import (
"reflect"

"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/codec"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/cosmos/ibc-go/v8/modules/core/03-connection/keeper"
"github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand All @@ -23,17 +16,9 @@ func (suite *KeeperTestSuite) TestMigrateParams() {
{
"success: default params",
func() {
// set old params via direct store manipulation in order to make sure that initializing a keytable works correctly in the migration handler
params := types.DefaultParams()
sk := suite.chainA.GetSimApp().GetKey(paramtypes.StoreKey)
store := suite.chainA.GetContext().KVStore(sk)
connectionStore := prefix.NewStore(store, append([]byte(ibcexported.ModuleName), '/'))
v := reflect.Indirect(reflect.ValueOf(params.MaxExpectedTimePerBlock)).Interface()
aminoCodec := codec.NewLegacyAmino()
bz, err := aminoCodec.MarshalJSON(v)
suite.Require().NoError(err)

connectionStore.Set(types.KeyMaxExpectedTimePerBlock, bz)
subspace := suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName)
subspace.SetParamSet(suite.chainA.GetContext(), &params)
},
types.DefaultParams(),
},
Expand Down
2 changes: 0 additions & 2 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectionkeeper "github.com/cosmos/ibc-go/v8/modules/core/03-connection/keeper"
// connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
portkeeper "github.com/cosmos/ibc-go/v8/modules/core/05-port/keeper"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
Expand Down Expand Up @@ -45,7 +44,6 @@ func NewKeeper(
stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper,
scopedKeeper capabilitykeeper.ScopedKeeper, authority string,
) *Keeper {
// register paramSpace at top level keeper
// panic if any of the keepers passed in is empty
if isEmpty(stakingKeeper) {
panic(errors.New("cannot initialize IBC keeper: empty staking keeper"))
Expand Down
14 changes: 8 additions & 6 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import (
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -1005,12 +1006,13 @@ func BlockedAddresses() map[string]bool {
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

// TODO: ibc module subspaces can be removed after migration of params
// https://github.com/cosmos/ibc-go/issues/2010
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
// register the key tables for legacy param subspaces
keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

return paramsKeeper
}
Expand Down

0 comments on commit d803655

Please sign in to comment.