Skip to content

Commit

Permalink
fix: add missing migration; use correct constant types (#1757)
Browse files Browse the repository at this point in the history
(cherry picked from commit 84199d7)
  • Loading branch information
MSalopek authored and mergify[bot] committed Apr 4, 2024
1 parent d69fb4f commit 86f3056
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions x/ccv/provider/migrations/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 18 additions & 0 deletions x/ccv/provider/migrations/v3/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
11 changes: 11 additions & 0 deletions x/ccv/provider/migrations/v3/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
3 changes: 2 additions & 1 deletion x/ccv/provider/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86f3056

Please sign in to comment.