From 988c7d7e37a88c2418626d5950eeee2a2f0cfab7 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:31:02 -0700 Subject: [PATCH 1/8] migration.go and incr consensus version --- x/ccv/provider/keeper/migration.go | 32 ++++++++++++++++++++++++++++++ x/ccv/provider/module.go | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 x/ccv/provider/keeper/migration.go diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go new file mode 100644 index 0000000000..12fd1fa327 --- /dev/null +++ b/x/ccv/provider/keeper/migration.go @@ -0,0 +1,32 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + providerKeeper Keeper + paramSpace paramtypes.Subspace +} + +// NewMigrator returns a new Migrator. +func NewMigrator(providerKeeper Keeper, paramSpace paramtypes.Subspace) Migrator { + return Migrator{providerKeeper: providerKeeper, paramSpace: paramSpace} +} + +// Migrate2to3 migrates x/ccvprovider state from consensus version 2 to 3. +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + return m.providerKeeper.MigrateQueuedPackets(ctx) +} + +func (k Keeper) MigrateQueuedPackets(ctx sdk.Context) error { + return nil +} + +// Pending packet data type enum, used to encode the type of packet data stored at each entry in the mutual queue. +const ( + slashPacketData byte = iota + vscMaturedPacketData +) diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index 5aa743ec2d..e109d30d11 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -129,7 +129,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // BeginBlock implements the AppModule interface func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { From b055e594de98817e759dccdf2dee3ae6b7a9ecfd Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:50:45 -0700 Subject: [PATCH 2/8] throttle v1 code for migration --- x/ccv/provider/keeper/migration.go | 60 ++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index 12fd1fa327..ed0e794ce3 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -1,8 +1,12 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "fmt" + + sdktypes "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // Migrator is a struct for handling in-place store migrations. @@ -17,16 +21,66 @@ func NewMigrator(providerKeeper Keeper, paramSpace paramtypes.Subspace) Migrator } // Migrate2to3 migrates x/ccvprovider state from consensus version 2 to 3. -func (m Migrator) Migrate2to3(ctx sdk.Context) error { +func (m Migrator) Migrate2to3(ctx sdktypes.Context) error { return m.providerKeeper.MigrateQueuedPackets(ctx) } -func (k Keeper) MigrateQueuedPackets(ctx sdk.Context) error { +func (k Keeper) MigrateQueuedPackets(ctx sdktypes.Context) error { + for _, consumer := range k.GetAllConsumerChains(ctx) { + slashData, vscmData := k.GetAllThrottledPacketData(ctx, consumer.ChainId) + if len(slashData) > 0 { + ctx.Logger().Error(fmt.Sprintf("slash data being dropped: %v", slashData)) + } + for _, data := range vscmData { + k.HandleVSCMaturedPacket(ctx, consumer.ChainId, data) + } + } return nil + } // Pending packet data type enum, used to encode the type of packet data stored at each entry in the mutual queue. +// Note this type is copy/pasted from throttle v1 code. const ( slashPacketData byte = iota vscMaturedPacketData ) + +// GetAllThrottledPacketData returns all throttled packet data for a given consumer chain, only used for 2 -> 3 migration. +// Note this method is adapted from throttle v1 code. +func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID string) ( + slashData []ccvtypes.SlashPacketData, vscMaturedData []ccvtypes.VSCMaturedPacketData, +) { + slashData = []ccvtypes.SlashPacketData{} + vscMaturedData = []ccvtypes.VSCMaturedPacketData{} + + store := ctx.KVStore(k.storeKey) + iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) + iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + bz := iterator.Value() + switch bz[0] { + case slashPacketData: + d := ccvtypes.SlashPacketData{} + if err := d.Unmarshal(bz[1:]); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("failed to unmarshal slash packet data: %v", err)) + continue + } + slashData = append(slashData, d) + case vscMaturedPacketData: + d := ccvtypes.VSCMaturedPacketData{} + if err := d.Unmarshal(bz[1:]); err != nil { + k.Logger(ctx).Error(fmt.Sprintf("failed to unmarshal vsc matured packet data: %v", err)) + continue + } + vscMaturedData = append(vscMaturedData, d) + default: + k.Logger(ctx).Error(fmt.Sprintf("invalid packet data type: %v", bz[0])) + continue + } + } + + return slashData, vscMaturedData +} From 56ff6f2a5aa85ff0293c015623c3b7c56b89a977 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:55:18 -0700 Subject: [PATCH 3/8] old methods --- x/ccv/provider/keeper/migration.go | 31 +++++++++++++++++++++++++ x/ccv/provider/keeper/migration_test.go | 15 ++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 x/ccv/provider/keeper/migration_test.go diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index ed0e794ce3..24669bb3c7 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -84,3 +84,34 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID return slashData, vscMaturedData } + +// Note this method is adapted from throttle v1 code. +func (k Keeper) QueueThrottledPacketDataOnlyForTesting( + ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, +) error { + store := ctx.KVStore(k.storeKey) + + var bz []byte + var err error + switch data := packetData.(type) { + case ccvtypes.SlashPacketData: + bz, err = data.Marshal() + if err != nil { + return fmt.Errorf("failed to marshal slash packet data: %v", err) + } + bz = append([]byte{slashPacketData}, bz...) + case ccvtypes.VSCMaturedPacketData: + bz, err = data.Marshal() + if err != nil { + return fmt.Errorf("failed to marshal vsc matured packet data: %v", err) + } + bz = append([]byte{vscMaturedPacketData}, bz...) + default: + // Indicates a developer error, this method should only be called + // by tests, QueueThrottledSlashPacketData, or QueueThrottledVSCMaturedPacketData. + panic(fmt.Sprintf("unexpected packet data type: %T", data)) + } + + store.Set(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum), bz) + return nil +} diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go new file mode 100644 index 0000000000..4a7c3d695d --- /dev/null +++ b/x/ccv/provider/keeper/migration_test.go @@ -0,0 +1,15 @@ +package keeper_test + +import ( + "testing" + + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" +) + +func TestMigrate2To3(t *testing.T) { + consumerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + // Set some data in old format + +} From c7ebeb31a71f23d531b7d70908f781976c1b9cb4 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:28:57 -0700 Subject: [PATCH 4/8] finish test --- x/ccv/provider/keeper/migration.go | 21 +++++ x/ccv/provider/keeper/migration_test.go | 103 +++++++++++++++++++++++- 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index 24669bb3c7..815e496494 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -34,6 +34,7 @@ func (k Keeper) MigrateQueuedPackets(ctx sdktypes.Context) error { for _, data := range vscmData { k.HandleVSCMaturedPacket(ctx, consumer.ChainId, data) } + k.DeleteThrottledPacketDataForConsumer(ctx, consumer.ChainId) } return nil @@ -85,6 +86,26 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID return slashData, vscMaturedData } +// Note this method is copy/pasted from throttle v1 code. +func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consumerChainID string) { + store := ctx.KVStore(k.storeKey) + iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) + iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) + defer iterator.Close() + + keysToDel := [][]byte{} + for ; iterator.Valid(); iterator.Next() { + keysToDel = append(keysToDel, iterator.Key()) + } + // Delete data for this consumer + for _, key := range keysToDel { + store.Delete(key) + } + + // Delete size of data queue for this consumer + store.Delete(providertypes.ThrottledPacketDataSizeKey(consumerChainID)) +} + // Note this method is adapted from throttle v1 code. func (k Keeper) QueueThrottledPacketDataOnlyForTesting( ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go index 4a7c3d695d..764f2f1b73 100644 --- a/x/ccv/provider/keeper/migration_test.go +++ b/x/ccv/provider/keeper/migration_test.go @@ -2,14 +2,115 @@ package keeper_test import ( "testing" + "time" testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" + "github.com/stretchr/testify/require" ) func TestMigrate2To3(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) defer ctrl.Finish() - // Set some data in old format + // Set consumer client ids to mock consumers being connected to provider + consumerKeeper.SetConsumerClientId(ctx, "chain-1", "client-1") + consumerKeeper.SetConsumerClientId(ctx, "chain-2", "client-2") + consumerKeeper.SetConsumerClientId(ctx, "chain-3", "client-3") + // Queue some data for chain-1 + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-1", 66, testutil.GetNewSlashPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-1", 67, testutil.GetNewVSCMaturedPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-1", 68, testutil.GetNewSlashPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-1", 69, testutil.GetNewVSCMaturedPacketData()) + + // Queue some data for chain-2 + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-2", 789, testutil.GetNewVSCMaturedPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-2", 790, testutil.GetNewSlashPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-2", 791, testutil.GetNewVSCMaturedPacketData()) + + // Queue some data for chain-3 + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-3", 123, testutil.GetNewSlashPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-3", 124, testutil.GetNewVSCMaturedPacketData()) + consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + ctx, "chain-3", 125, testutil.GetNewVSCMaturedPacketData()) + + // Confirm getter methods return expected values + slash1, vscm1 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-1") + require.Len(t, slash1, 2) + require.Len(t, vscm1, 2) + + slash2, vscm2 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-2") + require.Len(t, slash2, 1) + require.Len(t, vscm2, 2) + + slash3, vscm3 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-3") + require.Len(t, slash3, 1) + require.Len(t, vscm3, 2) + + // Set vsc send timestamp for every queued vsc matured packet, + // as a way to assert that the vsc matured packets are handled in the migration. + // + // That is, timestamp should exist before a vsc matured packet is handled, + // and deleted after handling. + for _, data := range vscm1 { + consumerKeeper.SetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId, time.Now()) + } + for _, data := range vscm2 { + consumerKeeper.SetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId, time.Now()) + } + for _, data := range vscm3 { + consumerKeeper.SetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId, time.Now()) + } + + // Confirm timestamps are set + for _, data := range vscm1 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) + require.True(t, found) + } + for _, data := range vscm2 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) + require.True(t, found) + } + for _, data := range vscm3 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) + require.True(t, found) + } + + // Run migration + err := consumerKeeper.MigrateQueuedPackets(ctx) + require.NoError(t, err) + + // Confirm throttled data is now deleted + slash1, vscm1 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-1") + require.Empty(t, slash1) + require.Empty(t, vscm1) + slash2, vscm2 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-2") + require.Empty(t, slash2) + require.Empty(t, vscm2) + slash3, vscm3 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-3") + require.Empty(t, slash3) + require.Empty(t, vscm3) + + // Confirm unbonding op indexes are deleted, meaning vsc matured packets were handled + for _, data := range vscm1 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) + require.False(t, found) + } + for _, data := range vscm2 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) + require.False(t, found) + } + for _, data := range vscm3 { + _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) + require.False(t, found) + } } From 96bb2a297068ec4a52bf503b8da2f65c8a9f8109 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:32:02 -0700 Subject: [PATCH 5/8] register those migs --- x/ccv/provider/module.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index e109d30d11..c70fdeafa7 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -107,6 +107,10 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { func (am AppModule) RegisterServices(cfg module.Configurator) { providertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) providertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) + m := keeper.NewMigrator(*am.keeper, am.paramSpace) + if err := cfg.RegisterMigration(providertypes.ModuleName, 2, m.Migrate2to3); err != nil { + panic(fmt.Sprintf("failed to register migrator for %s: %s", providertypes.ModuleName, err)) + } } // InitGenesis performs genesis initialization for the provider module. It returns no validator updates. From cacf0871705c66754ee9ad596ab4d2e3b50a7707 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:36:16 -0700 Subject: [PATCH 6/8] Update migration_test.go --- x/ccv/provider/keeper/migration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go index 764f2f1b73..14f15f018f 100644 --- a/x/ccv/provider/keeper/migration_test.go +++ b/x/ccv/provider/keeper/migration_test.go @@ -100,7 +100,7 @@ func TestMigrate2To3(t *testing.T) { require.Empty(t, slash3) require.Empty(t, vscm3) - // Confirm unbonding op indexes are deleted, meaning vsc matured packets were handled + // Confirm timestamps are deleted, meaning vsc matured packets were handled for _, data := range vscm1 { _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) require.False(t, found) From 490f53f30e2ea00484cf077876ba9e0748f8ff3a Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:39:48 -0700 Subject: [PATCH 7/8] lint --- x/ccv/provider/keeper/migration.go | 2 +- x/ccv/provider/keeper/migration_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index 815e496494..3f04a49ef6 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -5,6 +5,7 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) @@ -37,7 +38,6 @@ func (k Keeper) MigrateQueuedPackets(ctx sdktypes.Context) error { k.DeleteThrottledPacketDataForConsumer(ctx, consumer.ChainId) } return nil - } // Pending packet data type enum, used to encode the type of packet data stored at each entry in the mutual queue. diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go index 14f15f018f..e21ac50f28 100644 --- a/x/ccv/provider/keeper/migration_test.go +++ b/x/ccv/provider/keeper/migration_test.go @@ -4,8 +4,9 @@ import ( "testing" "time" - testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" "github.com/stretchr/testify/require" + + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" ) func TestMigrate2To3(t *testing.T) { From 9c2d1cb306998e2261c6a4a4ed21efd978dae948 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:54:47 -0700 Subject: [PATCH 8/8] consumer keeper -> provider keeper --- x/ccv/provider/keeper/migration_test.go | 60 ++++++++++++------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go index e21ac50f28..a710e3979c 100644 --- a/x/ccv/provider/keeper/migration_test.go +++ b/x/ccv/provider/keeper/migration_test.go @@ -10,50 +10,50 @@ import ( ) func TestMigrate2To3(t *testing.T) { - consumerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) + providerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) defer ctrl.Finish() // Set consumer client ids to mock consumers being connected to provider - consumerKeeper.SetConsumerClientId(ctx, "chain-1", "client-1") - consumerKeeper.SetConsumerClientId(ctx, "chain-2", "client-2") - consumerKeeper.SetConsumerClientId(ctx, "chain-3", "client-3") + providerKeeper.SetConsumerClientId(ctx, "chain-1", "client-1") + providerKeeper.SetConsumerClientId(ctx, "chain-2", "client-2") + providerKeeper.SetConsumerClientId(ctx, "chain-3", "client-3") // Queue some data for chain-1 - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-1", 66, testutil.GetNewSlashPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-1", 67, testutil.GetNewVSCMaturedPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-1", 68, testutil.GetNewSlashPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-1", 69, testutil.GetNewVSCMaturedPacketData()) // Queue some data for chain-2 - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-2", 789, testutil.GetNewVSCMaturedPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-2", 790, testutil.GetNewSlashPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-2", 791, testutil.GetNewVSCMaturedPacketData()) // Queue some data for chain-3 - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-3", 123, testutil.GetNewSlashPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-3", 124, testutil.GetNewVSCMaturedPacketData()) - consumerKeeper.QueueThrottledPacketDataOnlyForTesting( + providerKeeper.QueueThrottledPacketDataOnlyForTesting( ctx, "chain-3", 125, testutil.GetNewVSCMaturedPacketData()) // Confirm getter methods return expected values - slash1, vscm1 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-1") + slash1, vscm1 := providerKeeper.GetAllThrottledPacketData(ctx, "chain-1") require.Len(t, slash1, 2) require.Len(t, vscm1, 2) - slash2, vscm2 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-2") + slash2, vscm2 := providerKeeper.GetAllThrottledPacketData(ctx, "chain-2") require.Len(t, slash2, 1) require.Len(t, vscm2, 2) - slash3, vscm3 := consumerKeeper.GetAllThrottledPacketData(ctx, "chain-3") + slash3, vscm3 := providerKeeper.GetAllThrottledPacketData(ctx, "chain-3") require.Len(t, slash3, 1) require.Len(t, vscm3, 2) @@ -63,55 +63,55 @@ func TestMigrate2To3(t *testing.T) { // That is, timestamp should exist before a vsc matured packet is handled, // and deleted after handling. for _, data := range vscm1 { - consumerKeeper.SetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId, time.Now()) + providerKeeper.SetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId, time.Now()) } for _, data := range vscm2 { - consumerKeeper.SetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId, time.Now()) + providerKeeper.SetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId, time.Now()) } for _, data := range vscm3 { - consumerKeeper.SetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId, time.Now()) + providerKeeper.SetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId, time.Now()) } // Confirm timestamps are set for _, data := range vscm1 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) require.True(t, found) } for _, data := range vscm2 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) require.True(t, found) } for _, data := range vscm3 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) require.True(t, found) } // Run migration - err := consumerKeeper.MigrateQueuedPackets(ctx) + err := providerKeeper.MigrateQueuedPackets(ctx) require.NoError(t, err) // Confirm throttled data is now deleted - slash1, vscm1 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-1") + slash1, vscm1 = providerKeeper.GetAllThrottledPacketData(ctx, "chain-1") require.Empty(t, slash1) require.Empty(t, vscm1) - slash2, vscm2 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-2") + slash2, vscm2 = providerKeeper.GetAllThrottledPacketData(ctx, "chain-2") require.Empty(t, slash2) require.Empty(t, vscm2) - slash3, vscm3 = consumerKeeper.GetAllThrottledPacketData(ctx, "chain-3") + slash3, vscm3 = providerKeeper.GetAllThrottledPacketData(ctx, "chain-3") require.Empty(t, slash3) require.Empty(t, vscm3) // Confirm timestamps are deleted, meaning vsc matured packets were handled for _, data := range vscm1 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-1", data.ValsetUpdateId) require.False(t, found) } for _, data := range vscm2 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-2", data.ValsetUpdateId) require.False(t, found) } for _, data := range vscm3 { - _, found := consumerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) + _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-3", data.ValsetUpdateId) require.False(t, found) } }