From 5bb3e14e7eff9bf76265092057b909115a3f6538 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 10:55:25 -0700 Subject: [PATCH 01/18] wip --- proto/interchain_security/ccv/v1/ccv.proto | 4 +- x/ccv/consumer/keeper/keeper.go | 88 +++++++++----- x/ccv/consumer/keeper/keeper_test.go | 2 +- x/ccv/consumer/keeper/relay.go | 21 ++-- x/ccv/consumer/types/keys.go | 18 ++- x/ccv/consumer/types/keys_test.go | 4 +- x/ccv/types/ccv.go | 14 +++ x/ccv/types/ccv.pb.go | 129 +++++++++++++-------- 8 files changed, 186 insertions(+), 94 deletions(-) diff --git a/proto/interchain_security/ccv/v1/ccv.proto b/proto/interchain_security/ccv/v1/ccv.proto index f13951f4d6..cf68f07109 100644 --- a/proto/interchain_security/ccv/v1/ccv.proto +++ b/proto/interchain_security/ccv/v1/ccv.proto @@ -58,7 +58,7 @@ message MaturedUnbondingOps { repeated uint64 ids = 1; } -// ConsumerPacketData contains a consumer packet data and a type tag +// ConsumerPacketData contains a consumer packet data, type tag, and index for storage. message ConsumerPacketData { ConsumerPacketDataType type = 1; @@ -66,9 +66,11 @@ message ConsumerPacketData { SlashPacketData slashPacketData = 2; VSCMaturedPacketData vscMaturedPacketData = 3; } + uint64 idx = 4; } +// TODO: remove // ConsumerPacketDataList is a list of consumer packet data packets. message ConsumerPacketDataList { repeated ConsumerPacketData list = 1 diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index d420bb9bd4..65e1413df5 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -565,48 +565,78 @@ func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChai return validators } -// SetPendingPackets sets the pending CCV packets -func (k Keeper) SetPendingPackets(ctx sdk.Context, packets ccv.ConsumerPacketDataList) { - store := ctx.KVStore(k.storeKey) - bz, err := packets.Marshal() - if err != nil { - // This should never happen - panic(fmt.Errorf("failed to marshal ConsumerPacketDataList: %w", err)) - } - store.Set(types.PendingDataPacketsKey(), bz) +// Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. +// See consistency with PendingDataPacketsKey(). +func PendingDataPacketsIterator(store sdk.KVStore) sdk.Iterator { + return sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) } -// GetPendingPackets returns the pending CCV packets from the store -func (k Keeper) GetPendingPackets(ctx sdk.Context) ccv.ConsumerPacketDataList { - var packets ccv.ConsumerPacketDataList - +func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingDataPacketsKey()) + bz := store.Get(types.PendingPacketsIndexKey()) if bz == nil { - return packets + toReturn = 0 + } else { + toReturn = binary.BigEndian.Uint64(bz) } + toStore := toReturn + 1 + store.Set(types.PendingPacketsIndexKey(), sdk.Uint64ToBigEndian(toStore)) + return toReturn +} - err := packets.Unmarshal(bz) - if err != nil { - // An error here would indicate something is very wrong, - // the PendingPackets are assumed to be correctly serialized in SetPendingPackets. - panic(fmt.Errorf("failed to unmarshal pending data packets: %w", err)) +// GetPendingPackets returns ALL the pending CCV packets from the store +func (k Keeper) GetPendingPackets(ctx sdk.Context) []ccv.ConsumerPacketData { + var packets []ccv.ConsumerPacketData + store := ctx.KVStore(k.storeKey) + iterator := PendingDataPacketsIterator(store) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var packet ccv.ConsumerPacketData + bz := iterator.Value() + err := packet.Unmarshal(bz) + if err != nil { + // An error here would indicate something is very wrong, + panic(fmt.Errorf("failed to unmarshal pending data packet: %w", err)) + } + packets = append(packets, packet) } - return packets } -// DeletePendingDataPackets clears the pending data packets in store -func (k Keeper) DeletePendingDataPackets(ctx sdk.Context) { +// DeletePendingDataPackets deletes pending data packets with given indexes +func (k Keeper) DeletePendingDataPackets(ctx sdk.Context, idxs ...uint64) { + store := ctx.KVStore(k.storeKey) + for _, idx := range idxs { + store.Delete(types.PendingDataPacketsKey(idx)) + } +} + +func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - store.Delete(types.PendingDataPacketsKey()) + // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. + // See consistency with PendingDataPacketsKey(). + iterator := PendingDataPacketsIterator(store) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + store.Delete(iterator.Key()) + } } -// AppendPendingDataPacket appends the given data packet to the pending data packets in store -func (k Keeper) AppendPendingPacket(ctx sdk.Context, packet ...ccv.ConsumerPacketData) { - pending := k.GetPendingPackets(ctx) - list := append(pending.GetList(), packet...) - k.SetPendingPackets(ctx, ccv.ConsumerPacketDataList{List: list}) +// AppendPendingPacket enqueues the given data packet to the end of the pending data packets queue +func (k Keeper) AppendPendingPacket(ctx sdk.Context, packetType ccv.ConsumerPacketDataType, data ccv.ExportedIsConsumerPacketData_Data) { + cpd := ccv.NewConsumerPacketData( + packetType, + data, + k.getAndIncrementPendingPacketsIdx(ctx), + ) + key := types.PendingDataPacketsKey(cpd.Idx) + store := ctx.KVStore(k.storeKey) + bz, err := cpd.Marshal() + if err != nil { + // This should never happen + panic(fmt.Errorf("failed to marshal ConsumerPacketData: %w", err)) + } + store.Set(key, bz) } func (k Keeper) MarkAsPrevStandaloneChain(ctx sdk.Context) { diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index fe523ce7cf..2a8af31f25 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -369,7 +369,7 @@ func TestSetPendingPackets(t *testing.T) { consumerKeeper.AppendPendingPacket(ctx, dataPackets[len(dataPackets)-1]) storedDataPackets = consumerKeeper.GetPendingPackets(ctx) require.NotEmpty(t, storedDataPackets) - require.Equal(t, dataPackets, storedDataPackets.List) + require.Equal(t, dataPackets, storedDataPackets) vscMaturedPakcet := ccv.NewVSCMaturedPacketData(4) dataPackets = append(dataPackets, ccv.ConsumerPacketData{ diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index 2bf1580830..b5615f75ee 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -100,10 +100,10 @@ func (k Keeper) QueueVSCMaturedPackets(ctx sdk.Context) { // Append VSCMatured packet to pending packets. // Sending packets is attempted each EndBlock. // Unsent packets remain in the queue until sent. - k.AppendPendingPacket(ctx, ccv.ConsumerPacketData{ - Type: ccv.VscMaturedPacket, - Data: &ccv.ConsumerPacketData_VscMaturedPacketData{VscMaturedPacketData: vscPacket}, - }) + k.AppendPendingPacket(ctx, + ccv.VscMaturedPacket, + &ccv.ConsumerPacketData_VscMaturedPacketData{VscMaturedPacketData: vscPacket}, + ) k.DeletePacketMaturityTimes(ctx, maturityTime.VscId, maturityTime.MaturityTime) @@ -143,12 +143,12 @@ func (k Keeper) QueueSlashPacket(ctx sdk.Context, validator abci.Validator, vals // append the Slash packet data to pending data packets // to be sent once the CCV channel is established - k.AppendPendingPacket(ctx, ccv.ConsumerPacketData{ - Type: ccv.SlashPacket, - Data: &ccv.ConsumerPacketData_SlashPacketData{ + k.AppendPendingPacket(ctx, + ccv.SlashPacket, + &ccv.ConsumerPacketData_SlashPacketData{ SlashPacketData: slashPacket, }, - }) + ) k.Logger(ctx).Info("SlashPacket enqueued", "vscID", slashPacket.ValsetUpdateId, @@ -182,7 +182,7 @@ func (k Keeper) SendPackets(ctx sdk.Context) { } pending := k.GetPendingPackets(ctx) - for _, p := range pending.GetList() { + for _, p := range pending { // send packet over IBC err := ccv.SendIBCPacket( @@ -210,8 +210,7 @@ func (k Keeper) SendPackets(ctx sdk.Context) { } } - // clear pending data packets - k.DeletePendingDataPackets(ctx) + k.DeleteAllPendingDataPackets(ctx) } // OnAcknowledgementPacket executes application logic for acknowledgments of sent VSCMatured and Slash packets diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index 093f78b450..4252ee5ee8 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -97,6 +97,8 @@ const ( // PrevStandaloneChainByteKey is the byte storing the flag marking whether this chain was previously standalone PrevStandaloneChainByteKey + PendingPacketsIndexBytePrefix + // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go ) @@ -171,11 +173,13 @@ func CrossChainValidatorKey(addr []byte) []byte { return append([]byte{CrossChainValidatorBytePrefix}, addr...) } -// PendingDataPacketsKey returns the key for storing a list of data packets -// that cannot be sent yet to the provider chain either because the CCV channel -// is not established or because the client is expired. -func PendingDataPacketsKey() []byte { - return []byte{PendingDataPacketsBytePrefix} +// PendingDataPacketsKey returns the key for storing a queue of data packets to be sent to the provider. +// Packets in this queue will not be sent on the next endblocker if: +// - the CCV channel is not yet established +// - the client is expired +// - A slash packet is being bounced between consumer and provider (not yet implemented) +func PendingDataPacketsKey(idx uint64) []byte { + return append([]byte{PendingDataPacketsBytePrefix}, sdk.Uint64ToBigEndian(idx)...) } func PreCCVKey() []byte { @@ -205,6 +209,10 @@ func PrevStandaloneChainKey() []byte { return []byte{PrevStandaloneChainByteKey} } +func PendingPacketsIndexKey() []byte { + return []byte{PendingPacketsIndexBytePrefix} +} + // NOTE: DO NOT ADD FULLY DEFINED KEY FUNCTIONS WITHOUT ADDING THEM TO getAllFullyDefinedKeys() IN keys_test.go // diff --git a/x/ccv/consumer/types/keys_test.go b/x/ccv/consumer/types/keys_test.go index a63da6f326..ee92d0734c 100644 --- a/x/ccv/consumer/types/keys_test.go +++ b/x/ccv/consumer/types/keys_test.go @@ -41,6 +41,7 @@ func getAllKeyPrefixes() []byte { InitGenesisHeightByteKey, StandaloneTransferChannelIDByteKey, PrevStandaloneChainByteKey, + PendingPacketsIndexBytePrefix, } } @@ -72,10 +73,11 @@ func getAllFullyDefinedKeys() [][]byte { PacketMaturityTimeKey(0, time.Time{}), HeightValsetUpdateIDKey(0), OutstandingDowntimeKey([]byte{}), - PendingDataPacketsKey(), + PendingDataPacketsKey(473289), CrossChainValidatorKey([]byte{}), InitGenesisHeightKey(), StandaloneTransferChannelIDKey(), PrevStandaloneChainKey(), + PendingPacketsIndexKey(), } } diff --git a/x/ccv/types/ccv.go b/x/ccv/types/ccv.go index 6ec3a6c7c3..a6add95376 100644 --- a/x/ccv/types/ccv.go +++ b/x/ccv/types/ccv.go @@ -103,3 +103,17 @@ func (cp ConsumerPacketData) GetBytes() []byte { bytes := ModuleCdc.MustMarshalJSON(&cp) return bytes } + +// An exported wrapper around the auto generated isConsumerPacketData_Data interface, only for +// AppendPendingPacket to accept the interface as an argument. +type ExportedIsConsumerPacketData_Data interface { + isConsumerPacketData_Data +} + +func NewConsumerPacketData(cpdType ConsumerPacketDataType, data isConsumerPacketData_Data, idx uint64) ConsumerPacketData { + return ConsumerPacketData{ + Type: cpdType, + Data: data, + Idx: idx, + } +} diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 510ee2022c..9d2cea8b9b 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -326,13 +326,14 @@ func (m *MaturedUnbondingOps) GetIds() []uint64 { return nil } -// ConsumerPacketData contains a consumer packet data and a type tag +// ConsumerPacketData contains a consumer packet data, type tag, and index for storage. type ConsumerPacketData struct { Type ConsumerPacketDataType `protobuf:"varint,1,opt,name=type,proto3,enum=interchain_security.ccv.v1.ConsumerPacketDataType" json:"type,omitempty"` // Types that are valid to be assigned to Data: // *ConsumerPacketData_SlashPacketData // *ConsumerPacketData_VscMaturedPacketData Data isConsumerPacketData_Data `protobuf_oneof:"data"` + Idx uint64 `protobuf:"varint,4,opt,name=idx,proto3" json:"idx,omitempty"` } func (m *ConsumerPacketData) Reset() { *m = ConsumerPacketData{} } @@ -412,6 +413,13 @@ func (m *ConsumerPacketData) GetVscMaturedPacketData() *VSCMaturedPacketData { return nil } +func (m *ConsumerPacketData) GetIdx() uint64 { + if m != nil { + return m.Idx + } + return 0 +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { return []interface{}{ @@ -420,6 +428,7 @@ func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { } } +// TODO: remove // ConsumerPacketDataList is a list of consumer packet data packets. type ConsumerPacketDataList struct { List []ConsumerPacketData `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` @@ -481,51 +490,52 @@ func init() { } var fileDescriptor_68bd5f3242e6f29c = []byte{ - // 699 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcf, 0x6e, 0xda, 0x4a, - 0x14, 0xc6, 0xed, 0x60, 0x45, 0xca, 0x20, 0x25, 0x8e, 0x2f, 0xf7, 0x8a, 0xf8, 0xde, 0xeb, 0x58, - 0x56, 0xd4, 0xa2, 0x56, 0xb5, 0x8b, 0xd3, 0x45, 0xd5, 0x6e, 0x1a, 0x08, 0x11, 0xa8, 0xf9, 0x83, - 0xec, 0x90, 0xaa, 0xdd, 0x58, 0x83, 0x3d, 0x81, 0x11, 0x60, 0x23, 0xcf, 0x60, 0x95, 0x37, 0xa8, - 0xb2, 0xea, 0x0b, 0x64, 0x55, 0xf5, 0x41, 0xba, 0xcb, 0x32, 0xbb, 0x66, 0x15, 0x55, 0xc9, 0x1b, - 0xf4, 0x09, 0x2a, 0x0f, 0x86, 0x10, 0x70, 0x90, 0xb2, 0x62, 0x38, 0x73, 0xce, 0x07, 0xdf, 0x6f, - 0x3e, 0x1d, 0xb0, 0x85, 0x7d, 0x8a, 0x42, 0xb7, 0x0d, 0xb1, 0xef, 0x10, 0xe4, 0x0e, 0x42, 0x4c, - 0x87, 0x86, 0xeb, 0x46, 0x46, 0x54, 0x8c, 0x3f, 0xf4, 0x7e, 0x18, 0xd0, 0x40, 0x92, 0x53, 0xba, - 0xf4, 0xf8, 0x3a, 0x2a, 0xca, 0x5b, 0x6e, 0x40, 0x7a, 0x01, 0x31, 0x08, 0x85, 0x1d, 0xec, 0xb7, - 0x8c, 0xa8, 0xd8, 0x44, 0x14, 0x16, 0xc7, 0xdf, 0x47, 0x0a, 0x72, 0xae, 0x15, 0xb4, 0x02, 0x76, - 0x34, 0xe2, 0x53, 0x52, 0xfd, 0x97, 0x22, 0xdf, 0x43, 0x61, 0x0f, 0xfb, 0xd4, 0x80, 0x4d, 0x17, - 0x1b, 0x74, 0xd8, 0x47, 0x64, 0x74, 0xa9, 0x5d, 0xf1, 0xe0, 0xbf, 0x13, 0xd8, 0xc5, 0x1e, 0xa4, - 0x41, 0x68, 0x23, 0x5a, 0x6e, 0x43, 0xbf, 0x85, 0xea, 0xd0, 0xed, 0x20, 0xba, 0x0b, 0x29, 0x94, - 0x02, 0xb0, 0x1e, 0x8d, 0xef, 0x9d, 0x41, 0xdf, 0x83, 0x14, 0x91, 0x3c, 0xaf, 0x66, 0x0a, 0x59, - 0x53, 0xd5, 0xef, 0x94, 0xf5, 0x58, 0x59, 0x9f, 0x28, 0x35, 0x58, 0x63, 0x49, 0xbd, 0xb8, 0xde, - 0xe4, 0x7e, 0x5f, 0x6f, 0xe6, 0x87, 0xb0, 0xd7, 0x7d, 0xa3, 0xcd, 0x09, 0x69, 0x96, 0x18, 0xdd, - 0x1f, 0x21, 0x52, 0x01, 0xc4, 0x35, 0x82, 0x68, 0xd2, 0xe4, 0x60, 0x2f, 0xbf, 0xa4, 0xf2, 0x05, - 0xc1, 0x5a, 0x1d, 0xd5, 0x47, 0x8d, 0x35, 0x4f, 0xfa, 0x1f, 0x00, 0xd2, 0x85, 0xa4, 0xed, 0x40, - 0xb7, 0x43, 0xf2, 0x19, 0x35, 0x53, 0x58, 0xb1, 0x56, 0x58, 0x65, 0xc7, 0xed, 0x10, 0x2d, 0x00, - 0x1b,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 0x7a, 0x31, 0xd9, 0xd3, - 0x91, 0x69, 0x7c, 0x66, 0xcb, 0x9a, 0xad, 0xcd, 0xe6, 0x32, 0xdb, 0x9b, 0xdb, 0x7f, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xb7, 0xf6, 0x8f, 0xaa, 0xd4, 0x05, 0x00, 0x00, + // 706 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0x4f, 0x6e, 0xda, 0x40, + 0x14, 0xc6, 0xed, 0x60, 0x45, 0xca, 0x20, 0x25, 0xc4, 0xa5, 0x15, 0x71, 0x5b, 0x62, 0x59, 0x51, + 0x8b, 0x5a, 0xd5, 0x2e, 0x4e, 0x17, 0x55, 0xbb, 0x69, 0x20, 0x44, 0xa0, 0xe6, 0x0f, 0xb2, 0x43, + 0xaa, 0x76, 0x63, 0x0d, 0xf6, 0x04, 0x46, 0x80, 0x8d, 0x3c, 0x83, 0x15, 0x6e, 0x50, 0x65, 0xd5, + 0x0b, 0x64, 0xd5, 0x43, 0x74, 0xdd, 0x5d, 0x96, 0xd9, 0x35, 0xab, 0xa8, 0x4a, 0x6e, 0xd0, 0x13, + 0x54, 0x1e, 0x1b, 0x42, 0xc0, 0x41, 0xca, 0x8a, 0x61, 0xe6, 0xbd, 0x0f, 0xbe, 0xdf, 0xfb, 0xf4, + 0xc0, 0x06, 0x76, 0x29, 0xf2, 0xed, 0x36, 0xc4, 0xae, 0x45, 0x90, 0x3d, 0xf0, 0x31, 0x1d, 0x6a, + 0xb6, 0x1d, 0x68, 0x41, 0x31, 0xfc, 0x50, 0xfb, 0xbe, 0x47, 0x3d, 0x51, 0x4a, 0xa8, 0x52, 0xc3, + 0xe7, 0xa0, 0x28, 0x6d, 0xd8, 0x1e, 0xe9, 0x79, 0x44, 0x23, 0x14, 0x76, 0xb0, 0xdb, 0xd2, 0x82, + 0x62, 0x13, 0x51, 0x58, 0x1c, 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0xff, 0xf8, 0xe1, 0xe2, 0x3f, 0xe6, 0x05, + 0x00, 0x00, } func (m *ValidatorSetChangePacketData) Marshal() (dAtA []byte, err error) { @@ -748,6 +758,11 @@ func (m *ConsumerPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Idx != 0 { + i = encodeVarintCcv(dAtA, i, uint64(m.Idx)) + i-- + dAtA[i] = 0x20 + } if m.Data != nil { { size := m.Data.Size() @@ -951,6 +966,9 @@ func (m *ConsumerPacketData) Size() (n int) { if m.Data != nil { n += m.Data.Size() } + if m.Idx != 0 { + n += 1 + sovCcv(uint64(m.Idx)) + } return n } @@ -1652,6 +1670,25 @@ func (m *ConsumerPacketData) Unmarshal(dAtA []byte) error { } m.Data = &ConsumerPacketData_VscMaturedPacketData{v} iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Idx", wireType) + } + m.Idx = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCcv + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Idx |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCcv(dAtA[iNdEx:]) From 6b6eabef82d8731f2f14a2fdc6fc18f26f653f19 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 12:28:41 -0700 Subject: [PATCH 02/18] tests --- x/ccv/consumer/keeper/keeper_test.go | 84 ++++++++++++++++++---------- x/ccv/consumer/keeper/relay_test.go | 9 +-- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index 2a8af31f25..9030072aa8 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -312,23 +312,25 @@ func TestGetAllCCValidator(t *testing.T) { require.Equal(t, result, expectedGetAllOrder) } -func TestSetPendingPackets(t *testing.T) { +func TestPendingPackets(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - // prepare test setup - dataPackets := []ccv.ConsumerPacketData{ + // Instantiate some expected packet data + packetData := []ccv.ConsumerPacketData{ { Type: ccv.VscMaturedPacket, Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ VscMaturedPacketData: ccv.NewVSCMaturedPacketData(1), }, + Idx: 0, // Note these are expected idxs, we don't pass this data to the keeper }, { Type: ccv.VscMaturedPacket, Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ VscMaturedPacketData: ccv.NewVSCMaturedPacketData(2), }, + Idx: 1, }, { Type: ccv.SlashPacket, @@ -339,19 +341,24 @@ func TestSetPendingPackets(t *testing.T) { stakingtypes.DoubleSign, ), }, + Idx: 2, }, { Type: ccv.VscMaturedPacket, Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ VscMaturedPacketData: ccv.NewVSCMaturedPacketData(3), }, + Idx: 3, }, } - consumerKeeper.SetPendingPackets(ctx, ccv.ConsumerPacketDataList{List: dataPackets}) - storedDataPackets := consumerKeeper.GetPendingPackets(ctx) - require.NotEmpty(t, storedDataPackets) - require.Equal(t, dataPackets, storedDataPackets.List) + // Append all packets to the queue + for _, data := range packetData { + consumerKeeper.AppendPendingPacket(ctx, data.Type, data.Data) + } + storedPacketData := consumerKeeper.GetPendingPackets(ctx) + require.NotEmpty(t, storedPacketData) + require.Equal(t, packetData, storedPacketData) slashPacket := ccv.NewSlashPacketData( abci.Validator{ @@ -361,31 +368,50 @@ func TestSetPendingPackets(t *testing.T) { uint64(4), stakingtypes.Downtime, ) - dataPackets = append(dataPackets, ccv.ConsumerPacketData{ + // Append slash packet to expected packet data + packetData = append(packetData, ccv.ConsumerPacketData{ Type: ccv.SlashPacket, - Data: &ccv.ConsumerPacketData_SlashPacketData{SlashPacketData: slashPacket}, - }, - ) - consumerKeeper.AppendPendingPacket(ctx, dataPackets[len(dataPackets)-1]) - storedDataPackets = consumerKeeper.GetPendingPackets(ctx) - require.NotEmpty(t, storedDataPackets) - require.Equal(t, dataPackets, storedDataPackets) + Data: &ccv.ConsumerPacketData_SlashPacketData{ + SlashPacketData: slashPacket, + }, + Idx: 4, + }) - vscMaturedPakcet := ccv.NewVSCMaturedPacketData(4) - dataPackets = append(dataPackets, ccv.ConsumerPacketData{ + toAppend := packetData[len(packetData)-1] + consumerKeeper.AppendPendingPacket(ctx, toAppend.Type, toAppend.Data) + storedPacketData = consumerKeeper.GetPendingPackets(ctx) + require.NotEmpty(t, storedPacketData) + require.Equal(t, packetData, storedPacketData) + + vscMaturedPacket := ccv.NewVSCMaturedPacketData(4) + packetData = append(packetData, ccv.ConsumerPacketData{ Type: ccv.VscMaturedPacket, - Data: &ccv.ConsumerPacketData_VscMaturedPacketData{VscMaturedPacketData: vscMaturedPakcet}, - }, - ) - consumerKeeper.AppendPendingPacket(ctx, dataPackets[len(dataPackets)-1]) - storedDataPackets = consumerKeeper.GetPendingPackets(ctx) - require.NotEmpty(t, storedDataPackets) - require.Equal(t, dataPackets, storedDataPackets.List) - - consumerKeeper.DeletePendingDataPackets(ctx) - storedDataPackets = consumerKeeper.GetPendingPackets(ctx) - require.Empty(t, storedDataPackets) - require.Len(t, storedDataPackets.List, 0) + Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ + VscMaturedPacketData: vscMaturedPacket, + }, + Idx: 5, + }) + toAppend = packetData[len(packetData)-1] + consumerKeeper.AppendPendingPacket(ctx, toAppend.Type, toAppend.Data) + + storedPacketData = consumerKeeper.GetPendingPackets(ctx) + require.NotEmpty(t, storedPacketData) + require.Equal(t, packetData, storedPacketData) + + // Delete packet with idx 5 (final index) + consumerKeeper.DeletePendingDataPackets(ctx, 5) + storedPacketData = consumerKeeper.GetPendingPackets(ctx) + require.Equal(t, packetData[:len(packetData)-1], storedPacketData) + + // Delete packet with idx 0 (first index) + consumerKeeper.DeletePendingDataPackets(ctx, 0) + storedPacketData = consumerKeeper.GetPendingPackets(ctx) + require.Equal(t, packetData[1:len(packetData)-1], storedPacketData) + + // Delete all packets + consumerKeeper.DeleteAllPendingDataPackets(ctx) + storedPacketData = consumerKeeper.GetPendingPackets(ctx) + require.Empty(t, storedPacketData) } // TestVerifyProviderChain tests the VerifyProviderChain method for the consumer keeper diff --git a/x/ccv/consumer/keeper/relay_test.go b/x/ccv/consumer/keeper/relay_test.go index 60fbbfe719..526be8dea4 100644 --- a/x/ccv/consumer/keeper/relay_test.go +++ b/x/ccv/consumer/keeper/relay_test.go @@ -17,6 +17,7 @@ import ( testkeeper "github.com/cosmos/interchain-security/v2/testutil/keeper" consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" "github.com/cosmos/interchain-security/v2/x/ccv/types" + ccv "github.com/cosmos/interchain-security/v2/x/ccv/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -290,9 +291,9 @@ func TestSendPacketsFailure(t *testing.T) { consumerKeeper.SetParams(ctx, consumertypes.DefaultParams()) // Set some pending packets - consumerKeeper.SetPendingPackets(ctx, types.ConsumerPacketDataList{List: []types.ConsumerPacketData{ - {}, {}, {}, - }}) + consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{}) + consumerKeeper.AppendPendingPacket(ctx, types.SlashPacket, &ccv.ConsumerPacketData_SlashPacketData{}) + consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{}) // Mock the channel keeper to return an error gomock.InOrder( @@ -302,5 +303,5 @@ func TestSendPacketsFailure(t *testing.T) { // No panic should occur, pending packets should not be cleared consumerKeeper.SendPackets(ctx) - require.Equal(t, 3, len(consumerKeeper.GetPendingPackets(ctx).List)) + require.Equal(t, 3, len(consumerKeeper.GetPendingPackets(ctx))) } From 84e02501ed3d9b0aa4567bc14f12b7905ad8f81f Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:10:02 -0700 Subject: [PATCH 03/18] tests --- proto/interchain_security/ccv/v1/ccv.proto | 2 +- tests/integration/expired_client.go | 5 ++--- tests/integration/slashing.go | 24 +++++++++++----------- x/ccv/consumer/keeper/genesis.go | 16 +++++++++++---- x/ccv/consumer/keeper/genesis_test.go | 9 ++++++-- x/ccv/consumer/keeper/relay_test.go | 7 +++---- x/ccv/consumer/keeper/validators_test.go | 4 ++-- x/ccv/types/ccv.pb.go | 2 +- 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/proto/interchain_security/ccv/v1/ccv.proto b/proto/interchain_security/ccv/v1/ccv.proto index cf68f07109..226dbc99bd 100644 --- a/proto/interchain_security/ccv/v1/ccv.proto +++ b/proto/interchain_security/ccv/v1/ccv.proto @@ -70,7 +70,7 @@ message ConsumerPacketData { } -// TODO: remove +// [Depreciated] favor using []ConsumerPacketData directly. // ConsumerPacketDataList is a list of consumer packet data packets. message ConsumerPacketDataList { repeated ConsumerPacketData list = 1 diff --git a/tests/integration/expired_client.go b/tests/integration/expired_client.go index 16abe75c35..d6e8d4f985 100644 --- a/tests/integration/expired_client.go +++ b/tests/integration/expired_client.go @@ -122,7 +122,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() { // check that the packets were added to the list of pending data packets consumerPackets := consumerKeeper.GetPendingPackets(s.consumerCtx()) s.Require().NotEmpty(consumerPackets) - s.Require().Equal(2, len(consumerPackets.GetList()), "unexpected number of pending data packets") + s.Require().Len(consumerPackets, 2, "unexpected number of pending data packets") // try to send slash packet for downtime infraction addr := ed25519.GenPrivKey().PubKey().Address() @@ -136,7 +136,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() { // check that the packets were added to the list of pending data packets consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx()) s.Require().NotEmpty(consumerPackets) - s.Require().Equal(4, len(consumerPackets.GetList()), "unexpected number of pending data packets") + s.Require().Len(consumerPackets, 4, "unexpected number of pending data packets") // upgrade expired client to the consumer upgradeExpiredClient(s, Provider) @@ -147,7 +147,6 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() { // check that the list of pending data packets is emptied consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx()) s.Require().Empty(consumerPackets) - s.Require().Equal(0, len(consumerPackets.GetList()), "unexpected number of pending data packets") // relay all packet from consumer to provider relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 4) diff --git a/tests/integration/slashing.go b/tests/integration/slashing.go index 6e60bc5df3..1aa5b1758c 100644 --- a/tests/integration/slashing.go +++ b/tests/integration/slashing.go @@ -486,15 +486,15 @@ func (suite *CCVTestSuite) TestValidatorDowntime() { // check that slash packet is queued pendingPackets := consumerKeeper.GetPendingPackets(ctx) - suite.Require().NotEmpty(pendingPackets.List, "pending packets empty") - suite.Require().Len(pendingPackets.List, 1, "pending packets len should be 1 is %d", len(pendingPackets.List)) + suite.Require().NotEmpty(pendingPackets, "pending packets empty") + suite.Require().Len(pendingPackets, 1, "pending packets len should be 1 is %d", len(pendingPackets)) // clear queue, commit packets suite.consumerApp.GetConsumerKeeper().SendPackets(ctx) // check queue was cleared pendingPackets = suite.consumerApp.GetConsumerKeeper().GetPendingPackets(ctx) - suite.Require().Empty(pendingPackets.List, "pending packets NOT empty") + suite.Require().Empty(pendingPackets, "pending packets NOT empty") // verify that the slash packet was sent gotCommit := consumerIBCKeeper.ChannelKeeper.GetPacketCommitment(ctx, ccv.ConsumerPortID, channelID, seq) @@ -573,15 +573,15 @@ func (suite *CCVTestSuite) TestValidatorDoubleSigning() { // check slash packet is queued pendingPackets := suite.consumerApp.GetConsumerKeeper().GetPendingPackets(ctx) - suite.Require().NotEmpty(pendingPackets.List, "pending packets empty") - suite.Require().Len(pendingPackets.List, 1, "pending packets len should be 1 is %d", len(pendingPackets.List)) + suite.Require().NotEmpty(pendingPackets, "pending packets empty") + suite.Require().Len(pendingPackets, 1, "pending packets len should be 1 is %d", len(pendingPackets)) // clear queue, commit packets suite.consumerApp.GetConsumerKeeper().SendPackets(ctx) // check queue was cleared pendingPackets = suite.consumerApp.GetConsumerKeeper().GetPendingPackets(ctx) - suite.Require().Empty(pendingPackets.List, "pending packets NOT empty") + suite.Require().Empty(pendingPackets, "pending packets NOT empty") // check slash packet is sent gotCommit := suite.consumerApp.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(ctx, ccv.ConsumerPortID, channelID, seq) @@ -636,7 +636,7 @@ func (suite *CCVTestSuite) TestQueueAndSendSlashPacket() { // the downtime slash request duplicates dataPackets := consumerKeeper.GetPendingPackets(ctx) suite.Require().NotEmpty(dataPackets) - suite.Require().Len(dataPackets.GetList(), 12) + suite.Require().Len(dataPackets, 12) // save consumer next sequence seq, _ := consumerIBCKeeper.ChannelKeeper.GetNextSequenceSend(ctx, ccv.ConsumerPortID, channelID) @@ -663,7 +663,7 @@ func (suite *CCVTestSuite) TestQueueAndSendSlashPacket() { // check that pending data packets got cleared dataPackets = consumerKeeper.GetPendingPackets(ctx) suite.Require().Empty(dataPackets) - suite.Require().Len(dataPackets.GetList(), 0) + suite.Require().Len(dataPackets, 0) } // TestCISBeforeCCVEstablished tests that the consumer chain doesn't panic or @@ -674,14 +674,14 @@ func (suite *CCVTestSuite) TestCISBeforeCCVEstablished() { // Check pending packets is empty pendingPackets := consumerKeeper.GetPendingPackets(suite.consumerCtx()) - suite.Require().Len(pendingPackets.List, 0) + suite.Require().Len(pendingPackets, 0) consumerKeeper.Slash(suite.consumerCtx(), []byte{0x01, 0x02, 0x3}, 66, 4324, sdk.MustNewDecFromStr("0.05"), stakingtypes.Downtime) // Check slash packet was queued pendingPackets = consumerKeeper.GetPendingPackets(suite.consumerCtx()) - suite.Require().Len(pendingPackets.List, 1) + suite.Require().Len(pendingPackets, 1) // Pass 5 blocks, confirming the consumer doesn't panic for i := 0; i < 5; i++ { @@ -690,7 +690,7 @@ func (suite *CCVTestSuite) TestCISBeforeCCVEstablished() { // Check packet is still queued pendingPackets = consumerKeeper.GetPendingPackets(suite.consumerCtx()) - suite.Require().Len(pendingPackets.List, 1) + suite.Require().Len(pendingPackets, 1) // establish ccv channel suite.SetupCCVChannel(suite.path) @@ -699,5 +699,5 @@ func (suite *CCVTestSuite) TestCISBeforeCCVEstablished() { // Pass one more block, and confirm the packet is sent now that ccv channel is established suite.consumerChain.NextBlock() pendingPackets = consumerKeeper.GetPendingPackets(suite.consumerCtx()) - suite.Require().Len(pendingPackets.List, 0) + suite.Require().Len(pendingPackets, 0) } diff --git a/x/ccv/consumer/keeper/genesis.go b/x/ccv/consumer/keeper/genesis.go index 08f6327909..69ce2e1773 100644 --- a/x/ccv/consumer/keeper/genesis.go +++ b/x/ccv/consumer/keeper/genesis.go @@ -89,9 +89,12 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) k.SetLastTransmissionBlockHeight(ctx, state.LastTransmissionBlockHeight) } - // set pending consumer pending packets + // Set pending consumer packets, using the depreciated ConsumerPacketDataList type + // that exists for genesis. // note that the list includes pending mature VSC packet only if the handshake is completed - k.AppendPendingPacket(ctx, state.PendingConsumerPackets.List...) + for _, packet := range state.PendingConsumerPackets.List { + k.AppendPendingPacket(ctx, packet.Type, packet.Data) + } // set height to valset update id mapping for _, h2v := range state.HeightToValsetUpdateId { @@ -122,6 +125,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt // export the current validator set valset := k.MustGetCurrentValidatorsAsABCIUpdates(ctx) + // export pending packets using the depreciated ConsumerPacketDataList type + pendingPackets := k.GetPendingPackets(ctx) + pendingPacketsDepreciated := ccv.ConsumerPacketDataList{} + pendingPacketsDepreciated.List = append(pendingPacketsDepreciated.List, pendingPackets...) + // export all the states created after a provider channel got established if channelID, ok := k.GetProviderChannel(ctx); ok { clientID, found := k.GetProviderClientID(ctx) @@ -136,7 +144,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt k.GetAllPacketMaturityTimes(ctx), valset, k.GetAllHeightToValsetUpdateIDs(ctx), - k.GetPendingPackets(ctx), + pendingPacketsDepreciated, k.GetAllOutstandingDowntimes(ctx), k.GetLastTransmissionBlockHeight(ctx), params, @@ -156,7 +164,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt nil, valset, k.GetAllHeightToValsetUpdateIDs(ctx), - k.GetPendingPackets(ctx), + pendingPacketsDepreciated, nil, consumertypes.LastTransmissionBlockHeight{}, params, diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 55c5c41b19..fd8bbf89e1 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -291,7 +291,10 @@ func TestExportGenesis(t *testing.T) { ck.SetCCValidator(ctx, cVal) ck.SetParams(ctx, params) - ck.AppendPendingPacket(ctx, consPackets.List...) + for _, packet := range consPackets.List { + ck.AppendPendingPacket(ctx, packet.Type, packet.Data) + } + ck.SetHeightValsetUpdateID(ctx, defaultHeightValsetUpdateIDs[0].Height, defaultHeightValsetUpdateIDs[0].ValsetUpdateId) }, consumertypes.NewRestartGenesisState( @@ -321,7 +324,9 @@ func TestExportGenesis(t *testing.T) { ck.SetHeightValsetUpdateID(ctx, updatedHeightValsetUpdateIDs[0].Height, updatedHeightValsetUpdateIDs[0].ValsetUpdateId) ck.SetHeightValsetUpdateID(ctx, updatedHeightValsetUpdateIDs[1].Height, updatedHeightValsetUpdateIDs[1].ValsetUpdateId) - ck.AppendPendingPacket(ctx, consPackets.List...) + for _, packet := range consPackets.List { + ck.AppendPendingPacket(ctx, packet.Type, packet.Data) + } // populate the required states for an established CCV channel ck.SetPacketMaturityTime(ctx, matPackets[0].VscId, matPackets[0].MaturityTime) diff --git a/x/ccv/consumer/keeper/relay_test.go b/x/ccv/consumer/keeper/relay_test.go index 526be8dea4..edf5058f0f 100644 --- a/x/ccv/consumer/keeper/relay_test.go +++ b/x/ccv/consumer/keeper/relay_test.go @@ -17,7 +17,6 @@ import ( testkeeper "github.com/cosmos/interchain-security/v2/testutil/keeper" consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" "github.com/cosmos/interchain-security/v2/x/ccv/types" - ccv "github.com/cosmos/interchain-security/v2/x/ccv/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -291,9 +290,9 @@ func TestSendPacketsFailure(t *testing.T) { consumerKeeper.SetParams(ctx, consumertypes.DefaultParams()) // Set some pending packets - consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{}) - consumerKeeper.AppendPendingPacket(ctx, types.SlashPacket, &ccv.ConsumerPacketData_SlashPacketData{}) - consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{}) + consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &types.ConsumerPacketData_VscMaturedPacketData{}) + consumerKeeper.AppendPendingPacket(ctx, types.SlashPacket, &types.ConsumerPacketData_SlashPacketData{}) + consumerKeeper.AppendPendingPacket(ctx, types.VscMaturedPacket, &types.ConsumerPacketData_VscMaturedPacketData{}) // Mock the channel keeper to return an error gomock.InOrder( diff --git a/x/ccv/consumer/keeper/validators_test.go b/x/ccv/consumer/keeper/validators_test.go index a5ad0898e2..088075b220 100644 --- a/x/ccv/consumer/keeper/validators_test.go +++ b/x/ccv/consumer/keeper/validators_test.go @@ -149,7 +149,7 @@ func TestSlash(t *testing.T) { // If we call slash with infraction type empty, no slash packet will be queued consumerKeeper.Slash(ctx, []byte{0x01, 0x02, 0x03}, 5, 6, sdk.NewDec(9.0), stakingtypes.InfractionEmpty) pendingPackets := consumerKeeper.GetPendingPackets(ctx) - require.Len(t, pendingPackets.List, 0) + require.Len(t, pendingPackets, 0) // Consumer keeper from test setup should return false for IsPrevStandaloneChain() require.False(t, consumerKeeper.IsPrevStandaloneChain(ctx)) @@ -160,7 +160,7 @@ func TestSlash(t *testing.T) { // Call slash with valid infraction type and confirm 1 slash packet is queued consumerKeeper.Slash(ctx, []byte{0x01, 0x02, 0x03}, 5, 6, sdk.NewDec(9.0), stakingtypes.Downtime) pendingPackets = consumerKeeper.GetPendingPackets(ctx) - require.Len(t, pendingPackets.List, 1) + require.Len(t, pendingPackets, 1) // Next, we set a value for the standalone staking keeper, // and mark the consumer keeper as being from a previous standalone chain diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 9d2cea8b9b..378f6c4eb8 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -428,7 +428,7 @@ func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { } } -// TODO: remove +// [Depreciated] favor using []ConsumerPacketData directly. // ConsumerPacketDataList is a list of consumer packet data packets. type ConsumerPacketDataList struct { List []ConsumerPacketData `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` From 0eafb058ff66e1a8aee5c6b2dd6a1d2843ea290d Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:27:01 -0700 Subject: [PATCH 04/18] update genesis tests --- x/ccv/consumer/keeper/genesis_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index fd8bbf89e1..5e60bbb905 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -148,7 +148,12 @@ func TestInitGenesis(t *testing.T) { func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.GenesisState) { assertConsumerPortIsBound(t, ctx, &ck) - require.Equal(t, pendingDataPackets, ck.GetPendingPackets(ctx)) + obtainedPendingPackets := ck.GetPendingPackets(ctx) + for idx, expectedPacketData := range pendingDataPackets.List { + require.Equal(t, expectedPacketData.Type, obtainedPendingPackets[idx].Type) + require.Equal(t, expectedPacketData.Data, obtainedPendingPackets[idx].Data) + } + assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs) assertProviderClientID(t, ctx, &ck, provClientID) require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address) @@ -186,7 +191,12 @@ func TestInitGenesis(t *testing.T) { require.Equal(t, provChannelID, gotChannelID) require.True(t, ck.PacketMaturityTimeExists(ctx, matPackets[0].VscId, matPackets[0].MaturityTime)) - require.Equal(t, pendingDataPackets, ck.GetPendingPackets(ctx)) + + obtainedPendingPackets := ck.GetPendingPackets(ctx) + for idx, expectedPacketData := range pendingDataPackets.List { + require.Equal(t, expectedPacketData.Type, obtainedPendingPackets[idx].Type) + require.Equal(t, expectedPacketData.Data, obtainedPendingPackets[idx].Data) + } require.Equal(t, gs.OutstandingDowntimeSlashing, ck.GetAllOutstandingDowntimes(ctx)) @@ -252,12 +262,16 @@ func TestExportGenesis(t *testing.T) { Data: &ccv.ConsumerPacketData_SlashPacketData{ SlashPacketData: ccv.NewSlashPacketData(abciValidator, vscID, stakingtypes.Downtime), }, + Idx: 0, }, { Type: ccv.VscMaturedPacket, Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ VscMaturedPacketData: ccv.NewVSCMaturedPacketData(vscID), }, + // This idx is a part of the expected genesis state. + // If the keeper is correctly storing consumer packet data, indexes should be populated. + Idx: 1, }, }, } From 1af896f4e36893afaa30b9362a4220c40c3e1dc8 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:43:59 -0700 Subject: [PATCH 05/18] comments --- proto/interchain_security/ccv/v1/ccv.proto | 4 +++- x/ccv/consumer/keeper/keeper.go | 4 ++-- x/ccv/consumer/types/keys.go | 8 ++++++-- x/ccv/consumer/types/keys_test.go | 2 +- x/ccv/types/ccv.pb.go | 4 +++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/proto/interchain_security/ccv/v1/ccv.proto b/proto/interchain_security/ccv/v1/ccv.proto index 226dbc99bd..82ba3434f7 100644 --- a/proto/interchain_security/ccv/v1/ccv.proto +++ b/proto/interchain_security/ccv/v1/ccv.proto @@ -70,8 +70,10 @@ message ConsumerPacketData { } -// [Depreciated] favor using []ConsumerPacketData directly. +// [Depreciated] favor using []ConsumerPacketData directly, which can be stored more efficiently. +// // ConsumerPacketDataList is a list of consumer packet data packets. +// It is only used for genesis to ensure backwards compatibility with older versions of ICS. message ConsumerPacketDataList { repeated ConsumerPacketData list = 1 [ (gogoproto.nullable) = false ]; diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 65e1413df5..5796d8b36e 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -571,6 +571,8 @@ func PendingDataPacketsIterator(store sdk.KVStore) sdk.Iterator { return sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) } +// getAndIncrementPendingPacketsIdx returns the current pending packets index and increments it. +// This index is used for implementing a FIFO queue of pending packets in the KV store. func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.PendingPacketsIndexKey()) @@ -613,8 +615,6 @@ func (k Keeper) DeletePendingDataPackets(ctx sdk.Context, idxs ...uint64) { func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. - // See consistency with PendingDataPacketsKey(). iterator := PendingDataPacketsIterator(store) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index 4252ee5ee8..c0a5e378ba 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -97,7 +97,9 @@ const ( // PrevStandaloneChainByteKey is the byte storing the flag marking whether this chain was previously standalone PrevStandaloneChainByteKey - PendingPacketsIndexBytePrefix + // PendingPacketsIndexBytePrefix is the single byte key to the pending packets index. + // This index is used for implementing a FIFO queue of pending packets in the KV store. + PendingPacketsIndexByteKey // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go ) @@ -209,8 +211,10 @@ func PrevStandaloneChainKey() []byte { return []byte{PrevStandaloneChainByteKey} } +// PendingPacketsIndexKey returns the key to the pending packets index. +// This index is used for implementing a FIFO queue of pending packets in the KV store. func PendingPacketsIndexKey() []byte { - return []byte{PendingPacketsIndexBytePrefix} + return []byte{PendingPacketsIndexByteKey} } // NOTE: DO NOT ADD FULLY DEFINED KEY FUNCTIONS WITHOUT ADDING THEM TO getAllFullyDefinedKeys() IN keys_test.go diff --git a/x/ccv/consumer/types/keys_test.go b/x/ccv/consumer/types/keys_test.go index ee92d0734c..5290dd3599 100644 --- a/x/ccv/consumer/types/keys_test.go +++ b/x/ccv/consumer/types/keys_test.go @@ -41,7 +41,7 @@ func getAllKeyPrefixes() []byte { InitGenesisHeightByteKey, StandaloneTransferChannelIDByteKey, PrevStandaloneChainByteKey, - PendingPacketsIndexBytePrefix, + PendingPacketsIndexByteKey, } } diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 378f6c4eb8..0a7646cb7b 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -428,8 +428,10 @@ func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { } } -// [Depreciated] favor using []ConsumerPacketData directly. +// [Depreciated] favor using []ConsumerPacketData directly, which can be stored more efficiently. +// // ConsumerPacketDataList is a list of consumer packet data packets. +// It is only used for genesis to ensure backwards compatibility with older versions of ICS. type ConsumerPacketDataList struct { List []ConsumerPacketData `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` } From cf2359de3f43abca9db0294123940415d4d1a1d4 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:24:46 -0700 Subject: [PATCH 06/18] migration and changelog --- CHANGELOG.md | 2 ++ x/ccv/consumer/keeper/migration.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5960c76238..852196a3bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Add an entry to the unreleased section whenever merging a PR to main that is not targeted at a specific release. These entries will eventually be included in a release. +* (feat!) optimize pending packets storage on consumer, with migration! [#1037](https://github.com/cosmos/interchain-security/pull/1037) + ## v.2.0.0 Date: June 1st, 2023 diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index a44b89404b..0344788863 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -77,3 +78,30 @@ func MigrateParamsv1Tov2(ctx sdk.Context, paramsSubspace paramtypes.Subspace) { // Persist new params paramsSubspace.SetParamSet(ctx, &newParams) } + +// MigrateConsumerPacketData migrates consumer packet data according to +// https://github.com/cosmos/interchain-security/pull/1037 +func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { + // 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 + } + 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)) + } + + // Delete old data + store.Delete([]byte{consumertypes.PendingDataPacketsBytePrefix}) + + // re-serialize packet data in new format, with the same key prefix, + // where indexes are added internally to AppendPendingPacket. + for _, data := range depreciatedType.List { + k.AppendPendingPacket(ctx, data.Type, data.Data) + } +} From 1c7e7df23d926c342e115167b1718bc369d0c47e Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:11:31 -0700 Subject: [PATCH 07/18] migration test --- x/ccv/consumer/keeper/migration.go | 23 ++++++++++ x/ccv/consumer/keeper/migration_test.go | 59 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 0344788863..a301b5d35f 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -6,7 +6,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" + ccv "github.com/cosmos/interchain-security/v2/x/ccv/types" ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" ) @@ -81,6 +83,8 @@ func MigrateParamsv1Tov2(ctx sdk.Context, paramsSubspace paramtypes.Subspace) { // 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) { // deserialize packet data from old format var depreciatedType ccvtypes.ConsumerPacketDataList @@ -105,3 +109,22 @@ func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { k.AppendPendingPacket(ctx, data.Type, data.Data) } } + +// TODO: the following hackyness could be removed if we're able to reference older versions of ICS. +// This would likely require go.mod split, and a testing module that could depend on multiple ICS versions. + +func PendingDataPacketsKeyOnlyForTesting() []byte { + return []byte{types.PendingDataPacketsBytePrefix} // Assumes keys haven't been shuffled +} + +// Note: a better test of the old functionality would be to directly reference the old ICS version, +// including the version of ccv.ConsumerPacketDataList has a list of ccv.ConsumerPacketData without indexes. +func (k Keeper) SetPendingPacketsOnlyForTesting(ctx sdk.Context, packets ccv.ConsumerPacketDataList) { + store := ctx.KVStore(k.storeKey) + bz, err := packets.Marshal() + if err != nil { + // This should never happen + panic(fmt.Errorf("failed to marshal ConsumerPacketDataList: %w", err)) + } + store.Set(PendingDataPacketsKeyOnlyForTesting(), bz) +} diff --git a/x/ccv/consumer/keeper/migration_test.go b/x/ccv/consumer/keeper/migration_test.go index 29574a4808..4fc76fedad 100644 --- a/x/ccv/consumer/keeper/migration_test.go +++ b/x/ccv/consumer/keeper/migration_test.go @@ -10,6 +10,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + testutil "github.com/cosmos/interchain-security/v2/testutil/keeper" consumerkeeper "github.com/cosmos/interchain-security/v2/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" @@ -144,3 +145,61 @@ type v1Params struct { HistoricalEntries int64 `protobuf:"varint,8,opt,name=historical_entries,json=historicalEntries,proto3" json:"historical_entries,omitempty"` UnbondingPeriod time.Duration `protobuf:"bytes,9,opt,name=unbonding_period,json=unbondingPeriod,proto3,stdduration" json:"unbonding_period"` } + +func TestMigrateConsumerPacketData(t *testing.T) { + consumerKeeper, ctx, ctrl, _ := testutil.GetConsumerKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + // Set some pending data packets in the old format + packets := ccvtypes.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, + }, + }, + }, + }, + } + + // Set old data + consumerKeeper.SetPendingPacketsOnlyForTesting(ctx, packets) + + // Migrate + consumerKeeper.MigrateConsumerPacketData(ctx) + + // Check that the data is migrated properly + obtainedPackets := consumerKeeper.GetPendingPackets(ctx) + require.Len(t, packets.List, 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) + + // Check that indexes are populated + require.Equal(t, uint64(0), obtainedPackets[0].Idx) + require.Equal(t, uint64(1), obtainedPackets[1].Idx) + require.Equal(t, uint64(2), obtainedPackets[2].Idx) +} From 98dd22637af3e825d03207c27b34a829289c85f4 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:35:17 -0700 Subject: [PATCH 08/18] lints --- x/ccv/consumer/keeper/migration.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index a301b5d35f..03d7d3f263 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -6,9 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" - ccv "github.com/cosmos/interchain-security/v2/x/ccv/types" ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" ) @@ -114,12 +112,12 @@ func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { // This would likely require go.mod split, and a testing module that could depend on multiple ICS versions. func PendingDataPacketsKeyOnlyForTesting() []byte { - return []byte{types.PendingDataPacketsBytePrefix} // Assumes keys haven't been shuffled + return []byte{consumertypes.PendingDataPacketsBytePrefix} // Assumes keys haven't been shuffled } // Note: a better test of the old functionality would be to directly reference the old ICS version, // including the version of ccv.ConsumerPacketDataList has a list of ccv.ConsumerPacketData without indexes. -func (k Keeper) SetPendingPacketsOnlyForTesting(ctx sdk.Context, packets ccv.ConsumerPacketDataList) { +func (k Keeper) SetPendingPacketsOnlyForTesting(ctx sdk.Context, packets ccvtypes.ConsumerPacketDataList) { store := ctx.KVStore(k.storeKey) bz, err := packets.Marshal() if err != nil { From d4393e983a8b2c56a4544c62fb5483dacfc98fcf Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 21 Jun 2023 09:50:42 -0700 Subject: [PATCH 09/18] merge fixes --- x/ccv/consumer/keeper/keeper.go | 11 ---- x/ccv/types/ccv.pb.go | 89 +++++++++++++++++---------------- 2 files changed, 45 insertions(+), 55 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 9ec930a98c..885a4dc61b 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -592,17 +592,6 @@ func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Val return validators } -// SetPendingPackets sets the pending CCV packets -func (k Keeper) SetPendingPackets(ctx sdk.Context, packets ccv.ConsumerPacketDataList) { - store := ctx.KVStore(k.storeKey) - bz, err := packets.Marshal() - if err != nil { - // This should never happen - panic(fmt.Errorf("failed to marshal ConsumerPacketDataList: %w", err)) - } - store.Set(types.PendingDataPacketsKey(), bz) -} - // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). func PendingDataPacketsIterator(store sdk.KVStore) sdk.Iterator { diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 638371e6c8..0f87af60bc 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -493,51 +493,52 @@ func init() { } var fileDescriptor_68bd5f3242e6f29c = []byte{ - // 697 bytes of a gzipped FileDescriptorProto + // 707 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcf, 0x6a, 0xdb, 0x4a, - 0x14, 0xc6, 0xa5, 0x58, 0x04, 0x32, 0x86, 0x44, 0xd1, 0xf5, 0xbd, 0x38, 0xba, 0xad, 0x22, 0x44, - 0xa0, 0xa6, 0xa5, 0x52, 0xad, 0x74, 0x51, 0xda, 0x4d, 0x63, 0xc7, 0xc1, 0xa6, 0xf9, 0x63, 0xa4, - 0x38, 0xa5, 0xdd, 0x88, 0xb1, 0x34, 0xb1, 0x07, 0xdb, 0x1a, 0xa3, 0x19, 0x8b, 0xfa, 0x0d, 0x4a, - 0x56, 0x7d, 0x81, 0xac, 0x4a, 0x1f, 0xa4, 0xbb, 0x2c, 0x03, 0xdd, 0x64, 0x15, 0x4a, 0xf2, 0x06, - 0x7d, 0x82, 0x22, 0x59, 0x76, 0x1c, 0x5b, 0x31, 0x64, 0xe5, 0xf1, 0x99, 0x73, 0x3e, 0xf1, 0xfd, - 0xe6, 0xe3, 0x80, 0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 0x2e, 0xa4, 0x6d, 0x07, 0xba, - 0x1d, 0x9a, 0xcf, 0xa8, 0x99, 0xc2, 0x8a, 0xb5, 0x12, 0x57, 0x76, 0xdc, 0x0e, 0xd5, 0x08, 0xd8, - 0x78, 0xc8, 0x19, 0x95, 0x2c, 0x20, 0x74, 0x31, 0x65, 0x89, 0x93, 0x37, 0xfa, 0xc3, 0xec, 0xf5, - 0x45, 0x78, 0x4a, 0x42, 0xe4, 0xd0, 0x8a, 0xb5, 0xb4, 0xf7, 0x20, 0x77, 0x62, 0x97, 0x0f, 0x20, - 0x1b, 0x04, 0xc8, 0x9b, 0x42, 0x98, 0xe6, 0x88, 0x4f, 0x73, 0xa4, 0xfd, 0xe2, 0xc1, 0x9a, 0x1d, - 0x19, 0x98, 0x9a, 0xb6, 0xc0, 0xca, 0x84, 0x51, 0x3c, 0x96, 0x35, 0xe5, 0x87, 0xc1, 0x97, 0xf2, - 0x09, 0x72, 0x71, 0x06, 0xb9, 0x66, 0xdd, 0xc9, 0x3c, 0x82, 0x71, 0x09, 0x00, 0xec, 0x9f, 0x06, - 0xd0, 0x65, 0x98, 0xf8, 0xf9, 0x8c, 0xca, 0x17, 0x56, 0x4d, 0x4d, 0x1f, 0xa5, 0x51, 0x1f, 0xa7, - 0x2f, 0x49, 0xa3, 0x5e, 0x9b, 0x74, 0x5a, 0x53, 0x53, 0xda, 0x33, 0xf0, 0x4f, 0x02, 0xa5, 0xe1, - 0x37, 0x89, 0xef, 0x61, 0xbf, 0x75, 0xd4, 0xa7, 0x92, 0x08, 0x32, 0xd8, 0x1b, 0x65, 0x49, 0xb0, - 0xa2, 0xa3, 0xf6, 0x63, 0x09, 0x48, 0x65, 0xe2, 0xd3, 0x41, 0x0f, 0x05, 0x53, 0x04, 0xf6, 0x80, - 0x10, 0x45, 0x36, 0x36, 0xbf, 0x6a, 0x9a, 0x8b, 0xde, 0x6a, 0x7e, 0xfa, 0x78, 0xd8, 0x47, 0x56, - 0x3c, 0x2f, 0x7d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0x00, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x22, 0x37, 0xc9, 0xe2, + 0x05, 0x00, 0x00, } func (m *ValidatorSetChangePacketData) Marshal() (dAtA []byte, err error) { From 18f852a32bf1393229a44f09e7da6cdf7a03308f Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 21 Jun 2023 10:37:04 -0700 Subject: [PATCH 10/18] clean --- x/ccv/consumer/keeper/migration.go | 63 +---------- x/ccv/consumer/keeper/migration_test.go | 142 +----------------------- 2 files changed, 4 insertions(+), 201 deletions(-) diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 03d7d3f263..6a06a48925 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -2,12 +2,11 @@ package keeper import ( "fmt" - "time" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" + consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // Migrator is a struct for handling in-place store migrations. @@ -21,64 +20,6 @@ func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subs return Migrator{ccvConsumerKeeper: ccvConsumerKeeper, ccvConsumerParamSpace: ccvConsumerParamSpace} } -// Note: If migrating from v1.2.0-multiden to v2.0.0, there are no migrations required. -// This is due to the fact that the former version includes both of: -// - https://github.com/cosmos/interchain-security/commit/54e9852d3c89a2513cd0170a56c6eec894fc878d -// - https://github.com/cosmos/interchain-security/pull/833 -// both of which handle the introduction of new params. - -// Migratev1Tov2 migrates a consumer from v1.0.0 to v2.0.0. -func (m Migrator) Migratev1Tov2(ctx sdk.Context) error { - // Migrate params - MigrateParamsv1Tov2(ctx, m.ccvConsumerParamSpace) - - return nil -} - -// MigrateParamsv1Tov2 migrates the consumer CCV module params from v1.0.0 to v2.0.0, -// setting default values for new params. -func MigrateParamsv1Tov2(ctx sdk.Context, paramsSubspace paramtypes.Subspace) { - // Get old params - var enabled bool - paramsSubspace.Get(ctx, consumertypes.KeyEnabled, &enabled) - var blocksPerDistributionTransmission int64 - paramsSubspace.Get(ctx, consumertypes.KeyBlocksPerDistributionTransmission, &blocksPerDistributionTransmission) - var distributionTransmissionChannel string - paramsSubspace.Get(ctx, consumertypes.KeyDistributionTransmissionChannel, &distributionTransmissionChannel) - var providerFeePoolAddrStr string - paramsSubspace.Get(ctx, consumertypes.KeyProviderFeePoolAddrStr, &providerFeePoolAddrStr) - var ccvTimeoutPeriod time.Duration - paramsSubspace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &ccvTimeoutPeriod) - var transferTimeoutPeriod time.Duration - paramsSubspace.Get(ctx, consumertypes.KeyTransferTimeoutPeriod, &transferTimeoutPeriod) - var consumerRedistributionFrac string - paramsSubspace.Get(ctx, consumertypes.KeyConsumerRedistributionFrac, &consumerRedistributionFrac) - var historicalEntries int64 - paramsSubspace.Get(ctx, consumertypes.KeyHistoricalEntries, &historicalEntries) - var unbondingPeriod time.Duration - paramsSubspace.Get(ctx, consumertypes.KeyConsumerUnbondingPeriod, &unbondingPeriod) - - // Recycle old params, set new params to default values - defaultParams := consumertypes.DefaultParams() - newParams := consumertypes.NewParams( - enabled, - blocksPerDistributionTransmission, - distributionTransmissionChannel, - providerFeePoolAddrStr, - ccvTimeoutPeriod, - transferTimeoutPeriod, - consumerRedistributionFrac, - historicalEntries, - unbondingPeriod, - defaultParams.SoftOptOutThreshold, - defaultParams.RewardDenoms, - defaultParams.ProviderRewardDenoms, - ) - - // Persist new params - paramsSubspace.SetParamSet(ctx, &newParams) -} - // MigrateConsumerPacketData migrates consumer packet data according to // https://github.com/cosmos/interchain-security/pull/1037 // diff --git a/x/ccv/consumer/keeper/migration_test.go b/x/ccv/consumer/keeper/migration_test.go index 4fc76fedad..f284c1d0bf 100644 --- a/x/ccv/consumer/keeper/migration_test.go +++ b/x/ccv/consumer/keeper/migration_test.go @@ -2,150 +2,12 @@ package keeper_test import ( "testing" - "time" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - testutil "github.com/cosmos/interchain-security/v2/testutil/keeper" - consumerkeeper "github.com/cosmos/interchain-security/v2/x/ccv/consumer/keeper" - consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types" - ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmdb "github.com/tendermint/tm-db" ) -func TestMigrateParamsv1Tov2(t *testing.T) { - // Setup raw store - db := tmdb.NewMemDB() - stateStore := store.NewCommitMultiStore(db) - storeKey := sdk.NewKVStoreKey(paramtypes.StoreKey) - memStoreKey := storetypes.NewMemoryStoreKey("mem_key") - stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db) - stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) - registry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(registry) - ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - require.NoError(t, stateStore.LoadLatestVersion()) - - // Create new empty subspace - subspace := paramtypes.NewSubspace(cdc, - codec.NewLegacyAmino(), - storeKey, - memStoreKey, - paramtypes.ModuleName, - ).WithKeyTable(v1KeyTable()) // Note that new param key table is set in keeper constructor - - // Set 9 params from v1.0.0 - subspace.Set(ctx, consumertypes.KeyEnabled, true) - subspace.Set(ctx, consumertypes.KeyBlocksPerDistributionTransmission, int64(10)) - subspace.Set(ctx, consumertypes.KeyDistributionTransmissionChannel, "channel-0") - subspace.Set(ctx, consumertypes.KeyProviderFeePoolAddrStr, "cosmos17p3erf5gv2436fd4vyjwmudakts563a497syuz") - subspace.Set(ctx, ccvtypes.KeyCCVTimeoutPeriod, time.Hour) - subspace.Set(ctx, consumertypes.KeyTransferTimeoutPeriod, time.Hour) - subspace.Set(ctx, consumertypes.KeyConsumerRedistributionFrac, "0.5") - subspace.Set(ctx, consumertypes.KeyHistoricalEntries, int64(10)) - subspace.Set(ctx, consumertypes.KeyConsumerUnbondingPeriod, time.Hour) - - // Confirm 3 new params cannot be set with old key table - require.Panics(t, func() { - subspace.Set(ctx, consumertypes.KeySoftOptOutThreshold, "0.05") - }) - require.Panics(t, func() { - subspace.Set(ctx, consumertypes.KeyRewardDenoms, []string{"untrn"}) - }) - require.Panics(t, func() { - subspace.Set(ctx, consumertypes.KeyProviderRewardDenoms, []string{"uatom"}) - }) - - // Now create new subspace, mocking an upgrade where app initialization happens again - subspace = paramtypes.NewSubspace(cdc, - codec.NewLegacyAmino(), - storeKey, - memStoreKey, - paramtypes.ModuleName, - ).WithKeyTable(consumertypes.ParamKeyTable()) // Use v2 key table, this would be set in keeper constructor upon app init - - // Run migration - consumerkeeper.MigrateParamsv1Tov2(ctx, subspace) - - // Use keeper to confirm params are set correctly - keeper := consumerkeeper.Keeper{} - keeper.SetParamSpace(ctx, subspace) - - params := keeper.GetParams(ctx) - require.Equal(t, true, params.Enabled) - require.Equal(t, int64(10), params.BlocksPerDistributionTransmission) - require.Equal(t, "channel-0", params.DistributionTransmissionChannel) - require.Equal(t, "cosmos17p3erf5gv2436fd4vyjwmudakts563a497syuz", params.ProviderFeePoolAddrStr) - require.Equal(t, time.Hour, params.CcvTimeoutPeriod) - require.Equal(t, time.Hour, params.TransferTimeoutPeriod) - require.Equal(t, "0.5", params.ConsumerRedistributionFraction) - require.Equal(t, int64(10), params.HistoricalEntries) - require.Equal(t, time.Hour, params.UnbondingPeriod) - // 3 new params are set to default values - require.Equal(t, "0.05", params.SoftOptOutThreshold) - require.Equal(t, []string(nil), params.RewardDenoms) - require.Equal(t, []string(nil), params.ProviderRewardDenoms) - - // Set new params to other values - params.SoftOptOutThreshold = "0.1" - params.RewardDenoms = []string{"untrn"} - params.ProviderRewardDenoms = []string{"uatom"} - keeper.SetParams(ctx, params) - - require.Equal(t, "0.1", keeper.GetSoftOptOutThreshold(ctx)) - require.Equal(t, []string{"untrn"}, keeper.GetRewardDenoms(ctx)) - require.Equal(t, []string{"uatom"}, keeper.GetProviderRewardDenoms(ctx)) -} - -// v1KeyTable is a copy of the ParamKeyTable method from v1.0.0 -func v1KeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&v1Params{}) -} - -// ParamSetPairs implements params.ParamSet for v1Params -func (p *v1Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(consumertypes.KeyEnabled, p.Enabled, ccvtypes.ValidateBool), - paramtypes.NewParamSetPair(consumertypes.KeyBlocksPerDistributionTransmission, - p.BlocksPerDistributionTransmission, ccvtypes.ValidatePositiveInt64), - paramtypes.NewParamSetPair(consumertypes.KeyDistributionTransmissionChannel, - p.DistributionTransmissionChannel, ccvtypes.ValidateDistributionTransmissionChannel), - paramtypes.NewParamSetPair(consumertypes.KeyProviderFeePoolAddrStr, - p.ProviderFeePoolAddrStr, consumertypes.ValidateProviderFeePoolAddrStr), - paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod, - p.CcvTimeoutPeriod, ccvtypes.ValidateDuration), - paramtypes.NewParamSetPair(consumertypes.KeyTransferTimeoutPeriod, - p.TransferTimeoutPeriod, ccvtypes.ValidateDuration), - paramtypes.NewParamSetPair(consumertypes.KeyConsumerRedistributionFrac, - p.ConsumerRedistributionFraction, ccvtypes.ValidateStringFraction), - paramtypes.NewParamSetPair(consumertypes.KeyHistoricalEntries, - p.HistoricalEntries, ccvtypes.ValidatePositiveInt64), - paramtypes.NewParamSetPair(consumertypes.KeyConsumerUnbondingPeriod, - p.UnbondingPeriod, ccvtypes.ValidateDuration), - } -} - -// v1Params is a copy of the pb generated Params struct from v1.0.0 -type v1Params struct { - Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"` - BlocksPerDistributionTransmission int64 `protobuf:"varint,2,opt,name=blocks_per_distribution_transmission,json=blocksPerDistributionTransmission,proto3" json:"blocks_per_distribution_transmission,omitempty"` - DistributionTransmissionChannel string `protobuf:"bytes,3,opt,name=distribution_transmission_channel,json=distributionTransmissionChannel,proto3" json:"distribution_transmission_channel,omitempty"` - ProviderFeePoolAddrStr string `protobuf:"bytes,4,opt,name=provider_fee_pool_addr_str,json=providerFeePoolAddrStr,proto3" json:"provider_fee_pool_addr_str,omitempty"` - CcvTimeoutPeriod time.Duration `protobuf:"bytes,5,opt,name=ccv_timeout_period,json=ccvTimeoutPeriod,proto3,stdduration" json:"ccv_timeout_period"` - TransferTimeoutPeriod time.Duration `protobuf:"bytes,6,opt,name=transfer_timeout_period,json=transferTimeoutPeriod,proto3,stdduration" json:"transfer_timeout_period"` - ConsumerRedistributionFraction string `protobuf:"bytes,7,opt,name=consumer_redistribution_fraction,json=consumerRedistributionFraction,proto3" json:"consumer_redistribution_fraction,omitempty"` - HistoricalEntries int64 `protobuf:"varint,8,opt,name=historical_entries,json=historicalEntries,proto3" json:"historical_entries,omitempty"` - UnbondingPeriod time.Duration `protobuf:"bytes,9,opt,name=unbonding_period,json=unbondingPeriod,proto3,stdduration" json:"unbonding_period"` -} - func TestMigrateConsumerPacketData(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testutil.GetConsumerKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) defer ctrl.Finish() From 9737d0ff1c896e4f56c068e960a56c3fd385b2cf Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Thu, 22 Jun 2023 07:35:40 -0700 Subject: [PATCH 11/18] Update ccv.pb.go --- x/ccv/types/ccv.pb.go | 87 ++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 408390b7e8..503205692f 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -495,49 +495,50 @@ func init() { var fileDescriptor_68bd5f3242e6f29c = []byte{ // 707 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcf, 0x6a, 0xdb, 0x4a, - 0x14, 0xc6, 0xa5, 0x58, 0x04, 0x32, 0x86, 0x44, 0xd1, 0xf5, 0xbd, 0x38, 0xba, 0xad, 0x22, 0x44, - 0xa0, 0xa6, 0xa5, 0x52, 0xad, 0x74, 0x51, 0xda, 0x4d, 0x63, 0xc7, 0xc1, 0xa6, 0xf9, 0x63, 0xa4, - 0x38, 0xa5, 0xdd, 0x88, 0xb1, 0x34, 0xb1, 0x07, 0xdb, 0x1a, 0xa3, 0x19, 0x8b, 0xfa, 0x0d, 0x4a, - 0x56, 0x7d, 0x81, 0xac, 0x4a, 0x1f, 0xa4, 0xbb, 0x2c, 0x03, 0xdd, 0x64, 0x15, 0x4a, 0xf2, 0x06, - 0x7d, 0x82, 0x22, 0x59, 0x76, 0x1c, 0x5b, 0x31, 0x64, 0xe5, 0xf1, 0x99, 0x73, 0x3e, 0xf1, 0xfd, - 0xe6, 0xe3, 0x80, 0x2d, 0xec, 0x33, 0x14, 0xb8, 0x6d, 0x88, 0x7d, 0x87, 0x22, 0x77, 0x10, 0x60, - 0x36, 0x34, 0x5c, 0x37, 0x34, 0xc2, 0x62, 0xf4, 0xa3, 0xf7, 0x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4f, 0x83, 0x37, 0x1d, 0xef, 0xe7, 0x3f, 0xd8, + 0xac, 0x8f, 0x44, 0x7c, 0x85, 0x77, 0x40, 0xa9, 0x1c, 0x1d, 0x5a, 0xcd, 0x83, 0xaa, 0x69, 0x37, + 0x76, 0x2a, 0x1f, 0xaa, 0xc7, 0xf6, 0xf1, 0xa7, 0x46, 0xd5, 0x6e, 0x1e, 0x5a, 0x8d, 0x6a, 0xa5, + 0xbe, 0x57, 0xaf, 0xee, 0xf2, 0x8c, 0xf4, 0xf7, 0xf9, 0x85, 0xb2, 0xde, 0xf4, 0xc8, 0x00, 0x39, + 0xf8, 0x14, 0x8f, 0x9d, 0x09, 0x3a, 0x90, 0x32, 0x9b, 0xad, 0xfd, 0x1d, 0xab, 0xc6, 0xb3, 0xd2, + 0xda, 0xf9, 0x85, 0x92, 0x9f, 0x9a, 0x82, 0xb0, 0x0d, 0x36, 0x32, 0x1b, 0x22, 0x96, 0xfc, 0x92, + 0x54, 0x38, 0xbf, 0x50, 0xf8, 0x93, 0x19, 0x7e, 0x12, 0xf7, 0xe5, 0x9b, 0xcc, 0x94, 0x0f, 0x2f, + 0x6f, 0x65, 0xf6, 0xea, 0x56, 0x66, 0x7f, 0xdd, 0xca, 0xec, 0xd7, 0x3b, 0x99, 0xb9, 0xba, 0x93, + 0x99, 0xeb, 0x3b, 0x99, 0xf9, 0xfc, 0xba, 0x8d, 0x69, 0x67, 0xd8, 0xd2, 0x1c, 0xbf, 0xaf, 0xa7, + 0xcb, 0xf6, 0x1e, 0xd5, 0xcb, 0xc9, 0xd6, 0x0e, 0xb7, 0xf5, 0xb3, 0x78, 0x75, 0xc7, 0x4b, 0xb4, + 0xb5, 0x1c, 0x6f, 0xd1, 0xed, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x28, 0xa1, 0xed, 0x56, 0xe2, + 0x05, 0x00, 0x00, } func (m *ValidatorSetChangePacketData) Marshal() (dAtA []byte, err error) { From 189c1daec4b80189b25b16f6157fcd78dc73979e Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:12:55 -0700 Subject: [PATCH 12/18] add to ADR --- docs/docs/adrs/adr-008-throttle-retries.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/docs/adrs/adr-008-throttle-retries.md b/docs/docs/adrs/adr-008-throttle-retries.md index a8f0d250ce..b34b61df9f 100644 --- a/docs/docs/adrs/adr-008-throttle-retries.md +++ b/docs/docs/adrs/adr-008-throttle-retries.md @@ -8,6 +8,7 @@ title: Throttle with retries ## Changelog * 6/9/23: Initial draft +* 6/22/23: added note on consumer pending packets storage optimization ## Status @@ -46,6 +47,20 @@ With the behavior described, we maintain very similar behavior to the current th In the normal case, when no or a few slash packets are being sent, the VSCMaturedPackets will not be delayed, and hence unbonding will not be delayed. +### Consumer pending packets storage optimization + +In addition to the mentioned consumer changes above. An optimization will need to be made to the consumer's pending packets storage to properly implement the feature from this ADR. + +The consumer ccv module previously queued "pending packets" to be sent on each endblocker in [SendPackets](https://github.com/cosmos/interchain-security/blob/3bc4e7135066d848aac60b0787364c07157fd36d/x/ccv/consumer/keeper/relay.go#L178). These packets are queued in state with a protobuf list of `ConsumerPacketData`. For a single append operation, the entire list is deserialized, then a packet is appended to that list, and the list is serialized again, See older version of [AppendPendingPacket](https://github.com/cosmos/interchain-security/blob/05c2dae7c6372b1252b9e97215d07c6aa7618f33/x/ccv/consumer/keeper/keeper.go#L606). That is, a single append operation has O(N) complexity, where N is the size of the list. + +This poor append performance isn't a problem when the pending packets list is small. But with this ADR being implemented, the pending packets list could potentially grow to the order of thousands of entries, in the scenario that a slash packet is bouncing. + +We can improve the append time for this queue by converting it from a protobuf-esq list, to a queue implemented with sdk-esq code. The idea is to persist an uint64 index that will be incremented each time you queue up a packet. You can think of this as storing the tail of the queue. Then, packet data will be keyed by that index, making the data naturally ordered byte-wite for sdk's iterator. The index will also be stored in the packet data value bytes, so that the index can later be used to delete certain packets from the queue. + +Two things are achieved with this approach: +- More effecient packet append/enqueue times +- The ability to delete select packets from the queue (previously all packets were deleted at once) + ### Provider changes The main change needed for the provider is the removal of queuing logic for slash and vsc matured packets upon being received. From 1c33106b97edfddfb43e7d1d8220510922a0bfb3 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Fri, 23 Jun 2023 13:16:54 -0700 Subject: [PATCH 13/18] address some PR comments --- docs/docs/adrs/adr-008-throttle-retries.md | 7 ++++--- x/ccv/consumer/keeper/keeper.go | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/docs/adrs/adr-008-throttle-retries.md b/docs/docs/adrs/adr-008-throttle-retries.md index b34b61df9f..b8dfca60c0 100644 --- a/docs/docs/adrs/adr-008-throttle-retries.md +++ b/docs/docs/adrs/adr-008-throttle-retries.md @@ -51,15 +51,16 @@ In the normal case, when no or a few slash packets are being sent, the VSCMature In addition to the mentioned consumer changes above. An optimization will need to be made to the consumer's pending packets storage to properly implement the feature from this ADR. -The consumer ccv module previously queued "pending packets" to be sent on each endblocker in [SendPackets](https://github.com/cosmos/interchain-security/blob/3bc4e7135066d848aac60b0787364c07157fd36d/x/ccv/consumer/keeper/relay.go#L178). These packets are queued in state with a protobuf list of `ConsumerPacketData`. For a single append operation, the entire list is deserialized, then a packet is appended to that list, and the list is serialized again, See older version of [AppendPendingPacket](https://github.com/cosmos/interchain-security/blob/05c2dae7c6372b1252b9e97215d07c6aa7618f33/x/ccv/consumer/keeper/keeper.go#L606). That is, a single append operation has O(N) complexity, where N is the size of the list. +The consumer ccv module previously queued "pending packets" to be sent on each endblocker in [SendPackets](https://github.com/cosmos/interchain-security/blob/3bc4e7135066d848aac60b0787364c07157fd36d/x/ccv/consumer/keeper/relay.go#L178). These packets are queued in state with a protobuf list of `ConsumerPacketData`. For a single append operation, the entire list is deserialized, then a packet is appended to that list, and the list is serialized again. See older version of [AppendPendingPacket](https://github.com/cosmos/interchain-security/blob/05c2dae7c6372b1252b9e97215d07c6aa7618f33/x/ccv/consumer/keeper/keeper.go#L606). That is, a single append operation has O(N) complexity, where N is the size of the list. This poor append performance isn't a problem when the pending packets list is small. But with this ADR being implemented, the pending packets list could potentially grow to the order of thousands of entries, in the scenario that a slash packet is bouncing. We can improve the append time for this queue by converting it from a protobuf-esq list, to a queue implemented with sdk-esq code. The idea is to persist an uint64 index that will be incremented each time you queue up a packet. You can think of this as storing the tail of the queue. Then, packet data will be keyed by that index, making the data naturally ordered byte-wite for sdk's iterator. The index will also be stored in the packet data value bytes, so that the index can later be used to delete certain packets from the queue. Two things are achieved with this approach: -- More effecient packet append/enqueue times -- The ability to delete select packets from the queue (previously all packets were deleted at once) + +* More efficient packet append/enqueue times +* The ability to delete select packets from the queue (previously all packets were deleted at once) ### Provider changes diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 885a4dc61b..a054273f2e 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -592,12 +592,6 @@ func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Val return validators } -// Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. -// See consistency with PendingDataPacketsKey(). -func PendingDataPacketsIterator(store sdk.KVStore) sdk.Iterator { - return sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) -} - // getAndIncrementPendingPacketsIdx returns the current pending packets index and increments it. // This index is used for implementing a FIFO queue of pending packets in the KV store. func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { @@ -606,7 +600,7 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint if bz == nil { toReturn = 0 } else { - toReturn = binary.BigEndian.Uint64(bz) + toReturn = sdk.BigEndianToUint64(bz) } toStore := toReturn + 1 store.Set(types.PendingPacketsIndexKey(), sdk.Uint64ToBigEndian(toStore)) @@ -617,7 +611,9 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint func (k Keeper) GetPendingPackets(ctx sdk.Context) []ccv.ConsumerPacketData { var packets []ccv.ConsumerPacketData store := ctx.KVStore(k.storeKey) - iterator := PendingDataPacketsIterator(store) + // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. + // See consistency with PendingDataPacketsKey(). + iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var packet ccv.ConsumerPacketData @@ -642,10 +638,16 @@ func (k Keeper) DeletePendingDataPackets(ctx sdk.Context, idxs ...uint64) { func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - iterator := PendingDataPacketsIterator(store) + // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. + // See consistency with PendingDataPacketsKey(). + iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + keysToDel := [][]byte{} defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - store.Delete(iterator.Key()) + keysToDel = append(keysToDel, iterator.Key()) + } + for _, key := range keysToDel { + store.Delete(key) } } From a42229a465fd6f8f3f4fc14dcb4a5285ba1c4b84 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:01:06 -0700 Subject: [PATCH 14/18] comment --- proto/interchain_security/ccv/v1/ccv.proto | 4 +--- x/ccv/types/ccv.pb.go | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/proto/interchain_security/ccv/v1/ccv.proto b/proto/interchain_security/ccv/v1/ccv.proto index 1f22381f0a..f6845e6905 100644 --- a/proto/interchain_security/ccv/v1/ccv.proto +++ b/proto/interchain_security/ccv/v1/ccv.proto @@ -68,10 +68,8 @@ message ConsumerPacketData { } -// [Depreciated] favor using []ConsumerPacketData directly, which can be stored more efficiently. -// // ConsumerPacketDataList is a list of consumer packet data packets. -// It is only used for genesis to ensure backwards compatibility with older versions of ICS. +// NOTE: It is only used for exporting / importing state in InitGenesis and ExportGenesis. message ConsumerPacketDataList { repeated ConsumerPacketData list = 1 [ (gogoproto.nullable) = false ]; } diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index 503205692f..d3b18369b8 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -429,10 +429,8 @@ func (*ConsumerPacketData) XXX_OneofWrappers() []interface{} { } } -// [Depreciated] favor using []ConsumerPacketData directly, which can be stored more efficiently. -// // ConsumerPacketDataList is a list of consumer packet data packets. -// It is only used for genesis to ensure backwards compatibility with older versions of ICS. +// NOTE: It is only used for exporting / importing state in InitGenesis and ExportGenesis. type ConsumerPacketDataList struct { List []ConsumerPacketData `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` } From f517201bc75b03ed36645c1de1d52514bd9f7a46 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:10:01 -0700 Subject: [PATCH 15/18] Update ccv.pb.go --- x/ccv/types/ccv.pb.go | 107 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index caa9b92afb..c5eacc2288 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -687,60 +687,61 @@ func init() { } var fileDescriptor_68bd5f3242e6f29c = []byte{ - // 836 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x6e, 0xe2, 0x46, - 0x1c, 0xb6, 0x01, 0xad, 0x9a, 0xa1, 0x22, 0xce, 0x2c, 0xad, 0x58, 0x6f, 0xcb, 0x5a, 0xd6, 0x4a, + // 849 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcf, 0x6e, 0xe2, 0x46, + 0x1c, 0xc6, 0x80, 0x56, 0xcd, 0x50, 0x11, 0x67, 0x96, 0x56, 0x5e, 0x6f, 0xcb, 0x5a, 0xd6, 0x4a, 0x45, 0xa9, 0xd6, 0x2e, 0x64, 0x0f, 0x55, 0x7b, 0x69, 0x00, 0xa7, 0x71, 0x9b, 0x90, 0xc8, 0x06, - 0x56, 0xdb, 0x8b, 0x35, 0xd8, 0x13, 0x32, 0x0a, 0xd8, 0xc8, 0x33, 0xb8, 0xe5, 0x0d, 0x2a, 0x4e, - 0x7d, 0x01, 0x4e, 0x55, 0x0f, 0xfb, 0x18, 0xbd, 0xed, 0x71, 0xa5, 0x5e, 0xf6, 0xd2, 0xa8, 0x4a, - 0xde, 0xa0, 0x4f, 0x50, 0xd9, 0xfc, 0xc7, 0x06, 0x29, 0x52, 0xa5, 0xf6, 0x84, 0x19, 0xff, 0xbe, - 0x4f, 0xf3, 0xfd, 0x19, 0x79, 0xc0, 0x73, 0xe2, 0x32, 0xec, 0xdb, 0xd7, 0x88, 0xb8, 0x16, 0xc5, - 0xf6, 0xd0, 0x27, 0x6c, 0xa4, 0xda, 0x76, 0xa0, 0x06, 0xe5, 0xf0, 0x47, 0x19, 0xf8, 0x1e, 0xf3, - 0xa0, 0x98, 0x30, 0xa5, 0x84, 0xaf, 0x83, 0xb2, 0xf8, 0xdc, 0xf6, 0x68, 0xdf, 0xa3, 0x2a, 0x65, - 0xe8, 0x86, 0xb8, 0x5d, 0x35, 0x28, 0x77, 0x30, 0x43, 0xe5, 0xf9, 0xff, 0x29, 0x83, 0x98, 0xef, - 0x7a, 0x5d, 0x2f, 0x7a, 0x54, 0xc3, 0xa7, 0xd9, 0xea, 0x53, 0x86, 0x5d, 0x07, 0x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x60, 0xdf, 0x0c, 0x05, 0xac, 0xa0, 0x0d, 0xb0, 0xb7, 0xf0, 0x28, 0x82, - 0x65, 0x2b, 0xe2, 0x76, 0xe3, 0xab, 0x85, 0x99, 0xe5, 0xc2, 0x86, 0xe5, 0xb2, 0xb1, 0xa4, 0x79, - 0x80, 0xc7, 0x55, 0x00, 0x88, 0x7b, 0xe5, 0x23, 0x9b, 0x11, 0xcf, 0x2d, 0xa4, 0x25, 0xbe, 0x94, - 0xab, 0xc8, 0xca, 0xb4, 0x8d, 0xca, 0xbc, 0x7d, 0xb3, 0x36, 0x2a, 0xfa, 0x62, 0xd2, 0x58, 0x41, - 0xc9, 0x9f, 0x81, 0xc7, 0x33, 0x53, 0x5a, 0x6e, 0xc7, 0x73, 0x1d, 0xe2, 0x76, 0x2f, 0x06, 0x14, - 0x0a, 0x20, 0x4d, 0x9c, 0x69, 0x97, 0x32, 0x46, 0xf8, 0x28, 0xff, 0x96, 0x02, 0xb0, 0xe6, 0xb9, - 0x74, 0xd8, 0xc7, 0xfe, 0x8a, 0x03, 0x27, 0x20, 0x13, 0x56, 0x36, 0x12, 0x9f, 0xab, 0x54, 0x76, - 0x65, 0x15, 0x47, 0x37, 0x47, 0x03, 0x6c, 0x44, 0x78, 0xf8, 0x0a, 0xec, 0xd3, 0x75, 0x73, 0x23, - 0xd1, 0xd9, 0xca, 0xe7, 0xbb, 0x28, 0x37, 0xf2, 0x38, 0xe5, 0x8c, 0x4d, 0x16, 0x78, 0x05, 0xf2, - 0x01, 0xb5, 0x63, 0xc1, 0x47, 0x76, 0x65, 0x2b, 0x5f, 0xec, 0x2c, 0x57, 0x42, 0x61, 0x4e, 0x39, - 0x23, 0x91, 0xaf, 0xfa, 0x08, 0x64, 0x1c, 0xc4, 0x90, 0xdc, 0x01, 0x1f, 0xc7, 0x85, 0x9e, 0x11, - 0xca, 0xe0, 0xe9, 0x5a, 0xad, 0x95, 0x87, 0x59, 0xb5, 0x56, 0xe6, 0x37, 0x29, 0x90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, 0x5d, 0x6d, 0x1f, 0x9a, 0x08, 0x00, + 0x00, } func (m *ValidatorSetChangePacketData) Marshal() (dAtA []byte, err error) { From d84b29d8aaf7898a428e23d978af5979e321347e Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:17:29 -0700 Subject: [PATCH 16/18] lint --- x/ccv/consumer/keeper/migration.go | 1 + x/ccv/consumer/keeper/migration_test.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 6a06a48925..361bb2a62f 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) diff --git a/x/ccv/consumer/keeper/migration_test.go b/x/ccv/consumer/keeper/migration_test.go index f284c1d0bf..1e7bc54bdf 100644 --- a/x/ccv/consumer/keeper/migration_test.go +++ b/x/ccv/consumer/keeper/migration_test.go @@ -3,9 +3,10 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" - "github.com/stretchr/testify/require" ) func TestMigrateConsumerPacketData(t *testing.T) { From ab23828437eb354f046089d1de61cf2cd7343dc0 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Thu, 13 Jul 2023 10:46:28 -0700 Subject: [PATCH 17/18] Update x/ccv/consumer/keeper/keeper.go Co-authored-by: Simon Noetzlin --- x/ccv/consumer/keeper/keeper.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 37c449e9a6..cfff31b367 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -598,9 +598,7 @@ func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Val func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.PendingPacketsIndexKey()) - if bz == nil { - toReturn = 0 - } else { + if bz != nil { toReturn = sdk.BigEndianToUint64(bz) } toStore := toReturn + 1 From db04b8f94eb90857da4fdb9752614ab725dcda40 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Thu, 13 Jul 2023 10:49:33 -0700 Subject: [PATCH 18/18] byte wise --- docs/docs/adrs/adr-008-throttle-retries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/adrs/adr-008-throttle-retries.md b/docs/docs/adrs/adr-008-throttle-retries.md index b8dfca60c0..134214fffb 100644 --- a/docs/docs/adrs/adr-008-throttle-retries.md +++ b/docs/docs/adrs/adr-008-throttle-retries.md @@ -55,7 +55,7 @@ The consumer ccv module previously queued "pending packets" to be sent on each e This poor append performance isn't a problem when the pending packets list is small. But with this ADR being implemented, the pending packets list could potentially grow to the order of thousands of entries, in the scenario that a slash packet is bouncing. -We can improve the append time for this queue by converting it from a protobuf-esq list, to a queue implemented with sdk-esq code. The idea is to persist an uint64 index that will be incremented each time you queue up a packet. You can think of this as storing the tail of the queue. Then, packet data will be keyed by that index, making the data naturally ordered byte-wite for sdk's iterator. The index will also be stored in the packet data value bytes, so that the index can later be used to delete certain packets from the queue. +We can improve the append time for this queue by converting it from a protobuf-esq list, to a queue implemented with sdk-esq code. The idea is to persist an uint64 index that will be incremented each time you queue up a packet. You can think of this as storing the tail of the queue. Then, packet data will be keyed by that index, making the data naturally ordered byte-wise for sdk's iterator. The index will also be stored in the packet data value bytes, so that the index can later be used to delete certain packets from the queue. Two things are achieved with this approach: