From 9de8555985b5e8bb9ea21190634a9788aa8ce901 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:07:12 +0200 Subject: [PATCH] fix: add missing migration; use correct constant types (backport #1757) (#1760) fix: add missing migration; use correct constant types (#1757) (cherry picked from commit 84199d7ab84050d36e85791e95615d28e3edb9ad) Co-authored-by: MSalopek --- x/ccv/provider/migrations/migrator.go | 1 + x/ccv/provider/migrations/v3/migration_test.go | 18 ++++++++++++++++++ x/ccv/provider/migrations/v3/migrations.go | 11 +++++++++++ x/ccv/provider/types/params.go | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/x/ccv/provider/migrations/migrator.go b/x/ccv/provider/migrations/migrator.go index 9127844dee..19938477da 100644 --- a/x/ccv/provider/migrations/migrator.go +++ b/x/ccv/provider/migrations/migrator.go @@ -29,5 +29,6 @@ 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) } diff --git a/x/ccv/provider/migrations/v3/migration_test.go b/x/ccv/provider/migrations/v3/migration_test.go index 189c75e271..a7ded19f57 100644 --- a/x/ccv/provider/migrations/v3/migration_test.go +++ b/x/ccv/provider/migrations/v3/migration_test.go @@ -7,6 +7,7 @@ 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) { @@ -115,3 +116,20 @@ 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 c2cd9054ba..8d3bc2509d 100644 --- a/x/ccv/provider/migrations/v3/migrations.go +++ b/x/ccv/provider/migrations/v3/migrations.go @@ -5,7 +5,9 @@ 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 @@ -23,3 +25,12 @@ 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/types/params.go b/x/ccv/provider/types/params.go index 30bce2d17f..a0a7a5ed7a 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -39,7 +39,8 @@ const ( // DefaultBlocksPerEpoch defines the default blocks that constitute an epoch. Assuming we need 6 seconds per block, // an epoch corresponds to 1 hour (6 * 600 = 3600 seconds). - DefaultBlocksPerEpoch = 600 + // forcing int64 as the Params KeyTable expects an int64 and not int. + DefaultBlocksPerEpoch = int64(600) ) // Reflection based keys for params subspace