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

Add migration for channel params #5640

Merged
merged 8 commits into from
Jan 18, 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 e2e/tests/core/04-channel/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions modules/core/04-channel/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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()
if err := params.Validate(); err != nil {
return err
}
m.keeper.SetParams(ctx, params)
m.keeper.Logger(ctx).Info("successfully migrated channel params")
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
34 changes: 34 additions & 0 deletions modules/core/04-channel/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -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",
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
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)
})
}
}
7 changes: 7 additions & 0 deletions modules/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import (
"context"
"encoding/json"
"fmt"

Check failure on line 6 in modules/core/module.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"

Check failure on line 7 in modules/core/module.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
Expand All @@ -21,7 +22,7 @@
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
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"

Check failure on line 25 in modules/core/module.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
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"
Expand Down Expand Up @@ -157,6 +158,12 @@
}); err != nil {
panic(err)
}

channelMigrator := channelkeeper.NewMigrator(am.keeper.ChannelKeeper)
err := cfg.RegisterMigration(exported.ModuleName, 5, channelMigrator.MigrateParams)
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(err)
}
}

// InitGenesis performs genesis initialization for the ibc module. It returns
Expand Down
Loading