From cca6b9b6622f95595a8314dd5e7fed99c2d64db3 Mon Sep 17 00:00:00 2001 From: Nathan Toups Date: Tue, 2 Sep 2025 13:26:03 -0600 Subject: [PATCH 1/2] feat: remove legacy migration and simplify deps --- go.mod | 1 - go.sum | 2 -- x/ccv/consumer/keeper/migrations.go | 28 +--------------------------- x/ccv/consumer/module.go | 9 ++------- 4 files changed, 3 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index c72b8760b5..f5befa54b0 100644 --- a/go.mod +++ b/go.mod @@ -148,7 +148,6 @@ require ( cosmossdk.io/x/tx v0.14.0 cosmossdk.io/x/upgrade v0.2.0 github.com/cosmos/cosmos-db v1.1.1 - github.com/cosmos/interchain-security/v6 v6.4.1 github.com/informalsystems/itf-go v0.0.1 github.com/spf13/viper v1.20.1 golang.org/x/mod v0.24.0 diff --git a/go.sum b/go.sum index f632adc6b3..42a6e19082 100644 --- a/go.sum +++ b/go.sum @@ -829,8 +829,6 @@ github.com/cosmos/ibc-go/v10 v10.2.0 h1:wlk/zqz2O0WRyE6UConoR1ci2HSW02P9ywamZCh5 github.com/cosmos/ibc-go/v10 v10.2.0/go.mod h1:ijeyJ1FDvXoc5w+rlhpMntjhZ558EF02SBFjroW1hPo= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= -github.com/cosmos/interchain-security/v6 v6.4.1 h1:DzBDjPQIYUJiF0ioNHkvmcS629htvCu9r5gFb+m7mms= -github.com/cosmos/interchain-security/v6 v6.4.1/go.mod h1:yTbAxgcNKQ+/x2obvnHtxnOjQ5AcML4gb9V0P0e1rds= github.com/cosmos/ledger-cosmos-go v0.14.0 h1:WfCHricT3rPbkPSVKRH+L4fQGKYHuGOK9Edpel8TYpE= github.com/cosmos/ledger-cosmos-go v0.14.0/go.mod h1:E07xCWSBl3mTGofZ2QnL4cIUzMbbGVyik84QYKbX3RA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= diff --git a/x/ccv/consumer/keeper/migrations.go b/x/ccv/consumer/keeper/migrations.go index 3aab448bb3..8dc0d4147c 100644 --- a/x/ccv/consumer/keeper/migrations.go +++ b/x/ccv/consumer/keeper/migrations.go @@ -1,15 +1,11 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - v2 "github.com/cosmos/interchain-security/v5/x/ccv/consumer/migrations/v2" - v3 "github.com/cosmos/interchain-security/v5/x/ccv/consumer/migrations/v3" - v4 "github.com/cosmos/interchain-security/v6/x/ccv/consumer/migrations/v4" ) // Migrator is a struct for handling in-place store migrations. +// Note: This is a complete fork, so no migrations are implemented. type Migrator struct { keeper Keeper paramSpace paramtypes.Subspace @@ -19,25 +15,3 @@ type Migrator struct { func NewMigrator(keeper Keeper, paramspace paramtypes.Subspace) Migrator { return Migrator{keeper: keeper, paramSpace: paramspace} } - -// Migrate1to2 migrates x/ccvconsumer state from consensus version 1 to 2. -func (m Migrator) Migrate1to2(ctx sdk.Context) error { - store := ctx.KVStore(m.keeper.storeKey) - return v2.MigrateConsumerPacketData(ctx, store) -} - -// Migrate2to3 migrates x/ccvconsumer from consensus version 2 to 3. -// This migration is necessary to move the consumer module legacy params. -func (m Migrator) Migrate2to3(ctx sdk.Context) error { - store := ctx.KVStore(m.keeper.storeKey) - cdc := m.keeper.cdc - return v3.MigrateLegacyParams(ctx, cdc, store, m.paramSpace) -} - -// Migrate3to4 migrates x/ccvconsumer from consensus version 3 to 4. -func (m Migrator) Migrate3to4(ctx sdk.Context) error { - store := ctx.KVStore(m.keeper.storeKey) - v4.CleanupState(store) - - return nil -} diff --git a/x/ccv/consumer/module.go b/x/ccv/consumer/module.go index ccfdb93c19..eee9b245c6 100644 --- a/x/ccv/consumer/module.go +++ b/x/ccv/consumer/module.go @@ -123,13 +123,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { consumertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) consumertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) - m := keeper.NewMigrator(am.keeper, am.paramSpace) - if err := cfg.RegisterMigration(consumertypes.ModuleName, 1, m.Migrate1to2); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s", consumertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(consumertypes.ModuleName, 2, m.Migrate2to3); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 2 -> 3", consumertypes.ModuleName, err)) - } + // No migrations needed for this fork + _ = keeper.NewMigrator(am.keeper, am.paramSpace) } // InitGenesis performs genesis initialization for the consumer module. It returns From 8595df99f26549020e9f2dbf73217779e39a7196 Mon Sep 17 00:00:00 2001 From: Nathan Toups Date: Tue, 2 Sep 2025 14:14:23 -0600 Subject: [PATCH 2/2] feat: remove legacy migrations for consumer and provider --- x/ccv/consumer/migrations/v2/migration.go | 58 -------- .../consumer/migrations/v2/migration_test.go | 85 ----------- x/ccv/consumer/migrations/v3/legacy_params.go | 107 ------------- x/ccv/consumer/migrations/v3/migration.go | 27 ---- .../consumer/migrations/v3/migration_test.go | 93 ------------ x/ccv/consumer/migrations/v4/migration.go | 27 ---- x/ccv/provider/migrations/migrator.go | 69 --------- .../provider/migrations/v4/migration_test.go | 27 ---- x/ccv/provider/migrations/v4/migrations.go | 18 --- .../provider/migrations/v5/migration_test.go | 24 --- x/ccv/provider/migrations/v5/migrations.go | 20 --- .../provider/migrations/v6/migration_test.go | 27 ---- x/ccv/provider/migrations/v6/migrations.go | 23 --- x/ccv/provider/migrations/v7/legacy_params.go | 83 ----------- x/ccv/provider/migrations/v7/migrations.go | 21 --- .../provider/migrations/v7/migrations_test.go | 54 ------- x/ccv/provider/migrations/v8/migrations.go | 120 --------------- .../provider/migrations/v8/migrations_test.go | 140 ------------------ x/ccv/provider/module.go | 20 +-- 19 files changed, 1 insertion(+), 1042 deletions(-) delete mode 100644 x/ccv/consumer/migrations/v2/migration.go delete mode 100644 x/ccv/consumer/migrations/v2/migration_test.go delete mode 100644 x/ccv/consumer/migrations/v3/legacy_params.go delete mode 100644 x/ccv/consumer/migrations/v3/migration.go delete mode 100644 x/ccv/consumer/migrations/v3/migration_test.go delete mode 100644 x/ccv/consumer/migrations/v4/migration.go delete mode 100644 x/ccv/provider/migrations/v4/migration_test.go delete mode 100644 x/ccv/provider/migrations/v4/migrations.go delete mode 100644 x/ccv/provider/migrations/v5/migration_test.go delete mode 100644 x/ccv/provider/migrations/v5/migrations.go delete mode 100644 x/ccv/provider/migrations/v6/migration_test.go delete mode 100644 x/ccv/provider/migrations/v6/migrations.go delete mode 100644 x/ccv/provider/migrations/v7/legacy_params.go delete mode 100644 x/ccv/provider/migrations/v7/migrations.go delete mode 100644 x/ccv/provider/migrations/v7/migrations_test.go delete mode 100644 x/ccv/provider/migrations/v8/migrations.go delete mode 100644 x/ccv/provider/migrations/v8/migrations_test.go diff --git a/x/ccv/consumer/migrations/v2/migration.go b/x/ccv/consumer/migrations/v2/migration.go deleted file mode 100644 index a0b401188d..0000000000 --- a/x/ccv/consumer/migrations/v2/migration.go +++ /dev/null @@ -1,58 +0,0 @@ -package v2 - -import ( - "fmt" - - storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -// MigrateConsumerPacketData migrates consumer packet data according to -// https://github.com/cosmos/interchain-security/pull/1037 -// -// Note: an equivalent migration is not required for providers. -func MigrateConsumerPacketData(ctx sdk.Context, store storetypes.KVStore) error { - // retrieve old data an deserialize - var oldData consumertypes.ConsumerPacketDataList - bz := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) - if bz == nil { - ctx.Logger().Info("no pending data packets to migrate") - return nil - } - err := oldData.Unmarshal(bz) - if err != nil { - return fmt.Errorf("failed to unmarshal pending data packets: %w", err) - } - - // re-serialize packet data in new format, with the same key prefix, - // index incrementation happens in getAndIncrementPendingPacketsIdx - // the loop operations are equivalent to consumerkeeper.AppendPendingPacket() - for _, data := range oldData.List { - idx := getAndIncrementPendingPacketsIdx(ctx, store) - key := consumertypes.PendingDataPacketsKey(idx) - cpd := ccvtypes.NewConsumerPacketData(data.Type, data.Data) - bz, err := cpd.Marshal() - if err != nil { - // This should never happen - panic(fmt.Errorf("failed to marshal ConsumerPacketData: %w", err)) - } - store.Set(key, bz) - } - - store.Delete([]byte{consumertypes.PendingDataPacketsBytePrefix}) - return nil -} - -// getAndIncrementPendingPacketsIdx returns the current pending packets index and increments it. -func getAndIncrementPendingPacketsIdx(ctx sdk.Context, store storetypes.KVStore) (toReturn uint64) { - bz := store.Get(consumertypes.PendingPacketsIndexKey()) - if bz != nil { - toReturn = sdk.BigEndianToUint64(bz) - } - toStore := toReturn + 1 - store.Set(consumertypes.PendingPacketsIndexKey(), sdk.Uint64ToBigEndian(toStore)) - return toReturn -} diff --git a/x/ccv/consumer/migrations/v2/migration_test.go b/x/ccv/consumer/migrations/v2/migration_test.go deleted file mode 100644 index 0b3f24ec75..0000000000 --- a/x/ccv/consumer/migrations/v2/migration_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package v2_test - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/require" - - storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - testutil "github.com/cosmos/interchain-security/v5/testutil/keeper" - v2 "github.com/cosmos/interchain-security/v5/x/ccv/consumer/migrations/v2" - consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -func TestMigrateConsumerPacketData(t *testing.T) { - testingParams := testutil.NewInMemKeeperParams(t) - consumerKeeper, ctx, ctrl, _ := testutil.GetConsumerKeeperAndCtx(t, testingParams) - testStore := ctx.KVStore(testingParams.StoreKey) - - defer ctrl.Finish() - - // Set some pending data packets in the old format - packets := consumertypes.ConsumerPacketDataList{ - List: []ccvtypes.ConsumerPacketData{ - { - Type: ccvtypes.SlashPacket, - Data: &ccvtypes.ConsumerPacketData_SlashPacketData{ - SlashPacketData: &ccvtypes.SlashPacketData{ - ValsetUpdateId: 77, - }, - }, - }, - { - Type: ccvtypes.VscMaturedPacket, - Data: &ccvtypes.ConsumerPacketData_VscMaturedPacketData{ - VscMaturedPacketData: &ccvtypes.VSCMaturedPacketData{ - ValsetUpdateId: 88, - }, - }, - }, - { - Type: ccvtypes.VscMaturedPacket, - Data: &ccvtypes.ConsumerPacketData_VscMaturedPacketData{ - VscMaturedPacketData: &ccvtypes.VSCMaturedPacketData{ - ValsetUpdateId: 99, - }, - }, - }, - }, - } - - // assert that new storage is empty - storedPackets := consumerKeeper.GetPendingPackets(ctx) - require.Len(t, storedPackets, 0) - - // Set old data - setPendingPackets(ctx, testStore, packets) - // GetPendingPackets should panic because the marshalling is different before migration - require.Panics(t, func() { consumerKeeper.GetPendingPackets(ctx) }) - - // Migrate - v2.MigrateConsumerPacketData(ctx, testStore) - - // Check that the data is migrated properly - obtainedPackets := consumerKeeper.GetPendingPackets(ctx) - require.Len(t, obtainedPackets, 3) - - require.Equal(t, ccvtypes.SlashPacket, obtainedPackets[0].Type) - require.Equal(t, ccvtypes.VscMaturedPacket, obtainedPackets[1].Type) - require.Equal(t, ccvtypes.VscMaturedPacket, obtainedPackets[2].Type) - - require.Equal(t, uint64(77), obtainedPackets[0].GetSlashPacketData().ValsetUpdateId) - require.Equal(t, uint64(88), obtainedPackets[1].GetVscMaturedPacketData().ValsetUpdateId) - require.Equal(t, uint64(99), obtainedPackets[2].GetVscMaturedPacketData().ValsetUpdateId) -} - -func setPendingPackets(ctx sdk.Context, store storetypes.KVStore, packets consumertypes.ConsumerPacketDataList) { - bz, err := packets.Marshal() - if err != nil { - panic(fmt.Errorf("failed to marshal ConsumerPacketDataList: %w", err)) - } - store.Set([]byte{consumertypes.PendingDataPacketsBytePrefix}, bz) -} diff --git a/x/ccv/consumer/migrations/v3/legacy_params.go b/x/ccv/consumer/migrations/v3/legacy_params.go deleted file mode 100644 index 8734cb4266..0000000000 --- a/x/ccv/consumer/migrations/v3/legacy_params.go +++ /dev/null @@ -1,107 +0,0 @@ -package v3 - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -// Legacy: used for migration only! -// GetConsumerParamsLegacy returns the params for the consumer ccv module from legacy subspace -func GetConsumerParamsLegacy(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) ccvtypes.ConsumerParams { - return ccvtypes.NewParams( - getEnabled(ctx, paramSpace), - getBlocksPerDistributionTransmission(ctx, paramSpace), - getDistributionTransmissionChannel(ctx, paramSpace), - getProviderFeePoolAddrStr(ctx, paramSpace), - getCCVTimeoutPeriod(ctx, paramSpace), - getTransferTimeoutPeriod(ctx, paramSpace), - getConsumerRedistributionFrac(ctx, paramSpace), - getHistoricalEntries(ctx, paramSpace), - getUnbondingPeriod(ctx, paramSpace), - getRewardDenoms(ctx, paramSpace), - getProviderRewardDenoms(ctx, paramSpace), - getRetryDelayPeriod(ctx, paramSpace), - ) -} - -// getEnabled returns the enabled flag for the consumer module -func getEnabled(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) bool { - var enabled bool - paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) - return enabled -} - -func getBlocksPerDistributionTransmission(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) int64 { - var bpdt int64 - paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) - return bpdt -} - -func getDistributionTransmissionChannel(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) string { - var s string - paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) - return s -} - -func getProviderFeePoolAddrStr(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) string { - var s string - paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) - return s -} - -// getCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets -func getCCVTimeoutPeriod(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) time.Duration { - var p time.Duration - paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p -} - -// getTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets -func getTransferTimeoutPeriod(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) time.Duration { - var p time.Duration - paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) - return p -} - -// getConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution -// address during distribution events. The fraction is a string representing a -// decimal number. For example "0.75" would represent 75%. -func getConsumerRedistributionFrac(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) string { - var str string - paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) - return str -} - -// getHistoricalEntries returns the number of historical info entries to persist in store -func getHistoricalEntries(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) int64 { - var n int64 - paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) - return n -} - -func getUnbondingPeriod(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) time.Duration { - var period time.Duration - paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) - return period -} - -func getRewardDenoms(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) []string { - var denoms []string - paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) - return denoms -} - -func getProviderRewardDenoms(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) []string { - var denoms []string - paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) - return denoms -} - -func getRetryDelayPeriod(ctx sdk.Context, paramStore ccvtypes.LegacyParamSubspace) time.Duration { - var period time.Duration - paramStore.Get(ctx, ccvtypes.KeyRetryDelayPeriod, &period) - return period -} diff --git a/x/ccv/consumer/migrations/v3/migration.go b/x/ccv/consumer/migrations/v3/migration.go deleted file mode 100644 index aadc94bc43..0000000000 --- a/x/ccv/consumer/migrations/v3/migration.go +++ /dev/null @@ -1,27 +0,0 @@ -package v3 - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - storetypes "cosmossdk.io/store/types" - - consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -// MigrateLegacyParams migrates the consumers module's parameters from the x/params subspace to the -// consumer modules store. -func MigrateLegacyParams(ctx sdk.Context, cdc codec.BinaryCodec, store storetypes.KVStore, legacyParamspace ccvtypes.LegacyParamSubspace) error { - ctx.Logger().Info("starting consumer legacy params migration") - params := GetConsumerParamsLegacy(ctx, legacyParamspace) - err := params.Validate() - if err != nil { - return err - } - - bz := cdc.MustMarshal(¶ms) - store.Set(consumertypes.ParametersKey(), bz) - ctx.Logger().Info("successfully migrated consumer parameters") - return nil -} diff --git a/x/ccv/consumer/migrations/v3/migration_test.go b/x/ccv/consumer/migrations/v3/migration_test.go deleted file mode 100644 index 17d36e9745..0000000000 --- a/x/ccv/consumer/migrations/v3/migration_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package v3 - -import ( - "fmt" - "testing" - "time" - - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/interchain-security/v5/app/encoding" - consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" - - "github.com/stretchr/testify/require" -) - -type testLegacyParamSubspace struct { - *ccvtypes.ConsumerParams -} - -func newTestLegacyParamsSubspace(p ccvtypes.ConsumerParams) testLegacyParamSubspace { - return testLegacyParamSubspace{ - &p, - } -} - -func (ps testLegacyParamSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { - switch string(key) { - case string(ccvtypes.KeyEnabled): - *ptr.(*bool) = ps.Enabled - case string(ccvtypes.KeyBlocksPerDistributionTransmission): - *ptr.(*int64) = ps.BlocksPerDistributionTransmission - case string(ccvtypes.KeyDistributionTransmissionChannel): - *ptr.(*string) = ps.DistributionTransmissionChannel - case string(ccvtypes.KeyProviderFeePoolAddrStr): - *ptr.(*string) = ps.ProviderFeePoolAddrStr - case string(ccvtypes.KeyCCVTimeoutPeriod): - *ptr.(*time.Duration) = ps.CcvTimeoutPeriod - case string(ccvtypes.KeyTransferTimeoutPeriod): - *ptr.(*time.Duration) = ps.TransferTimeoutPeriod - case string(ccvtypes.KeyConsumerRedistributionFrac): - *ptr.(*string) = ps.ConsumerRedistributionFraction - case string(ccvtypes.KeyHistoricalEntries): - *ptr.(*int64) = ps.HistoricalEntries - case string(ccvtypes.KeyConsumerUnbondingPeriod): - *ptr.(*time.Duration) = ps.UnbondingPeriod - case string(ccvtypes.KeyRewardDenoms): - *ptr.(*[]string) = ps.RewardDenoms - case string(ccvtypes.KeyProviderRewardDenoms): - *ptr.(*[]string) = ps.ProviderRewardDenoms - case string(ccvtypes.KeyRetryDelayPeriod): - *ptr.(*time.Duration) = ps.RetryDelayPeriod - default: - panic(fmt.Sprintf("invalid paramspace key: %s", string(key))) - - } -} - -func TestMigrateParams(t *testing.T) { - cdc := encoding.MakeTestEncodingConfig().Codec - storeKey := storetypes.NewKVStoreKey("ccvconsumer") - ctx := testutil.DefaultContext(storeKey, storetypes.NewTransientStoreKey("transient_test")) - store := ctx.KVStore(storeKey) - - defaultParams := ccvtypes.DefaultParams() - legacyParamSubspace := newTestLegacyParamsSubspace(defaultParams) - // confirms that testLegacyParamSubspace works as expected - require.NotPanics(t, func() { - GetConsumerParamsLegacy(ctx, legacyParamSubspace) - }) - - emptyParams := ccvtypes.ConsumerParams{} - bz := store.Get(consumertypes.ParametersKey()) - require.NoError(t, cdc.Unmarshal(bz, &emptyParams)) - require.NotNil(t, emptyParams) - require.Empty(t, emptyParams) - require.NotEqual(t, defaultParams, emptyParams) - - err := MigrateLegacyParams(ctx, cdc, store, legacyParamSubspace) - require.NoError(t, err) - - // check that new params are available after migration and equal to defaults - // legacyParamSubspace was set to match defaultParams - migratedParams := ccvtypes.ConsumerParams{} - paramsBz := store.Get(consumertypes.ParametersKey()) - require.NotEqual(t, bz, paramsBz) - require.NoError(t, cdc.Unmarshal(paramsBz, &migratedParams)) - - require.Equal(t, defaultParams, migratedParams) - require.NotEqual(t, emptyParams, migratedParams) -} diff --git a/x/ccv/consumer/migrations/v4/migration.go b/x/ccv/consumer/migrations/v4/migration.go deleted file mode 100644 index 3a65343a7e..0000000000 --- a/x/ccv/consumer/migrations/v4/migration.go +++ /dev/null @@ -1,27 +0,0 @@ -package v4 - -import ( - storetypes "cosmossdk.io/store/types" -) - -const ( - LegacyPacketMaturityTimeKeyName = byte(12) -) - -// CleanupState removes deprecated state -func CleanupState(store storetypes.KVStore) { - removePrefix(store, LegacyPacketMaturityTimeKeyName) -} - -func removePrefix(store storetypes.KVStore, prefix byte) { - iterator := storetypes.KVStorePrefixIterator(store, []byte{prefix}) - defer iterator.Close() - - var keysToDel [][]byte - for ; iterator.Valid(); iterator.Next() { - keysToDel = append(keysToDel, iterator.Key()) - } - for _, delKey := range keysToDel { - store.Delete(delKey) - } -} diff --git a/x/ccv/provider/migrations/migrator.go b/x/ccv/provider/migrations/migrator.go index 711f1e76dd..19302f829d 100644 --- a/x/ccv/provider/migrations/migrator.go +++ b/x/ccv/provider/migrations/migrator.go @@ -1,18 +1,10 @@ package migrations import ( - "fmt" - storetypes "cosmossdk.io/store/types" - sdktypes "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper" - v4 "github.com/cosmos/interchain-security/v5/x/ccv/provider/migrations/v4" - v5 "github.com/cosmos/interchain-security/v5/x/ccv/provider/migrations/v5" - v6 "github.com/cosmos/interchain-security/v5/x/ccv/provider/migrations/v6" - v7 "github.com/cosmos/interchain-security/v5/x/ccv/provider/migrations/v7" - v8 "github.com/cosmos/interchain-security/v5/x/ccv/provider/migrations/v8" ) // Migrator is a struct for handling in-place store migrations. @@ -34,64 +26,3 @@ func NewMigrator( storeKey: storeKey, } } - -// Migrating consensus version 1 to 2 is a no-op. -// Migrating from v1 -> v2 -> v3 will require multiple state breaking changes and migrations. -// First run provider@v2.x.y in production to migrate from consensus version 1 to 2. -// Then, in order to migrate to consensus version 3, first upgrade to provider@v3.x.y. -func (m Migrator) Migrate1to2(ctx sdktypes.Context) error { - return fmt.Errorf("state migration failed: " + - "first run provider@v2.x.y in production to migrate from consensus version 1 to 2; " + - "then, in order to migrate to consensus version 3, first upgrade to provider@v3.x.y") -} - -// Migrate2to3 migrates x/ccvprovider state from consensus version 2 to 3. -func (m Migrator) Migrate2to3(ctx sdktypes.Context) error { - return fmt.Errorf("state migration failed: " + - "first run provider@v4.0.x in production to migrate from consensus version 2 to 3") -} - -// 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 -} - -// Migrate4to5 migrates x/ccvprovider state from consensus version 4 to 5. -// The migration consists of setting a top N of 95 for all registered consumer chains. -func (m Migrator) Migrate4to5(ctx sdktypes.Context) error { - v5.MigrateTopNForRegisteredChains(ctx, m.providerKeeper) - return nil -} - -// Migrate5to6 migrates x/ccvprovider state from consensus version 5 to 6. -// It consists of setting the `NumberOfEpochsToStartReceivingRewards` param, as well as -// computing and storing the minimal power in the top N for all registered consumer chains. -func (m Migrator) Migrate5to6(ctx sdktypes.Context) error { - v6.MigrateParams(ctx, m.paramSpace) - v6.MigrateMinPowerInTopN(ctx, m.providerKeeper) - return nil -} - -// Migrate6to7 migrates x/ccvprovider state from consensus version 6 to 7. -// The migration consists of initializing new provider chain params using params from the legacy store. -func (m Migrator) Migrate6to7(ctx sdktypes.Context) error { - return v7.MigrateLegacyParams(ctx, m.providerKeeper, m.paramSpace) -} - -// Migrate7to8 migrates x/ccvprovider state from consensus version 7 to 8. -// The migration consists of the following actions: -// - complete the outstanding paused unbonding ops waiting for VSCMaturedPackets from consumer chains -// - migrate the ConsumerAddrsToPrune index to ConsumerAddrsToPruneV2 -// - cleanup deprecated state -func (m Migrator) Migrate7to8(ctx sdktypes.Context) error { - store := ctx.KVStore(m.storeKey) - v8.CompleteUnbondingOps(ctx, store, m.providerKeeper) - if err := v8.MigrateConsumerAddrsToPrune(ctx, store, m.providerKeeper); err != nil { - return err - } - v8.CleanupState(store) - - return nil -} diff --git a/x/ccv/provider/migrations/v4/migration_test.go b/x/ccv/provider/migrations/v4/migration_test.go deleted file mode 100644 index 4423842149..0000000000 --- a/x/ccv/provider/migrations/v4/migration_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package v4 - -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" -) - -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 deleted file mode 100644 index e60c98700e..0000000000 --- a/x/ccv/provider/migrations/v4/migrations.go +++ /dev/null @@ -1,18 +0,0 @@ -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/v5/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/migrations/v5/migration_test.go b/x/ccv/provider/migrations/v5/migration_test.go deleted file mode 100644 index 7805df4ccd..0000000000 --- a/x/ccv/provider/migrations/v5/migration_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package v5 - -import ( - "testing" - - testutil "github.com/cosmos/interchain-security/v5/testutil/keeper" -) - -func TestMigrateParams(t *testing.T) { - inMemParams := testutil.NewInMemKeeperParams(t) - provKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) - defer ctrl.Finish() - - provKeeper.SetConsumerClientId(ctx, "chainID", "clientID") - - // For Replicated Security, TopN is not used - // The migration is now a no-op that just logs a message - - // Run the migration - MigrateTopNForRegisteredChains(ctx, provKeeper) - - // Migration should complete without errors - // No state changes are expected for Replicated Security -} diff --git a/x/ccv/provider/migrations/v5/migrations.go b/x/ccv/provider/migrations/v5/migrations.go deleted file mode 100644 index 5c1dbe38ec..0000000000 --- a/x/ccv/provider/migrations/v5/migrations.go +++ /dev/null @@ -1,20 +0,0 @@ -package v5 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper" -) - -// This migration only takes already registered chains into account. -// If a chain is in voting while the upgrade happens, this is not sufficient, -// and a migration to rewrite the proposal is needed. -func MigrateTopNForRegisteredChains(ctx sdk.Context, providerKeeper providerkeeper.Keeper) { - // This migration is no longer needed for Replicated Security - // All bonded validators participate, so there's no TopN concept - providerKeeper.Logger(ctx).Info("MigrateTopNForRegisteredChains: Skipped - Replicated Security doesn't use Top N") -} - -// // If there are consumer addition proposals in the voting period at the upgrade time, they may need the topN value updated. -// func MigrateTopNForVotingPeriodChains(ctx sdk.Context, govKeeper govkeeper.Keeper, providerKeeper providerkeeper.Keeper) { -// } diff --git a/x/ccv/provider/migrations/v6/migration_test.go b/x/ccv/provider/migrations/v6/migration_test.go deleted file mode 100644 index 9396a3e05d..0000000000 --- a/x/ccv/provider/migrations/v6/migration_test.go +++ /dev/null @@ -1,27 +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" -) - -func TestMigrateParams(t *testing.T) { - inMemParams := testutil.NewInMemKeeperParams(t) - _, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) - defer ctrl.Finish() - - // initially number of epochs param does not exist - require.False(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards)) - - MigrateParams(ctx, *inMemParams.ParamsSubspace) - - // after migration, number of epochs to start receiving rewards param should exist and be equal to default - require.True(t, inMemParams.ParamsSubspace.Has(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards)) - var numberOfEpochsParam int64 - inMemParams.ParamsSubspace.Get(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards, &numberOfEpochsParam) - require.Equal(t, providertypes.DefaultNumberOfEpochsToStartReceivingRewards, numberOfEpochsParam) -} diff --git a/x/ccv/provider/migrations/v6/migrations.go b/x/ccv/provider/migrations/v6/migrations.go deleted file mode 100644 index db10483dcf..0000000000 --- a/x/ccv/provider/migrations/v6/migrations.go +++ /dev/null @@ -1,23 +0,0 @@ -package v6 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/v5/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.WithKeyTable(providertypes.ParamKeyTable()) - } - paramsSubspace.Set(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards, providertypes.DefaultNumberOfEpochsToStartReceivingRewards) -} - -func MigrateMinPowerInTopN(ctx sdk.Context, providerKeeper providerkeeper.Keeper) { - // This migration is no longer needed for Replicated Security - // All bonded validators participate, so there's no minimum power threshold - providerKeeper.Logger(ctx).Info("MigrateMinPowerInTopN: Skipped - Replicated Security doesn't use Top N") -} diff --git a/x/ccv/provider/migrations/v7/legacy_params.go b/x/ccv/provider/migrations/v7/legacy_params.go deleted file mode 100644 index c0ef2798db..0000000000 --- a/x/ccv/provider/migrations/v7/legacy_params.go +++ /dev/null @@ -1,83 +0,0 @@ -package v7 - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - ibctmtypes "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint" - "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" - - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -// getTemplateClient returns the template client for provider proposals -func getTemplateClient(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) *ibctmtypes.ClientState { - var cs ibctmtypes.ClientState - paramSpace.Get(ctx, types.KeyTemplateClient, &cs) - return &cs -} - -// getTrustingPeriodFraction returns a TrustingPeriodFraction -// used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction -func getTrustingPeriodFraction(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) string { - var f string - paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) - return f -} - -// getCCVTimeoutPeriod returns the timeout period for sent ibc packets -func getCCVTimeoutPeriod(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) time.Duration { - var p time.Duration - paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p -} - -// getSlashMeterReplenishPeriod returns the period in which: -// Once the slash meter becomes not-full, the slash meter is replenished after this period. -func getSlashMeterReplenishPeriod(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) time.Duration { - var p time.Duration - paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) - return p -} - -// getSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished -// to the slash meter every replenish period. This param also serves as a maximum fraction of total -// voting power that the slash meter can hold. -func getSlashMeterReplenishFraction(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) string { - var f string - paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) - return f -} - -func getConsumerRewardDenomRegistrationFee(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) sdk.Coin { - var c sdk.Coin - paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) - return c -} - -func getBlocksPerEpoch(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) int64 { - var b int64 - paramSpace.Get(ctx, types.KeyBlocksPerEpoch, &b) - return b -} - -func getNumberOfEpochsToStartReceivingRewards(ctx sdk.Context, paramSpace ccvtypes.LegacyParamSubspace) int64 { - var b int64 - paramSpace.Get(ctx, types.KeyNumberOfEpochsToStartReceivingRewards, &b) - return b -} - -// Legacy: Only for migration purposes. GetParamsLegacy returns the paramset for the provider -// module from a given param subspace -func GetParamsLegacy(ctx sdk.Context, paramspace ccvtypes.LegacyParamSubspace) types.Params { - return types.NewParams( - getTemplateClient(ctx, paramspace), - getTrustingPeriodFraction(ctx, paramspace), - getCCVTimeoutPeriod(ctx, paramspace), - getSlashMeterReplenishPeriod(ctx, paramspace), - getSlashMeterReplenishFraction(ctx, paramspace), - getConsumerRewardDenomRegistrationFee(ctx, paramspace), - getBlocksPerEpoch(ctx, paramspace), - getNumberOfEpochsToStartReceivingRewards(ctx, paramspace), - ) -} diff --git a/x/ccv/provider/migrations/v7/migrations.go b/x/ccv/provider/migrations/v7/migrations.go deleted file mode 100644 index 3c2f171dac..0000000000 --- a/x/ccv/provider/migrations/v7/migrations.go +++ /dev/null @@ -1,21 +0,0 @@ -package v7 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper" - ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types" -) - -// MigrateParams migrates the provider module's parameters from the x/params to self store. -func MigrateLegacyParams(ctx sdk.Context, keeper providerkeeper.Keeper, legacyParamspace ccvtypes.LegacyParamSubspace) error { - ctx.Logger().Info("starting provider legacy params migration") - params := GetParamsLegacy(ctx, legacyParamspace) - err := params.Validate() - if err != nil { - return err - } - - keeper.SetParams(ctx, params) - keeper.Logger(ctx).Info("successfully migrated legacy provider parameters") - return nil -} diff --git a/x/ccv/provider/migrations/v7/migrations_test.go b/x/ccv/provider/migrations/v7/migrations_test.go deleted file mode 100644 index 4b983205cc..0000000000 --- a/x/ccv/provider/migrations/v7/migrations_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package v7 - -import ( - "testing" - - 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" - "github.com/stretchr/testify/require" -) - -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.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) - inMemParams.ParamsSubspace.Set(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards, defaultParams.NumberOfEpochsToStartReceivingRewards) - - // 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) -} diff --git a/x/ccv/provider/migrations/v8/migrations.go b/x/ccv/provider/migrations/v8/migrations.go deleted file mode 100644 index cdf299f91f..0000000000 --- a/x/ccv/provider/migrations/v8/migrations.go +++ /dev/null @@ -1,120 +0,0 @@ -package v8 - -import ( - "encoding/binary" - "time" - - storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - providerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" -) - -const ( - LegacyUnbondingOpBytePrefix = byte(11) - LegacyConsumerAddrsToPruneBytePrefix = byte(25) - LegacyMaturedUnbondingOpsByteKey = byte(1) - LegacyUnbondingOpIndexBytePrefix = byte(12) - LegacyInitTimeoutTimestampBytePrefix = byte(8) - LegacyVscSendTimestampBytePrefix = byte(18) - LegacyVSCMaturedHandledThisBlockBytePrefix = byte(28) -) - -// CompleteUnbondingOps completes all unbonding operations. -// Note that it must be executed before CleanupState. -func CompleteUnbondingOps(ctx sdk.Context, store storetypes.KVStore, pk providerkeeper.Keeper) { - iterator := storetypes.KVStorePrefixIterator(store, []byte{LegacyUnbondingOpBytePrefix}) - defer func() { - if err := iterator.Close(); err != nil { - pk.Logger(ctx).Error("Failed to close iterator", "error", err) - } - }() - - for ; iterator.Valid(); iterator.Next() { - id := binary.BigEndian.Uint64(iterator.Key()[1:]) - if err := pk.UnbondingCanComplete(ctx, id); err != nil { - pk.Logger(ctx).Error("UnbondingCanComplete failed", "unbondingID", id, "error", err.Error()) - } - } -} - -// MigrateConsumerAddrsToPrune migrates the ConsumerAddrsToPrune index to ConsumerAddrsToPruneV2. -// Note: This migration must be done before removing the VscSendTimestamp index -func MigrateConsumerAddrsToPrune(ctx sdk.Context, store storetypes.KVStore, pk providerkeeper.Keeper) error { - iterator := storetypes.KVStorePrefixIterator(store, []byte{LegacyConsumerAddrsToPruneBytePrefix}) - defer iterator.Close() - - unbondingPeriod, err := pk.UnbondingTime(ctx) - if err != nil { - return err - } - - for ; iterator.Valid(); iterator.Next() { - chainID, vscID, err := providertypes.ParseChainIdAndUintIdKey(LegacyConsumerAddrsToPruneBytePrefix, iterator.Key()) - if err != nil { - pk.Logger(ctx).Error("ParseChainIdAndUintIdKey failed while migrating ConsumerAddrsToPrune", - "key", string(iterator.Key()), - "error", err.Error(), - ) - continue - } - // use the VscSendTimestamp index to compute the timestamp after which this consumer address can be pruned - vscSendTimestampKey := providertypes.ChainIdAndUintIdKey(LegacyVscSendTimestampBytePrefix, chainID, vscID) - var sentTime time.Time - if timeBz := store.Get(vscSendTimestampKey); timeBz != nil { - if ts, err := sdk.ParseTimeBytes(timeBz); err == nil { - sentTime = ts - } else { - pk.Logger(ctx).Error("MigrateConsumerAddrsToPrune failed parsing VSC send timestamp key", "error", err.Error()) - continue - } - } else { - pk.Logger(ctx).Error( - "MigrateConsumerAddrsToPrune cannot find VSC send timestamp", - "chainID", chainID, - "vscID", vscID, - ) - continue - } - pruneAfterTs := sentTime.Add(unbondingPeriod).UTC() - - var addrs providertypes.AddressList - err = addrs.Unmarshal(iterator.Value()) - if err != nil { - pk.Logger(ctx).Error("MigrateConsumerAddrsToPrune failed unmarshaling data from store", "key", string(iterator.Value())) - continue - } - - for _, addr := range addrs.Addresses { - consumerAddr := providertypes.NewConsumerConsAddress(addr) - pk.AppendConsumerAddrsToPrune(ctx, chainID, pruneAfterTs, consumerAddr) - } - } - - return nil -} - -// CleanupState removes deprecated state -func CleanupState(store storetypes.KVStore) { - removePrefix(store, LegacyMaturedUnbondingOpsByteKey) - removePrefix(store, LegacyUnbondingOpBytePrefix) - removePrefix(store, LegacyUnbondingOpIndexBytePrefix) - removePrefix(store, LegacyInitTimeoutTimestampBytePrefix) - removePrefix(store, LegacyVscSendTimestampBytePrefix) - removePrefix(store, LegacyVSCMaturedHandledThisBlockBytePrefix) - removePrefix(store, LegacyConsumerAddrsToPruneBytePrefix) -} - -func removePrefix(store storetypes.KVStore, prefix byte) { - iterator := storetypes.KVStorePrefixIterator(store, []byte{prefix}) - defer iterator.Close() - - var keysToDel [][]byte - for ; iterator.Valid(); iterator.Next() { - keysToDel = append(keysToDel, iterator.Key()) - } - for _, delKey := range keysToDel { - store.Delete(delKey) - } -} diff --git a/x/ccv/provider/migrations/v8/migrations_test.go b/x/ccv/provider/migrations/v8/migrations_test.go deleted file mode 100644 index 8c23fccc64..0000000000 --- a/x/ccv/provider/migrations/v8/migrations_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package v8 - -import ( - "testing" - "time" - - "github.com/golang/mock/gomock" - - storetypes "cosmossdk.io/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - testutil "github.com/cosmos/interchain-security/v5/testutil/keeper" - providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types" - "github.com/stretchr/testify/require" -) - -func legacyConsumerAddrsToPruneKey(chainID string, vscID uint64) []byte { - return providertypes.ChainIdAndUintIdKey(LegacyConsumerAddrsToPruneBytePrefix, chainID, vscID) -} - -func legacyAppendConsumerAddrsToPrune( - store storetypes.KVStore, - chainID string, - vscID uint64, - consumerAddr providertypes.ConsumerConsAddress, -) { - bz := store.Get(legacyConsumerAddrsToPruneKey(chainID, vscID)) - var consumerAddrsToPrune providertypes.AddressList - if bz != nil { - err := consumerAddrsToPrune.Unmarshal(bz) - if err != nil { - // An error here would indicate something is very wrong, - // the data bytes are assumed to be correctly serialized by previous calls to this method. - panic(err) - } - } - consumerAddrsToPrune.Addresses = append(consumerAddrsToPrune.Addresses, consumerAddr.ToSdkConsAddr()) - bz, err := consumerAddrsToPrune.Marshal() - if err != nil { - // An error here would indicate something is very wrong, - // consumerAddrsToPrune is instantiated in this method and should be able to be marshaled. - panic(err) - } - store.Set(legacyConsumerAddrsToPruneKey(chainID, vscID), bz) -} - -func legacyVscSendingTimestampKey(chainID string, vscID uint64) []byte { - return providertypes.ChainIdAndUintIdKey(LegacyVscSendTimestampBytePrefix, chainID, vscID) -} - -func legacySetVscSendTimestamp( - store storetypes.KVStore, - chainID string, - vscID uint64, - timestamp time.Time, -) { - // Convert timestamp into bytes for storage - timeBz := sdk.FormatTimeBytes(timestamp) - - store.Set(legacyVscSendingTimestampKey(chainID, vscID), timeBz) -} - -func TestMigrateConsumerAddrsToPrune(t *testing.T) { - t.Helper() - inMemParams := testutil.NewInMemKeeperParams(t) - pk, ctx, ctrl, mocks := testutil.GetProviderKeeperAndCtx(t, inMemParams) - defer ctrl.Finish() - - store := ctx.KVStore(inMemParams.StoreKey) - - consumerAddrsToPrune := []struct { - chainId string - vscId uint64 - address providertypes.ConsumerConsAddress - }{ - {"chain-1", 1, providertypes.NewConsumerConsAddress([]byte{0x01})}, - {"chain-1", 1, providertypes.NewConsumerConsAddress([]byte{0x02})}, - {"chain-2", 1, providertypes.NewConsumerConsAddress([]byte{0x03})}, - {"chain-1", 2, providertypes.NewConsumerConsAddress([]byte{0x04})}, - {"chain-1", 3, providertypes.NewConsumerConsAddress([]byte{0x05})}, - } - for _, x := range consumerAddrsToPrune { - legacyAppendConsumerAddrsToPrune(store, x.chainId, x.vscId, x.address) - } - - ts1 := time.Now().UTC() - ts2 := ts1.Add(time.Minute).UTC() - ts3 := ts2.Add(time.Hour).UTC() - vscSendTimestamps := []struct { - chainId string - vscId uint64 - ts time.Time - }{ - {"chain-1", 1, ts1}, - {"chain-1", 2, ts2}, - {"chain-1", 3, ts3}, - {"chain-2", 1, ts1}, - } - for _, x := range vscSendTimestamps { - legacySetVscSendTimestamp(store, x.chainId, x.vscId, x.ts) - } - - gomock.InOrder( - mocks.MockStakingKeeper.EXPECT().UnbondingTime(ctx).Times(2), - ) - - unbondingPeriod, err := pk.UnbondingTime(ctx) - require.NoError(t, err) - - err = MigrateConsumerAddrsToPrune(ctx, store, pk) - require.NoError(t, err) - - consumerAddrs := pk.GetAllConsumerAddrsToPrune(ctx, "chain-1") - require.Len(t, consumerAddrs, 3) - // two addresses with ts1 - require.Equal(t, ts1.Add(unbondingPeriod).UTC(), consumerAddrs[0].PruneTs) - require.Len(t, consumerAddrs[0].ConsumerAddrs.Addresses, 2) - consumerAddr := providertypes.NewConsumerConsAddress(consumerAddrs[0].ConsumerAddrs.Addresses[0]) - require.Equal(t, consumerAddrsToPrune[0].address, consumerAddr) - consumerAddr = providertypes.NewConsumerConsAddress(consumerAddrs[0].ConsumerAddrs.Addresses[1]) - require.Equal(t, consumerAddrsToPrune[1].address, consumerAddr) - // one address with ts2 - require.Equal(t, ts2.Add(unbondingPeriod).UTC(), consumerAddrs[1].PruneTs) - require.Len(t, consumerAddrs[1].ConsumerAddrs.Addresses, 1) - consumerAddr = providertypes.NewConsumerConsAddress(consumerAddrs[1].ConsumerAddrs.Addresses[0]) - require.Equal(t, consumerAddrsToPrune[3].address, consumerAddr) - // one address with ts3 - require.Equal(t, ts3.Add(unbondingPeriod).UTC(), consumerAddrs[2].PruneTs) - require.Len(t, consumerAddrs[2].ConsumerAddrs.Addresses, 1) - consumerAddr = providertypes.NewConsumerConsAddress(consumerAddrs[2].ConsumerAddrs.Addresses[0]) - require.Equal(t, consumerAddrsToPrune[4].address, consumerAddr) - - consumerAddrs = pk.GetAllConsumerAddrsToPrune(ctx, "chain-2") - require.Len(t, consumerAddrs, 1) - // one address with ts1 - require.Equal(t, ts1.Add(unbondingPeriod).UTC(), consumerAddrs[0].PruneTs) - require.Len(t, consumerAddrs[0].ConsumerAddrs.Addresses, 1) - consumerAddr = providertypes.NewConsumerConsAddress(consumerAddrs[0].ConsumerAddrs.Addresses[0]) - require.Equal(t, consumerAddrsToPrune[2].address, consumerAddr) - -} diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index c8e646ded9..de0cc5b044 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -124,25 +124,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { providertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) providertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) - migrator := migrations.NewMigrator(*am.keeper, am.paramSpace, am.storeKey) - if err := cfg.RegisterMigration(providertypes.ModuleName, 2, migrator.Migrate2to3); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 2 -> 3", providertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(providertypes.ModuleName, 3, migrator.Migrate3to4); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 3 -> 4", providertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(providertypes.ModuleName, 4, migrator.Migrate4to5); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 4 -> 5", providertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(providertypes.ModuleName, 5, migrator.Migrate5to6); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 5 -> 6", providertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(providertypes.ModuleName, 6, migrator.Migrate6to7); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 6 -> 7", providertypes.ModuleName, err)) - } - if err := cfg.RegisterMigration(providertypes.ModuleName, 7, migrator.Migrate7to8); err != nil { - panic(fmt.Sprintf("failed to register migrator for %s: %s -- from 7 -> 8", providertypes.ModuleName, err)) - } + _ = migrations.NewMigrator(*am.keeper, am.paramSpace, am.storeKey) } // InitGenesis performs genesis initialization for the provider module. It returns no validator updates.