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: add missing migration; use correct constant types (backport #1757) #1759

Merged
merged 1 commit into from
Apr 5, 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
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
Loading