From b9c408dfbe40d241496115be5dc7927056e58ade Mon Sep 17 00:00:00 2001
From: Philip Offtermatt
Date: Thu, 4 Jul 2024 08:55:10 +0200
Subject: [PATCH 1/3] Add initialization for validator cap
---
.../provider/migrations/vX/migration_test.go | 57 +++++++++++++++++++
x/ccv/provider/migrations/vX/migrations.go | 16 ++++++
2 files changed, 73 insertions(+)
create mode 100644 x/ccv/provider/migrations/vX/migration_test.go
create mode 100644 x/ccv/provider/migrations/vX/migrations.go
diff --git a/x/ccv/provider/migrations/vX/migration_test.go b/x/ccv/provider/migrations/vX/migration_test.go
new file mode 100644
index 0000000000..f66c73301f
--- /dev/null
+++ b/x/ccv/provider/migrations/vX/migration_test.go
@@ -0,0 +1,57 @@
+package v6
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ testutil "github.com/cosmos/interchain-security/v5/testutil/keeper"
+ providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
+ ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types"
+)
+
+func TestMigrateParams(t *testing.T) {
+ t.Helper()
+ inMemParams := testutil.NewInMemKeeperParams(t)
+ k, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams)
+ defer ctrl.Finish()
+
+ if !inMemParams.ParamsSubspace.HasKeyTable() {
+ inMemParams.ParamsSubspace.WithKeyTable(providertypes.ParamKeyTable())
+ }
+
+ defaultParams := providertypes.DefaultParams()
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyTemplateClient, defaultParams.TemplateClient)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyTrustingPeriodFraction, defaultParams.TrustingPeriodFraction)
+ inMemParams.ParamsSubspace.Set(ctx, ccvtypes.KeyCCVTimeoutPeriod, defaultParams.CcvTimeoutPeriod)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyInitTimeoutPeriod, defaultParams.InitTimeoutPeriod)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyVscTimeoutPeriod, defaultParams.VscTimeoutPeriod)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeySlashMeterReplenishPeriod, defaultParams.SlashMeterReplenishPeriod)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeySlashMeterReplenishFraction, defaultParams.SlashMeterReplenishFraction)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyConsumerRewardDenomRegistrationFee, defaultParams.ConsumerRewardDenomRegistrationFee)
+ inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, defaultParams.BlocksPerEpoch)
+
+ // confirms that inMemParams.ParamsSubspace works as expected
+ require.NotPanics(t, func() {
+ GetParamsLegacy(ctx, inMemParams.ParamsSubspace)
+ })
+
+ // no "new" params should be available before migration
+ // "new" params are stored under providertypes.ParametersKey()
+ emptyParams := k.GetParams(ctx)
+ require.Empty(t, emptyParams)
+
+ // make sure that the legacy params are equal to the default params (they were set using inMemParams.ParamsSubspace.Set())
+ legacyParams := GetParamsLegacy(ctx, inMemParams.ParamsSubspace)
+ require.NotNil(t, legacyParams)
+ require.Equal(t, defaultParams, legacyParams)
+
+ err := MigrateLegacyParams(ctx, k, inMemParams.ParamsSubspace)
+ require.NoError(t, err)
+
+ // check that "new" params are available after migration and equal to defaults
+ migratedParams := k.GetParams(ctx)
+ require.NotEmpty(t, migratedParams)
+ require.Equal(t, defaultParams, migratedParams)
+ require.NotEqual(t, emptyParams, migratedParams)
+}
diff --git a/x/ccv/provider/migrations/vX/migrations.go b/x/ccv/provider/migrations/vX/migrations.go
new file mode 100644
index 0000000000..6cb53a98df
--- /dev/null
+++ b/x/ccv/provider/migrations/vX/migrations.go
@@ -0,0 +1,16 @@
+package v6
+
+import (
+ sdk "github.com/cosmos/cosmos-sdk/types"
+ providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
+)
+
+// MigrateMaxValidatorsForExistingConsumers initializes the max validators
+// parameter for existing consumers to the MaxProviderConsensusValidators parameter.
+// This is necessary to avoid those consumer chains having an excessive amount of validators.
+func InitializeMaxValidatorsForExistingConsumers(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
+ maxVals := providerKeeper.GetParams(ctx).MaxProviderConsensusValidators
+ for _, chainID := range providerKeeper.GetAllRegisteredConsumerChainIDs(ctx) {
+ providerKeeper.SetValidatorSetCap(ctx, chainID, uint32(maxVals))
+ }
+}
From 919947dae11fb733dc0e4c7669a974b58b39581c Mon Sep 17 00:00:00 2001
From: Philip Offtermatt
Date: Thu, 4 Jul 2024 08:59:52 +0200
Subject: [PATCH 2/3] Remove migration test
---
.../provider/migrations/vX/migration_test.go | 57 -------------------
1 file changed, 57 deletions(-)
delete mode 100644 x/ccv/provider/migrations/vX/migration_test.go
diff --git a/x/ccv/provider/migrations/vX/migration_test.go b/x/ccv/provider/migrations/vX/migration_test.go
deleted file mode 100644
index f66c73301f..0000000000
--- a/x/ccv/provider/migrations/vX/migration_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package v6
-
-import (
- "testing"
-
- "github.com/stretchr/testify/require"
-
- testutil "github.com/cosmos/interchain-security/v5/testutil/keeper"
- providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
- ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types"
-)
-
-func TestMigrateParams(t *testing.T) {
- t.Helper()
- inMemParams := testutil.NewInMemKeeperParams(t)
- k, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams)
- defer ctrl.Finish()
-
- if !inMemParams.ParamsSubspace.HasKeyTable() {
- inMemParams.ParamsSubspace.WithKeyTable(providertypes.ParamKeyTable())
- }
-
- defaultParams := providertypes.DefaultParams()
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyTemplateClient, defaultParams.TemplateClient)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyTrustingPeriodFraction, defaultParams.TrustingPeriodFraction)
- inMemParams.ParamsSubspace.Set(ctx, ccvtypes.KeyCCVTimeoutPeriod, defaultParams.CcvTimeoutPeriod)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyInitTimeoutPeriod, defaultParams.InitTimeoutPeriod)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyVscTimeoutPeriod, defaultParams.VscTimeoutPeriod)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeySlashMeterReplenishPeriod, defaultParams.SlashMeterReplenishPeriod)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeySlashMeterReplenishFraction, defaultParams.SlashMeterReplenishFraction)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyConsumerRewardDenomRegistrationFee, defaultParams.ConsumerRewardDenomRegistrationFee)
- inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyBlocksPerEpoch, defaultParams.BlocksPerEpoch)
-
- // confirms that inMemParams.ParamsSubspace works as expected
- require.NotPanics(t, func() {
- GetParamsLegacy(ctx, inMemParams.ParamsSubspace)
- })
-
- // no "new" params should be available before migration
- // "new" params are stored under providertypes.ParametersKey()
- emptyParams := k.GetParams(ctx)
- require.Empty(t, emptyParams)
-
- // make sure that the legacy params are equal to the default params (they were set using inMemParams.ParamsSubspace.Set())
- legacyParams := GetParamsLegacy(ctx, inMemParams.ParamsSubspace)
- require.NotNil(t, legacyParams)
- require.Equal(t, defaultParams, legacyParams)
-
- err := MigrateLegacyParams(ctx, k, inMemParams.ParamsSubspace)
- require.NoError(t, err)
-
- // check that "new" params are available after migration and equal to defaults
- migratedParams := k.GetParams(ctx)
- require.NotEmpty(t, migratedParams)
- require.Equal(t, defaultParams, migratedParams)
- require.NotEqual(t, emptyParams, migratedParams)
-}
From d9d4305bcb8b7e05156b229219600f88c9f6c9f1 Mon Sep 17 00:00:00 2001
From: Philip Offtermatt <57488781+p-offtermatt@users.noreply.github.com>
Date: Mon, 15 Jul 2024 13:26:10 +0200
Subject: [PATCH 3/3] Fix inconsistent naming
---
x/ccv/provider/migrations/vX/migrations.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/x/ccv/provider/migrations/vX/migrations.go b/x/ccv/provider/migrations/vX/migrations.go
index 6cb53a98df..9040c82ee2 100644
--- a/x/ccv/provider/migrations/vX/migrations.go
+++ b/x/ccv/provider/migrations/vX/migrations.go
@@ -5,7 +5,7 @@ import (
providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
)
-// MigrateMaxValidatorsForExistingConsumers initializes the max validators
+// InitializeMaxValidatorsForExistingConsumers initializes the max validators
// parameter for existing consumers to the MaxProviderConsensusValidators parameter.
// This is necessary to avoid those consumer chains having an excessive amount of validators.
func InitializeMaxValidatorsForExistingConsumers(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {