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!: introduce v4 provider migration code #1762

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion x/ccv/provider/migrations/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

providerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/provider/keeper"
v3 "github.com/cosmos/interchain-security/v4/x/ccv/provider/migrations/v3"
v4 "github.com/cosmos/interchain-security/v4/x/ccv/provider/migrations/v4"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -29,6 +30,12 @@ func (m Migrator) Migrate1to2(ctx sdktypes.Context) error {

// Migrate2to3 migrates x/ccvprovider state from consensus version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdktypes.Context) error {
v3.MigrateParams(ctx, m.paramSpace)
MSalopek marked this conversation as resolved.
Show resolved Hide resolved
return v3.MigrateQueuedPackets(ctx, m.providerKeeper)
}

// Migrate3to4 migrates x/ccvprovider state from consensus version 3 to 4.
// The migration consists of provider chain params additions.
func (m Migrator) Migrate3to4(ctx sdktypes.Context) error {
v4.MigrateParams(ctx, m.paramSpace)
return nil
}
18 changes: 0 additions & 18 deletions x/ccv/provider/migrations/v3/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"

testutil "github.com/cosmos/interchain-security/v4/testutil/keeper"
providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
)

func TestMigrate2To3(t *testing.T) {
Expand Down Expand Up @@ -116,20 +115,3 @@ func TestMigrate2To3(t *testing.T) {
require.False(t, found)
}
}

func TestMigrateParams(t *testing.T) {
inMemParams := testutil.NewInMemKeeperParams(t)
_, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams)
defer ctrl.Finish()

// initially blocks per epoch param does not exist
require.False(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyBlocksPerEpoch))

MigrateParams(ctx, *inMemParams.ParamsSubspace)

// after migration, blocks per epoch param should exist and be equal to default
require.True(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyBlocksPerEpoch))
var blocksPerEpochParam int64
inMemParams.ParamsSubspace.Get(ctx, providertypes.KeyBlocksPerEpoch, &blocksPerEpochParam)
require.Equal(t, providertypes.DefaultBlocksPerEpoch, blocksPerEpochParam)
}
11 changes: 0 additions & 11 deletions x/ccv/provider/migrations/v3/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
providerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
)

// MigrateQueuedPackets processes all queued packet data for all consumer chains that were stored
Expand All @@ -25,12 +23,3 @@ func MigrateQueuedPackets(ctx sdk.Context, k providerkeeper.Keeper) error {
}
return nil
}

func MigrateParams(ctx sdk.Context, paramsSubspace paramtypes.Subspace) {
if paramsSubspace.HasKeyTable() {
paramsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, providertypes.DefaultBlocksPerEpoch)
} else {
paramsSubspace.WithKeyTable(providertypes.ParamKeyTable())
paramsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, providertypes.DefaultBlocksPerEpoch)
}
}
27 changes: 27 additions & 0 deletions x/ccv/provider/migrations/v4/migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v4

import (
"testing"

"github.com/stretchr/testify/require"

testutil "github.com/cosmos/interchain-security/v4/testutil/keeper"
providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
)

func TestMigrateParams(t *testing.T) {
inMemParams := testutil.NewInMemKeeperParams(t)
_, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams)
defer ctrl.Finish()

// initially blocks per epoch param does not exist
require.False(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyBlocksPerEpoch))

MigrateParams(ctx, *inMemParams.ParamsSubspace)

// after migration, blocks per epoch param should exist and be equal to default
require.True(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyBlocksPerEpoch))
var blocksPerEpochParam int64
inMemParams.ParamsSubspace.Get(ctx, providertypes.KeyBlocksPerEpoch, &blocksPerEpochParam)
require.Equal(t, providertypes.DefaultBlocksPerEpoch, blocksPerEpochParam)
}
18 changes: 18 additions & 0 deletions x/ccv/provider/migrations/v4/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v4

import (
sdk "github.com/cosmos/cosmos-sdk/types"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
)

// MigrateParams adds missing provider chain params to the param store.
func MigrateParams(ctx sdk.Context, paramsSubspace paramtypes.Subspace) {
if paramsSubspace.HasKeyTable() {
paramsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, providertypes.DefaultBlocksPerEpoch)
} else {
paramsSubspace.WithKeyTable(providertypes.ParamKeyTable())
paramsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, providertypes.DefaultBlocksPerEpoch)
}
}
2 changes: 1 addition & 1 deletion x/ccv/provider/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 3 }
func (AppModule) ConsensusVersion() uint64 { return 4 }

// BeginBlock implements the AppModule interface
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
Expand Down
Loading