From 72b02c799319ba3ce5d5d708c4281b8388c41a60 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 4 Oct 2023 11:27:23 +0200 Subject: [PATCH 1/2] imp: use expected interface for legacy params subspace --- .../controller/keeper/keeper.go | 5 ++--- .../controller/keeper/migrations.go | 9 ++++++++- .../apps/27-interchain-accounts/host/keeper/keeper.go | 5 ++--- .../27-interchain-accounts/host/keeper/migrations.go | 11 ++++++++++- .../27-interchain-accounts/types/expected_keepers.go | 6 ++++++ modules/apps/transfer/keeper/keeper.go | 5 ++--- modules/apps/transfer/keeper/migrations.go | 11 ++++++++++- modules/apps/transfer/types/expected_keepers.go | 6 ++++++ modules/core/02-client/keeper/keeper.go | 5 ++--- modules/core/02-client/keeper/migrations.go | 11 ++++++++++- modules/core/02-client/types/expected_keepers.go | 7 +++++++ modules/core/03-connection/keeper/keeper.go | 5 ++--- modules/core/03-connection/keeper/migrations.go | 11 ++++++++++- modules/core/03-connection/types/expected_keepers.go | 6 ++++++ modules/core/keeper/keeper.go | 3 +-- modules/core/types/expected_interfaces.go | 9 +++++++++ 16 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 modules/core/types/expected_interfaces.go diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 9af2a2a32cd..63e606c395e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" @@ -28,7 +27,7 @@ import ( type Keeper struct { storeKey storetypes.StoreKey cdc codec.Codec - legacySubspace paramtypes.Subspace + legacySubspace icatypes.ParamSubspace ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper portKeeper icatypes.PortKeeper @@ -44,7 +43,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts controller Keeper instance func NewKeeper( - cdc codec.Codec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, + cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string, ) Keeper { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index 705d93cb4b4..8d60b638d98 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -6,11 +6,13 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -55,8 +57,13 @@ 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 { + legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) + if !ok { + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) + } + var params controllertypes.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + legacySubpsace.GetParamSet(ctx, ¶ms) m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated ica/controller submodule to self-manage params") diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index da9ba160325..c426c4cc0cb 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" @@ -27,7 +26,7 @@ import ( type Keeper struct { storeKey storetypes.StoreKey cdc codec.Codec - legacySubspace paramtypes.Subspace + legacySubspace icatypes.ParamSubspace ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper @@ -45,7 +44,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts host Keeper instance func NewKeeper( - cdc codec.Codec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, + cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string, diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index 894018606c7..e064cc1f121 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -1,9 +1,13 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place state migrations. @@ -21,8 +25,13 @@ 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 { + legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) + if !ok { + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) + } + var params types.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + legacySubpsace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 3f8d542e891..c668e8e6783 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -32,3 +32,9 @@ type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability IsBound(ctx sdk.Context, portID string) bool } + +// ParamSubspace defines the expected Subspace interface for module parameters. +type ParamSubspace interface { + Get(ctx sdk.Context, key []byte, ptr interface{}) + Set(ctx sdk.Context, key []byte, param interface{}) +} diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 18ff530ae4b..04704a1f53b 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" tmbytes "github.com/cometbft/cometbft/libs/bytes" @@ -28,7 +27,7 @@ import ( type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec - legacySubspace paramtypes.Subspace + legacySubspace types.ParamSubspace ics4Wrapper porttypes.ICS4Wrapper channelKeeper types.ChannelKeeper @@ -46,7 +45,7 @@ type Keeper struct { func NewKeeper( cdc codec.BinaryCodec, key storetypes.StoreKey, - legacySubspace paramtypes.Subspace, + legacySubspace types.ParamSubspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index ae13ab7c80e..84d3d377027 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -3,9 +3,13 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -22,8 +26,13 @@ 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 { + legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) + if !ok { + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) + } + var params types.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + legacySubpsace.GetParamSet(ctx, ¶ms) m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated transfer app self-manage params") diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index 434c873d8cf..d94e2353629 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -54,3 +54,9 @@ type ConnectionKeeper interface { type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability } + +// ParamSubspace defines the expected Subspace interface for module parameters. +type ParamSubspace interface { + Get(ctx sdk.Context, key []byte, ptr interface{}) + Set(ctx sdk.Context, key []byte, param interface{}) +} diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index b1e63b943fe..a635fbef5a7 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cometbft/cometbft/light" @@ -32,13 +31,13 @@ import ( type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec - legacySubspace paramtypes.Subspace + legacySubspace types.ParamSubspace stakingKeeper types.StakingKeeper upgradeKeeper types.UpgradeKeeper } // NewKeeper creates a new NewKeeper instance -func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper { return Keeper{ storeKey: key, cdc: cdc, diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index 54620867928..f677278f66b 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -1,10 +1,14 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" v7 "github.com/cosmos/ibc-go/v8/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -37,8 +41,13 @@ 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 { + legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) + if !ok { + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) + } + var params types.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + legacySubpsace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err } diff --git a/modules/core/02-client/types/expected_keepers.go b/modules/core/02-client/types/expected_keepers.go index ea56078ed26..f6fd0b31514 100644 --- a/modules/core/02-client/types/expected_keepers.go +++ b/modules/core/02-client/types/expected_keepers.go @@ -6,6 +6,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -25,3 +26,9 @@ type UpgradeKeeper interface { SetUpgradedConsensusState(ctx context.Context, planHeight int64, bz []byte) error ScheduleUpgrade(ctx context.Context, plan upgradetypes.Plan) error } + +// ParamSubspace defines the expected Subspace interface for module parameters. +type ParamSubspace interface { + Get(ctx sdk.Context, key []byte, ptr interface{}) + Set(ctx sdk.Context, key []byte, param interface{}) +} diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index b4f8cf506c7..cd18555f56e 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" @@ -24,13 +23,13 @@ type Keeper struct { types.QueryServer storeKey storetypes.StoreKey - legacySubspace paramtypes.Subspace + legacySubspace types.ParamSubspace cdc codec.BinaryCodec clientKeeper types.ClientKeeper } // NewKeeper creates a new IBC connection Keeper instance -func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, ck types.ClientKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, ck types.ClientKeeper) Keeper { return Keeper{ storeKey: key, cdc: cdc, diff --git a/modules/core/03-connection/keeper/migrations.go b/modules/core/03-connection/keeper/migrations.go index 64b84e7885e..82b7cc58e89 100644 --- a/modules/core/03-connection/keeper/migrations.go +++ b/modules/core/03-connection/keeper/migrations.go @@ -1,10 +1,14 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" connectionv7 "github.com/cosmos/ibc-go/v8/modules/core/03-connection/migrations/v7" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -28,8 +32,13 @@ 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 { + legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) + if !ok { + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) + } + var params types.Params - m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) + legacySubpsace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err } diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index b470bf6520f..24890e6c561 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -18,3 +18,9 @@ type ClientKeeper interface { IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore } + +// ParamSubspace defines the expected Subspace interface for module parameters. +type ParamSubspace interface { + Get(ctx sdk.Context, key []byte, ptr interface{}) + Set(ctx sdk.Context, key []byte, param interface{}) +} diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 6831be40bda..08ee5dc027e 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -8,7 +8,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" @@ -40,7 +39,7 @@ type Keeper struct { // NewKeeper creates a new ibc Keeper func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace, stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, authority string, ) *Keeper { diff --git a/modules/core/types/expected_interfaces.go b/modules/core/types/expected_interfaces.go new file mode 100644 index 00000000000..1cf11cac2a2 --- /dev/null +++ b/modules/core/types/expected_interfaces.go @@ -0,0 +1,9 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +// ParamSubspace defines the expected Subspace interface for module parameters. +type ParamSubspace interface { + Get(ctx sdk.Context, key []byte, ptr interface{}) + Set(ctx sdk.Context, key []byte, param interface{}) +} From 16ecdb597c34085a86650609776fcdbc7d0d6dfc Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 4 Oct 2023 11:56:14 +0200 Subject: [PATCH 2/2] chore: define GetParamSet on expected interface and rm explicit type conversions --- .../controller/keeper/migrations.go | 9 +-------- .../27-interchain-accounts/host/keeper/migrations.go | 11 +---------- .../27-interchain-accounts/types/expected_keepers.go | 4 ++-- modules/apps/transfer/keeper/migrations.go | 11 +---------- modules/apps/transfer/types/expected_keepers.go | 4 ++-- modules/core/02-client/keeper/migrations.go | 11 +---------- modules/core/02-client/types/expected_keepers.go | 4 ++-- modules/core/03-connection/keeper/migrations.go | 11 +---------- modules/core/03-connection/types/expected_keepers.go | 4 ++-- modules/core/types/expected_interfaces.go | 8 +++++--- 10 files changed, 18 insertions(+), 59 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index 8d60b638d98..705d93cb4b4 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -6,13 +6,11 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -57,13 +55,8 @@ 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 { - legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) - } - var params controllertypes.Params - legacySubpsace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated ica/controller submodule to self-manage params") diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index e064cc1f121..894018606c7 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -1,13 +1,9 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place state migrations. @@ -25,13 +21,8 @@ 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 { - legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) - } - var params types.Params - legacySubpsace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index c668e8e6783..09cf6c22024 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" @@ -35,6 +36,5 @@ type PortKeeper interface { // ParamSubspace defines the expected Subspace interface for module parameters. type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) } diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index 84d3d377027..ae13ab7c80e 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -3,13 +3,9 @@ package keeper import ( "fmt" - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -26,13 +22,8 @@ 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 { - legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) - } - var params types.Params - legacySubpsace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated transfer app self-manage params") diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index d94e2353629..7aee3eace68 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" @@ -57,6 +58,5 @@ type PortKeeper interface { // ParamSubspace defines the expected Subspace interface for module parameters. type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) } diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index f677278f66b..54620867928 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -1,14 +1,10 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" v7 "github.com/cosmos/ibc-go/v8/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -41,13 +37,8 @@ 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 { - legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) - } - var params types.Params - legacySubpsace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err } diff --git a/modules/core/02-client/types/expected_keepers.go b/modules/core/02-client/types/expected_keepers.go index f6fd0b31514..6f4cd34557a 100644 --- a/modules/core/02-client/types/expected_keepers.go +++ b/modules/core/02-client/types/expected_keepers.go @@ -7,6 +7,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -29,6 +30,5 @@ type UpgradeKeeper interface { // ParamSubspace defines the expected Subspace interface for module parameters. type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) } diff --git a/modules/core/03-connection/keeper/migrations.go b/modules/core/03-connection/keeper/migrations.go index 82b7cc58e89..64b84e7885e 100644 --- a/modules/core/03-connection/keeper/migrations.go +++ b/modules/core/03-connection/keeper/migrations.go @@ -1,14 +1,10 @@ package keeper import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" connectionv7 "github.com/cosmos/ibc-go/v8/modules/core/03-connection/migrations/v7" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" - ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) // Migrator is a struct for handling in-place store migrations. @@ -32,13 +28,8 @@ 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 { - legacySubpsace, ok := m.keeper.legacySubspace.(paramtypes.Subspace) - if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", paramtypes.Subspace{}, m.keeper.legacySubspace) - } - var params types.Params - legacySubpsace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) if err := params.Validate(); err != nil { return err } diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index 24890e6c561..a37605b64cf 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -21,6 +22,5 @@ type ClientKeeper interface { // ParamSubspace defines the expected Subspace interface for module parameters. type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) } diff --git a/modules/core/types/expected_interfaces.go b/modules/core/types/expected_interfaces.go index 1cf11cac2a2..c6aca313696 100644 --- a/modules/core/types/expected_interfaces.go +++ b/modules/core/types/expected_interfaces.go @@ -1,9 +1,11 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) // ParamSubspace defines the expected Subspace interface for module parameters. type ParamSubspace interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Set(ctx sdk.Context, key []byte, param interface{}) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) }