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 #6167

Merged
merged 17 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (core) [\#6055](https://github.com/cosmos/ibc-go/pull/6055) Introduce a new interface `ConsensusHost` used to validate an IBC `ClientState` and `ConsensusState` against the host chain's underlying consensus parameters.

### Bug Fixes
* (apps/27-interchain-accounts) [\#6167](https://github.com/cosmos/ibc-go/pull/6167) Avoid panic when migrate param for newly added host.
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
18 changes: 16 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@
// 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 {
defaultParams := types.DefaultParams()
var params types.Params
m.keeper.legacySubspace.GetParamSet(ctx, &params)

ps := &params
for _, pair := range ps.ParamSetPairs() {
if !m.keeper.legacySubspace.Has(ctx, pair.Key) {
var value interface{}
if string(pair.Key) == "HostEnabled" {

Check failure on line 30 in modules/apps/27-interchain-accounts/host/keeper/migrations.go

View workflow job for this annotation

GitHub Actions / lint

ifElseChain: rewrite if-else to switch statement (gocritic)
value = defaultParams.HostEnabled
} else if string(pair.Key) == "AllowMessages" {
value = defaultParams.AllowMessages
} else {
continue
}
m.keeper.legacySubspace.Set(ctx, pair.Key, value)
}
m.keeper.legacySubspace.Get(ctx, pair.Key, pair.Value)
}
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
if err := params.Validate(); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
},
icahosttypes.DefaultParams(),
},
{
"success: no params",
func() {},
icahosttypes.DefaultParams(),
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ type PortKeeper interface {
// ParamSubspace defines the expected Subspace interface for module parameters.
type ParamSubspace interface {
GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet)
Has(ctx sdk.Context, key []byte) bool
Get(ctx sdk.Context, key []byte, ptr interface{})
Set(ctx sdk.Context, key []byte, value interface{})
}
Loading