From 15d2d216563ccef7840ec54f471a07c752c4f706 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Mon, 8 Apr 2024 11:55:43 +0200 Subject: [PATCH] fix!: introduce v4 provider migration code (#1762) --- x/ccv/provider/migrations/migrator.go | 9 ++++++- .../provider/migrations/v3/migration_test.go | 18 ------------- x/ccv/provider/migrations/v3/migrations.go | 11 -------- .../provider/migrations/v4/migration_test.go | 27 +++++++++++++++++++ x/ccv/provider/migrations/v4/migrations.go | 18 +++++++++++++ x/ccv/provider/module.go | 2 +- 6 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 x/ccv/provider/migrations/v4/migration_test.go create mode 100644 x/ccv/provider/migrations/v4/migrations.go diff --git a/x/ccv/provider/migrations/migrator.go b/x/ccv/provider/migrations/migrator.go index 19938477da..7c52ee27ce 100644 --- a/x/ccv/provider/migrations/migrator.go +++ b/x/ccv/provider/migrations/migrator.go @@ -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. @@ -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) 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 +} diff --git a/x/ccv/provider/migrations/v3/migration_test.go b/x/ccv/provider/migrations/v3/migration_test.go index a7ded19f57..189c75e271 100644 --- a/x/ccv/provider/migrations/v3/migration_test.go +++ b/x/ccv/provider/migrations/v3/migration_test.go @@ -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) { @@ -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) -} diff --git a/x/ccv/provider/migrations/v3/migrations.go b/x/ccv/provider/migrations/v3/migrations.go index 8d3bc2509d..c2cd9054ba 100644 --- a/x/ccv/provider/migrations/v3/migrations.go +++ b/x/ccv/provider/migrations/v3/migrations.go @@ -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 @@ -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) - } -} diff --git a/x/ccv/provider/migrations/v4/migration_test.go b/x/ccv/provider/migrations/v4/migration_test.go new file mode 100644 index 0000000000..5ab5faf87a --- /dev/null +++ b/x/ccv/provider/migrations/v4/migration_test.go @@ -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) +} diff --git a/x/ccv/provider/migrations/v4/migrations.go b/x/ccv/provider/migrations/v4/migrations.go new file mode 100644 index 0000000000..06b89d7efb --- /dev/null +++ b/x/ccv/provider/migrations/v4/migrations.go @@ -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) + } +} diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index f34b92bb07..6f7ec08f7b 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -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) {