From 5959b27ba0ccd0bd26d11f6e32729f3315b2cf9a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:11:52 +0100 Subject: [PATCH] Add migration for channel params (#5640) (#5650) * chore: adding channel params migration * chore: removed separate migration fn * chore: fix linter * chore: bump consensus * chore: fix linter again * chore: pr feedback --------- Co-authored-by: Carlos Rodriguez (cherry picked from commit 59ac9b25e7c1a7fd597ee82d1acf7799ecd25795) Co-authored-by: Cian Hatton --- modules/core/04-channel/keeper/migrations.go | 25 ++++++++++++++ .../core/04-channel/keeper/migrations_test.go | 34 +++++++++++++++++++ modules/core/module.go | 9 ++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 modules/core/04-channel/keeper/migrations.go create mode 100644 modules/core/04-channel/keeper/migrations_test.go diff --git a/modules/core/04-channel/keeper/migrations.go b/modules/core/04-channel/keeper/migrations.go new file mode 100644 index 00000000000..5bc0fcf0a41 --- /dev/null +++ b/modules/core/04-channel/keeper/migrations.go @@ -0,0 +1,25 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// MigrateParams migrates params to the default channel params. +func (m Migrator) MigrateParams(ctx sdk.Context) error { + params := channeltypes.DefaultParams() + m.keeper.SetParams(ctx, params) + m.keeper.Logger(ctx).Info("successfully migrated ibc channel params") + return nil +} diff --git a/modules/core/04-channel/keeper/migrations_test.go b/modules/core/04-channel/keeper/migrations_test.go new file mode 100644 index 00000000000..944aac49ce1 --- /dev/null +++ b/modules/core/04-channel/keeper/migrations_test.go @@ -0,0 +1,34 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// TestMigrateDefaultParams tests the migration for the channel params +func (suite *KeeperTestSuite) TestMigrateDefaultParams() { + testCases := []struct { + name string + expectedParams channeltypes.Params + }{ + { + "success: default params", + channeltypes.DefaultParams(), + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + ctx := suite.chainA.GetContext() + migrator := keeper.NewMigrator(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper) + err := migrator.MigrateParams(ctx) + suite.Require().NoError(err) + + params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) + suite.Require().Equal(tc.expectedParams, params) + }) + } +} diff --git a/modules/core/module.go b/modules/core/module.go index 27edd09a143..e7f6ebd4a94 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -22,6 +22,7 @@ import ( 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" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v8/modules/core/client/cli" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -157,6 +158,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { }); err != nil { panic(err) } + + channelMigrator := channelkeeper.NewMigrator(am.keeper.ChannelKeeper) + err := cfg.RegisterMigration(exported.ModuleName, 5, channelMigrator.MigrateParams) + if err != nil { + panic(err) + } } // InitGenesis performs genesis initialization for the ibc module. It returns @@ -177,7 +184,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 5 } +func (AppModule) ConsensusVersion() uint64 { return 6 } // BeginBlock returns the begin blocker for the ibc module. func (am AppModule) BeginBlock(ctx context.Context) error {