Skip to content

Commit 59ac9b2

Browse files
chattoncrodriguezvega
andauthoredJan 18, 2024
Add migration for channel params (cosmos#5640)
* 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 <[email protected]>

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package keeper
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
6+
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
7+
)
8+
9+
// Migrator is a struct for handling in-place store migrations.
10+
type Migrator struct {
11+
keeper Keeper
12+
}
13+
14+
// NewMigrator returns a new Migrator.
15+
func NewMigrator(keeper Keeper) Migrator {
16+
return Migrator{keeper: keeper}
17+
}
18+
19+
// MigrateParams migrates params to the default channel params.
20+
func (m Migrator) MigrateParams(ctx sdk.Context) error {
21+
params := channeltypes.DefaultParams()
22+
m.keeper.SetParams(ctx, params)
23+
m.keeper.Logger(ctx).Info("successfully migrated ibc channel params")
24+
return nil
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package keeper_test
2+
3+
import (
4+
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
5+
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
6+
)
7+
8+
// TestMigrateDefaultParams tests the migration for the channel params
9+
func (suite *KeeperTestSuite) TestMigrateDefaultParams() {
10+
testCases := []struct {
11+
name string
12+
expectedParams channeltypes.Params
13+
}{
14+
{
15+
"success: default params",
16+
channeltypes.DefaultParams(),
17+
},
18+
}
19+
20+
for _, tc := range testCases {
21+
tc := tc
22+
suite.Run(tc.name, func() {
23+
suite.SetupTest() // reset
24+
25+
ctx := suite.chainA.GetContext()
26+
migrator := keeper.NewMigrator(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
27+
err := migrator.MigrateParams(ctx)
28+
suite.Require().NoError(err)
29+
30+
params := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx)
31+
suite.Require().Equal(tc.expectedParams, params)
32+
})
33+
}
34+
}

‎modules/core/module.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
2323
connectionkeeper "github.com/cosmos/ibc-go/v8/modules/core/03-connection/keeper"
2424
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
25+
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
2526
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
2627
"github.com/cosmos/ibc-go/v8/modules/core/client/cli"
2728
"github.com/cosmos/ibc-go/v8/modules/core/exported"
@@ -157,6 +158,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
157158
}); err != nil {
158159
panic(err)
159160
}
161+
162+
channelMigrator := channelkeeper.NewMigrator(am.keeper.ChannelKeeper)
163+
err := cfg.RegisterMigration(exported.ModuleName, 5, channelMigrator.MigrateParams)
164+
if err != nil {
165+
panic(err)
166+
}
160167
}
161168

162169
// 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
177184
}
178185

179186
// ConsensusVersion implements AppModule/ConsensusVersion.
180-
func (AppModule) ConsensusVersion() uint64 { return 5 }
187+
func (AppModule) ConsensusVersion() uint64 { return 6 }
181188

182189
// BeginBlock returns the begin blocker for the ibc module.
183190
func (am AppModule) BeginBlock(ctx context.Context) error {

0 commit comments

Comments
 (0)
Please sign in to comment.