From f1d559bbb84e507b0983fac973f6c9747574b91c Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 12:03:28 +0000 Subject: [PATCH 1/6] chore: adding channel params migration --- e2e/tests/core/04-channel/upgrades_test.go | 1 + modules/core/04-channel/keeper/migrations.go | 32 +++++++++ .../core/04-channel/keeper/migrations_test.go | 65 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 modules/core/04-channel/keeper/migrations.go create mode 100644 modules/core/04-channel/keeper/migrations_test.go diff --git a/e2e/tests/core/04-channel/upgrades_test.go b/e2e/tests/core/04-channel/upgrades_test.go index 2e7a8a8f60c..b3cd671911a 100644 --- a/e2e/tests/core/04-channel/upgrades_test.go +++ b/e2e/tests/core/04-channel/upgrades_test.go @@ -11,6 +11,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" sdkmath "cosmossdk.io/math" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/e2e/testsuite" diff --git a/modules/core/04-channel/keeper/migrations.go b/modules/core/04-channel/keeper/migrations.go new file mode 100644 index 00000000000..16338068979 --- /dev/null +++ b/modules/core/04-channel/keeper/migrations.go @@ -0,0 +1,32 @@ +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 specified channel params. +func (m Migrator) MigrateParams(ctx sdk.Context, params channeltypes.Params) error { + m.keeper.SetParams(ctx, params) + if err := params.Validate(); err != nil { + return err + } + m.keeper.Logger(ctx).Info("successfully migrated channel params") + return nil +} + +// MigrateDefaultParams migrates params to the default channel params. +func (m Migrator) MigrateDefaultParams(ctx sdk.Context) error { + return m.MigrateParams(ctx, channeltypes.DefaultParams()) +} 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..d79b4efc81f --- /dev/null +++ b/modules/core/04-channel/keeper/migrations_test.go @@ -0,0 +1,65 @@ +package keeper_test + +import ( + "time" + + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// TestMigrateParams tests the migration for the channel params +func (suite *KeeperTestSuite) TestMigrateParams() { + testCases := []struct { + name string + expectedParams channeltypes.Params + }{ + { + "success: default params", + channeltypes.NewParams(channeltypes.NewTimeout(clienttypes.ZeroHeight(), uint64(time.Minute*20))), + }, + } + + 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, tc.expectedParams) + suite.Require().NoError(err) + + params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) + suite.Require().Equal(tc.expectedParams, params) + }) + } +} + +// 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.MigrateDefaultParams(ctx) + suite.Require().NoError(err) + + params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) + suite.Require().Equal(tc.expectedParams, params) + }) + } +} From 8bc988fb83cde40c2abee70d74fc6637fc87aa5f Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 12:10:21 +0000 Subject: [PATCH 2/6] chore: removed separate migration fn --- modules/core/04-channel/keeper/migrations.go | 12 +++---- .../core/04-channel/keeper/migrations_test.go | 33 +------------------ modules/core/module.go | 7 ++++ 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/modules/core/04-channel/keeper/migrations.go b/modules/core/04-channel/keeper/migrations.go index 16338068979..5d99902f3f6 100644 --- a/modules/core/04-channel/keeper/migrations.go +++ b/modules/core/04-channel/keeper/migrations.go @@ -16,17 +16,13 @@ func NewMigrator(keeper Keeper) Migrator { return Migrator{keeper: keeper} } -// MigrateParams migrates params to the specified channel params. -func (m Migrator) MigrateParams(ctx sdk.Context, params channeltypes.Params) error { - m.keeper.SetParams(ctx, params) +// MigrateParams migrates params to the default channel params. +func (m Migrator) MigrateParams(ctx sdk.Context) error { + params := channeltypes.DefaultParams() if err := params.Validate(); err != nil { return err } + m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated channel params") return nil } - -// MigrateDefaultParams migrates params to the default channel params. -func (m Migrator) MigrateDefaultParams(ctx sdk.Context) error { - return m.MigrateParams(ctx, channeltypes.DefaultParams()) -} diff --git a/modules/core/04-channel/keeper/migrations_test.go b/modules/core/04-channel/keeper/migrations_test.go index d79b4efc81f..944aac49ce1 100644 --- a/modules/core/04-channel/keeper/migrations_test.go +++ b/modules/core/04-channel/keeper/migrations_test.go @@ -1,41 +1,10 @@ package keeper_test import ( - "time" - - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) -// TestMigrateParams tests the migration for the channel params -func (suite *KeeperTestSuite) TestMigrateParams() { - testCases := []struct { - name string - expectedParams channeltypes.Params - }{ - { - "success: default params", - channeltypes.NewParams(channeltypes.NewTimeout(clienttypes.ZeroHeight(), uint64(time.Minute*20))), - }, - } - - 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, tc.expectedParams) - suite.Require().NoError(err) - - params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) - suite.Require().Equal(tc.expectedParams, params) - }) - } -} - // TestMigrateDefaultParams tests the migration for the channel params func (suite *KeeperTestSuite) TestMigrateDefaultParams() { testCases := []struct { @@ -55,7 +24,7 @@ func (suite *KeeperTestSuite) TestMigrateDefaultParams() { ctx := suite.chainA.GetContext() migrator := keeper.NewMigrator(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper) - err := migrator.MigrateDefaultParams(ctx) + err := migrator.MigrateParams(ctx) suite.Require().NoError(err) params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) diff --git a/modules/core/module.go b/modules/core/module.go index 27edd09a143..4bdc158ae10 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -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 From afaaf2342879f620af13dcd5c21ed9baf4026784 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 12:36:53 +0000 Subject: [PATCH 3/6] chore: fix linter --- e2e/testsuite/testconfig.go | 6 +++--- modules/core/module.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go index f8cfe1b5b7a..96f5b551d32 100644 --- a/e2e/testsuite/testconfig.go +++ b/e2e/testsuite/testconfig.go @@ -561,7 +561,7 @@ func defaultGovv1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([] appState[govtypes.ModuleName] = govGenBz if !testvalues.AllowAllClientsWildcardFeatureReleases.IsSupported(version) { - ibcGenBz, err := modifyClientGenesisAppState(chainConfig, appState[ibcexported.ModuleName]) + ibcGenBz, err := modifyClientGenesisAppState(appState[ibcexported.ModuleName]) if err != nil { return nil, err } @@ -628,7 +628,7 @@ func defaultGovv1Beta1ModifyGenesis(version string) func(ibc.ChainConfig, []byte return nil, fmt.Errorf("failed to extract ibc genesis bytes: %s", err) } - ibcGenesisBytes, err := modifyClientGenesisAppState(chainConfig, ibcModuleBytes) + ibcGenesisBytes, err := modifyClientGenesisAppState(ibcModuleBytes) if err != nil { return nil, err } @@ -704,7 +704,7 @@ func modifyGovv1Beta1AppState(chainConfig ibc.ChainConfig, govAppState []byte) ( } // modifyClientGenesisAppState takes the existing ibc app state and marshals it to a ibc GenesisState. -func modifyClientGenesisAppState(chainConfig ibc.ChainConfig, ibcAppState []byte) ([]byte, error) { +func modifyClientGenesisAppState(ibcAppState []byte) ([]byte, error) { cfg := testutil.MakeTestEncodingConfig() cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) diff --git a/modules/core/module.go b/modules/core/module.go index 4bdc158ae10..5801c56e61f 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -4,8 +4,6 @@ import ( "context" "encoding/json" "fmt" - channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper" - "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -23,6 +21,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" From 67a422ed4913795ebcd0668032c2243445490364 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 12:37:59 +0000 Subject: [PATCH 4/6] chore: bump consensus --- modules/core/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/module.go b/modules/core/module.go index 5801c56e61f..6e7da3a2ade 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -183,7 +183,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 { From 955c20274237894b40dea935fd983e0296259313 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 12:42:20 +0000 Subject: [PATCH 5/6] chore: fix linter again --- modules/core/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/module.go b/modules/core/module.go index 6e7da3a2ade..e7f6ebd4a94 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" From 12e8801d4a4185c9caf494f85b7f35d79ae8e875 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Jan 2024 16:54:50 +0000 Subject: [PATCH 6/6] chore: pr feedback --- modules/core/04-channel/keeper/migrations.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/core/04-channel/keeper/migrations.go b/modules/core/04-channel/keeper/migrations.go index 5d99902f3f6..5bc0fcf0a41 100644 --- a/modules/core/04-channel/keeper/migrations.go +++ b/modules/core/04-channel/keeper/migrations.go @@ -19,10 +19,7 @@ func NewMigrator(keeper Keeper) Migrator { // MigrateParams migrates params to the default channel params. func (m Migrator) MigrateParams(ctx sdk.Context) error { params := channeltypes.DefaultParams() - if err := params.Validate(); err != nil { - return err - } m.keeper.SetParams(ctx, params) - m.keeper.Logger(ctx).Info("successfully migrated channel params") + m.keeper.Logger(ctx).Info("successfully migrated ibc channel params") return nil }