From 27ef1d22fb358ce1159f846fc299ac8b02a2f83e Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:36:51 -0700 Subject: [PATCH] feat: increment consensus ver and register migration (#1295) * increment consensus ver and register migration * Update CHANGELOG.md * Update migration.go * Update module.go --- CHANGELOG.md | 1 + x/ccv/consumer/keeper/migration.go | 13 +++++++++---- x/ccv/consumer/module.go | 12 ++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 032927214a..29b6328e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Note: Changes: +* (feat) [#1295](https://github.com/cosmos/interchain-security/pull/1295) increment consumer consensus version and register consumer packet migration. * (fix!) [#1262](https://github.com/cosmos/interchain-security/pull/1262) Remove incorrect address validation on `ProviderFeePoolAddrStr` param. * (feature!) [#1244](https://github.com/cosmos/interchain-security/pull/1244) Update the default consumer unbonding period to 2 weeks. * (fix!) [#1244](https://github.com/cosmos/interchain-security/pull/1244) Validate token transfer messages before calling `Transfer()`. diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 361bb2a62f..5d5d913b9b 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -21,23 +21,27 @@ func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subs return Migrator{ccvConsumerKeeper: ccvConsumerKeeper, ccvConsumerParamSpace: ccvConsumerParamSpace} } +// Migrate1to2 migrates x/ccvconsumer state from consensus version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return m.ccvConsumerKeeper.MigrateConsumerPacketData(ctx) +} + // 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 (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { +func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) error { // deserialize packet data from old format var depreciatedType ccvtypes.ConsumerPacketDataList store := ctx.KVStore(k.storeKey) bz := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) if bz == nil { ctx.Logger().Info("no pending data packets to migrate") - return + return nil } err := depreciatedType.Unmarshal(bz) if err != nil { - // An error here would indicate something is very wrong - panic(fmt.Errorf("failed to unmarshal pending data packets: %w", err)) + return fmt.Errorf("failed to unmarshal pending data packets: %w", err) } // Delete old data @@ -48,6 +52,7 @@ func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { for _, data := range depreciatedType.List { k.AppendPendingPacket(ctx, data.Type, data.Data) } + return nil } // TODO: the following hackyness could be removed if we're able to reference older versions of ICS. diff --git a/x/ccv/consumer/module.go b/x/ccv/consumer/module.go index e175205530..ba38b01d73 100644 --- a/x/ccv/consumer/module.go +++ b/x/ccv/consumer/module.go @@ -107,6 +107,11 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { 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)) + } } // InitGenesis performs genesis initialization for the consumer module. It returns @@ -126,12 +131,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { - // Note that v1.0.0 consumers should technically be on a different consensus version - // than v1.2.0-multiden and v2.0.0. However, Neutron was the first consumer to launch - // in prod, and they've started on v1.2.0-multiden (which has a ConsensusVersion of 1). - // - // v1.2.0-multiden and v2.0.0 are consensus compatible, so they need return the same ConsensusVersion of 1. - return 1 + return 2 } // BeginBlock implements the AppModule interface