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: avoid panic when migrate param for newly added host (backport #6167) #6192

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (apps/27-interchain-accounts) [\#6167](https://github.com/cosmos/ibc-go/pull/6167) Fixed an edge case bug where migrating params for a pre-existing ica module which implemented controller functionality only could panic when migrating params for newly added host, and align controller param migration with host.

## [v8.2.0](https://github.com/cosmos/ibc-go/releases/tag/v8.2.0) - 2024-04-05

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ 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 {
var params controllertypes.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

params := controllertypes.DefaultParams()
if m.keeper.legacySubspace != nil {
m.keeper.legacySubspace.GetParamSetIfExists(ctx, &params)
}
m.keeper.SetParams(ctx, params)
m.keeper.Logger(ctx).Info("successfully migrated ica/controller submodule to self-manage params")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
},
icacontrollertypes.DefaultParams(),
},
{
"success: no legacy params pre-migration",
func() {
suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
suite.chainA.Codec,
suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey),
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.PortKeeper,
suite.chainA.GetSimApp().ScopedICAControllerKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
suite.chainA.GetSimApp().ICAControllerKeeper.GetAuthority(),
)
},
icacontrollertypes.DefaultParams(),
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ 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 {
var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

params := types.DefaultParams()
if m.keeper.legacySubspace != nil {
m.keeper.legacySubspace.GetParamSetIfExists(ctx, &params)
}
if err := params.Validate(); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package keeper_test
import (
"fmt"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/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 @@ -22,6 +25,24 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
},
icahosttypes.DefaultParams(),
},
{
"success: no legacy params pre-migration",
func() {
suite.chainA.GetSimApp().ICAHostKeeper = icahostkeeper.NewKeeper(
suite.chainA.Codec,
suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey),
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCFeeKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.PortKeeper,
suite.chainA.GetSimApp().AccountKeeper,
suite.chainA.GetSimApp().ScopedICAHostKeeper,
suite.chainA.GetSimApp().MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
},
icahosttypes.DefaultParams(),
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ type PortKeeper interface {
// ParamSubspace defines the expected Subspace interface for module parameters.
type ParamSubspace interface {
GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet)
GetParamSetIfExists(ctx sdk.Context, ps paramtypes.ParamSet)
}
Loading