diff --git a/proto/interchain_security/ccv/provider/v1/genesis.proto b/proto/interchain_security/ccv/provider/v1/genesis.proto index 36e6ca549f..1bbdee1498 100644 --- a/proto/interchain_security/ccv/provider/v1/genesis.proto +++ b/proto/interchain_security/ccv/provider/v1/genesis.proto @@ -22,7 +22,7 @@ message GenesisState { (gogoproto.moretags) = "yaml:\"consumer_states\"" ]; // empty for a new chain - repeated interchain_security.ccv.v1.UnbondingOp unbonding_ops = 3 + repeated interchain_security.ccv.provider.v1.UnbondingOp unbonding_ops = 3 [ (gogoproto.nullable) = false ]; // empty for a new chain interchain_security.ccv.v1.MaturedUnbondingOps mature_unbonding_ops = 4; @@ -65,18 +65,11 @@ message ConsumerState { repeated interchain_security.ccv.v1.ValidatorSetChangePacketData pending_valset_changes = 6 [ (gogoproto.nullable) = false ]; repeated string slash_downtime_ack = 7; - // UnbondingOpsIndex defines the unbonding operations on the consumer chain - repeated UnbondingOpIndex unbonding_ops_index = 8 + // UnbondingOpsIndex defines the unbonding operations waiting on this consumer chain + repeated interchain_security.ccv.provider.v1.VscUnbondingOps unbonding_ops_index = 8 [ (gogoproto.nullable) = false ]; } -// UnbondingOpIndex defines the genesis information for each unbonding operations index -// referenced by chain id and valset udpate id -message UnbondingOpIndex { - uint64 valset_update_id = 1; - repeated uint64 unbonding_op_index = 2; -} - // ValsetUpdateIdToHeight defines the genesis information for the mapping // of each valset udpate id to a block height message ValsetUpdateIdToHeight { diff --git a/proto/interchain_security/ccv/provider/v1/provider.proto b/proto/interchain_security/ccv/provider/v1/provider.proto index 07d5fd97b5..214518e4c4 100644 --- a/proto/interchain_security/ccv/provider/v1/provider.proto +++ b/proto/interchain_security/ccv/provider/v1/provider.proto @@ -9,6 +9,7 @@ import "google/protobuf/timestamp.proto"; import "google/protobuf/duration.proto"; import "ibc/core/client/v1/client.proto"; import "ibc/lightclients/tendermint/v1/tendermint.proto"; +import "tendermint/crypto/keys.proto"; // ConsumerAdditionProposal is a governance proposal on the provider chain to spawn a new consumer chain. // If it passes, then all validators on the provider chain are expected to validate the consumer chain at spawn time @@ -153,4 +154,41 @@ message ConsumerRemovalProposals { // AddressList contains a list of consensus addresses message AddressList { repeated bytes addresses = 1; -} \ No newline at end of file +} + +message ChannelToChain { + string channel_id = 1; + string chain_id = 2; +} + +// VscUnbondingOps contains the IDs of unbonding operations that are waiting for +// at least one VSCMaturedPacket with vscID from a consumer chain +message VscUnbondingOps { + uint64 vsc_id = 1; + repeated uint64 unbonding_op_ids = 2; +} + +// UnbondingOp contains the ids of consumer chains that need to unbond before +// the unbonding operation with the given ID can unbond +message UnbondingOp { + uint64 id = 1; + // consumer chains that are still unbonding + repeated string unbonding_consumer_chains = 2; +} + +message InitTimeoutTimestamp { + string chain_id = 1; + uint64 timestamp = 2; +} + +message VscSendTimestamp { + uint64 vsc_id = 1; + google.protobuf.Timestamp timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; +} + +message KeyAssignmentReplacement { + bytes provider_addr = 1; + tendermint.crypto.PublicKey prev_c_key = 2; + int64 power = 3; +} + diff --git a/proto/interchain_security/ccv/v1/ccv.proto b/proto/interchain_security/ccv/v1/ccv.proto index f25b997356..c693a09188 100644 --- a/proto/interchain_security/ccv/v1/ccv.proto +++ b/proto/interchain_security/ccv/v1/ccv.proto @@ -32,13 +32,6 @@ message ValidatorSetChangePackets { ]; } - -message UnbondingOp { - uint64 id = 1; - // consumer chains that are still unbonding - repeated string unbonding_consumer_chains = 2; -} - // This packet is sent from the consumer chain to the provider chain // to notify that a VSC packet reached maturity on the consumer chain. message VSCMaturedPacketData { @@ -60,11 +53,6 @@ message SlashPacketData { cosmos.staking.v1beta1.InfractionType infraction = 3; } -// UnbondingOpsIndex defines a list of unbonding operation ids. -message UnbondingOpsIndex { - repeated uint64 ids = 1; -} - // MaturedUnbondingOps defines a list of ids corresponding to ids of matured unbonding operations. message MaturedUnbondingOps { repeated uint64 ids = 1; diff --git a/tests/difference/core/driver/core_test.go b/tests/difference/core/driver/core_test.go index 83232a341b..3456e86bd3 100644 --- a/tests/difference/core/driver/core_test.go +++ b/tests/difference/core/driver/core_test.go @@ -390,11 +390,9 @@ func (s *CoreSuite) TestAssumptions() { s.Require().Empty(s.consumerKeeper().GetPendingPackets(s.ctx(C))) // Consumer has no maturities - s.consumerKeeper().IteratePacketMaturityTime(s.ctx(C), - func(vscId uint64, timeNs uint64) (stop bool) { - s.T().Fatal(FAIL_MSG) - return false // Don't stop - }) + for range s.consumerKeeper().GetAllPacketMaturityTimes(s.ctx(C)) { + s.T().Fatal(FAIL_MSG) + } // Consumer power for i := 0; i < len(initState.ValStates.Status); i++ { diff --git a/tests/e2e/stop_consumer.go b/tests/e2e/stop_consumer.go index 2a2aa9c76a..04d92de429 100644 --- a/tests/e2e/stop_consumer.go +++ b/tests/e2e/stop_consumer.go @@ -170,21 +170,16 @@ func (s *CCVTestSuite) checkConsumerChainIsRemoved(chainID string, checkChannel } // check UnbondingOps were deleted and undelegation entries aren't onHold - providerKeeper.IterateOverUnbondingOpIndex( - s.providerCtx(), - chainID, - func(vscID uint64, ubdIndex []uint64) (stop bool) { - _, found := providerKeeper.GetUnbondingOpIndex(s.providerCtx(), chainID, uint64(vscID)) + for _, unbondingOpsIndex := range providerKeeper.GetAllUnbondingOpIndexes(s.providerCtx(), chainID) { + _, found := providerKeeper.GetUnbondingOpIndex(s.providerCtx(), chainID, unbondingOpsIndex.VscId) + s.Require().False(found) + for _, ubdID := range unbondingOpsIndex.UnbondingOpIds { + _, found = providerKeeper.GetUnbondingOp(s.providerCtx(), unbondingOpsIndex.UnbondingOpIds[ubdID]) s.Require().False(found) - for _, ubdID := range ubdIndex { - _, found = providerKeeper.GetUnbondingOp(s.providerCtx(), ubdIndex[ubdID]) - s.Require().False(found) - ubd, _ := providerStakingKeeper.GetUnbondingDelegationByUnbondingID(s.providerCtx(), ubdIndex[ubdID]) - s.Require().Zero(ubd.Entries[ubdID].UnbondingOnHoldRefCount) - } - return false // do not stop the iteration - }, - ) + ubd, _ := providerStakingKeeper.GetUnbondingDelegationByUnbondingID(s.providerCtx(), unbondingOpsIndex.UnbondingOpIds[ubdID]) + s.Require().Zero(ubd.Entries[ubdID].UnbondingOnHoldRefCount) + } + } // verify consumer chain's states are removed _, found := providerKeeper.GetConsumerGenesis(s.providerCtx(), chainID) diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index 910df5b36c..8f430ab91a 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -254,3 +254,14 @@ func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal { return prop } + +// Obtains a CrossChainValidator with a newly generated key, and randomized field values +func GetNewCrossChainValidator(t *testing.T) consumertypes.CrossChainValidator { + b1 := make([]byte, 8) + _, _ = rand.Read(b1) + power := int64(binary.BigEndian.Uint64(b1)) + privKey := ed25519.GenPrivKey() + validator, err := consumertypes.NewCCValidator(privKey.PubKey().Address(), power, privKey.PubKey()) + require.NoError(t, err) + return validator +} diff --git a/x/ccv/consumer/keeper/genesis.go b/x/ccv/consumer/keeper/genesis.go index 088ce6adc4..91d8ae9c80 100644 --- a/x/ccv/consumer/keeper/genesis.go +++ b/x/ccv/consumer/keeper/genesis.go @@ -118,35 +118,6 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt panic("provider client does not exist") } - maturingPackets := []consumertypes.MaturingVSCPacket{} - k.IteratePacketMaturityTime(ctx, func(vscId, timeNs uint64) (stop bool) { - mat := consumertypes.MaturingVSCPacket{ - VscId: vscId, - MaturityTime: timeNs, - } - maturingPackets = append(maturingPackets, mat) - return false // do not stop the iteration - }) - - heightToVCIDs := []consumertypes.HeightToValsetUpdateID{} - k.IterateHeightToValsetUpdateID(ctx, func(height, vscID uint64) (stop bool) { - hv := consumertypes.HeightToValsetUpdateID{ - Height: height, - ValsetUpdateId: vscID, - } - heightToVCIDs = append(heightToVCIDs, hv) - return false // do not stop the iteration - }) - - outstandingDowntimes := []consumertypes.OutstandingDowntime{} - k.IterateOutstandingDowntime(ctx, func(addr string) (stop bool) { - od := consumertypes.OutstandingDowntime{ - ValidatorConsensusAddress: addr, - } - outstandingDowntimes = append(outstandingDowntimes, od) - return false // do not stop the iteration - }) - // TODO: update GetLastTransmissionBlockHeight to not return an error ltbh, err := k.GetLastTransmissionBlockHeight(ctx) if err != nil { @@ -156,11 +127,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt genesis = consumertypes.NewRestartGenesisState( clientID, channelID, - maturingPackets, + k.GetAllPacketMaturityTimes(ctx), valset, - k.GetHeightToValsetUpdateIDs(ctx), + k.GetAllHeightToValsetUpdateIDs(ctx), k.GetPendingPackets(ctx), - outstandingDowntimes, + k.GetAllOutstandingDowntimes(ctx), *ltbh, params, ) @@ -178,7 +149,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt "", nil, valset, - k.GetHeightToValsetUpdateIDs(ctx), + k.GetAllHeightToValsetUpdateIDs(ctx), k.GetPendingPackets(ctx), nil, consumertypes.LastTransmissionBlockHeight{}, diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 08abb89cda..30d733ad6d 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -187,7 +187,7 @@ func TestInitGenesis(t *testing.T) { require.Equal(t, vscID, ck.GetPacketMaturityTime(ctx, vscID)) require.Equal(t, pendingDataPackets, ck.GetPendingPackets(ctx)) - require.Equal(t, gs.OutstandingDowntimeSlashing, ck.GetOutstandingDowntimes(ctx)) + require.Equal(t, gs.OutstandingDowntimeSlashing, ck.GetAllOutstandingDowntimes(ctx)) ltbh, err := ck.GetLastTransmissionBlockHeight(ctx) require.NoError(t, err) @@ -382,10 +382,10 @@ func assertProviderClientID(t *testing.T, ctx sdk.Context, ck *consumerkeeper.Ke // assert that the given input match the height to valset update ID mappings in the store func assertHeightValsetUpdateIDs(t *testing.T, ctx sdk.Context, ck *consumerkeeper.Keeper, heighValsetUpdateIDs []consumertypes.HeightToValsetUpdateID) { ctr := 0 - ck.IterateHeightToValsetUpdateID(ctx, func(height uint64, vscID uint64) (stop bool) { - require.Equal(t, heighValsetUpdateIDs[ctr].Height, height) - require.Equal(t, heighValsetUpdateIDs[ctr].ValsetUpdateId, vscID) + + for _, heightToValsetUpdateID := range ck.GetAllHeightToValsetUpdateIDs(ctx) { + require.Equal(t, heighValsetUpdateIDs[ctr].Height, heightToValsetUpdateID.Height) + require.Equal(t, heighValsetUpdateIDs[ctr].ValsetUpdateId, heightToValsetUpdateID.ValsetUpdateId) ctr++ - return false - }) + } } diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index e04b00a965..33a5aca779 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -206,24 +206,50 @@ func (k Keeper) DeletePendingChanges(ctx sdk.Context) { store.Delete(types.PendingChangesKey()) } -// IteratePacketMaturityTime iterates through the VSC packet maturity times set in the store -func (k Keeper) IteratePacketMaturityTime(ctx sdk.Context, cb func(vscId, timeNs uint64) (stop bool)) { +// GetElapsedPacketMaturityTimes returns a slice of already elapsed PacketMaturityTimes, sorted by vscIDs, +// i.e., the slice contains the IDs of the matured VSCPackets +func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPacket []consumertypes.MaturingVSCPacket) { + currentTime := uint64(ctx.BlockTime().UnixNano()) store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - // Extract bytes following the 1 byte prefix - seqBytes := iterator.Key()[1:] - seq := binary.BigEndian.Uint64(seqBytes) - timeNs := binary.BigEndian.Uint64(iterator.Value()) + for ; iterator.Valid(); iterator.Next() { + vscId := binary.BigEndian.Uint64(iterator.Key()[1:]) + maturityTime := binary.BigEndian.Uint64(iterator.Value()) - stop := cb(seq, timeNs) - if stop { + // If the maturity time is after the current time, then stop the iteration; + // TODO: the iteration over PacketMaturityTimes should be over maturity times, + // see https://github.com/cosmos/interchain-security/issues/598 + if currentTime < maturityTime { break } + + maturingVSCPacket = append(maturingVSCPacket, consumertypes.MaturingVSCPacket{ + VscId: vscId, + MaturityTime: maturityTime, + }) } + return maturingVSCPacket +} + +// GetAllPacketMaturityTimes returns a slice of all PacketMaturityTimes, sorted by vscIDs. +func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPacket []consumertypes.MaturingVSCPacket) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + vscId := binary.BigEndian.Uint64(iterator.Key()[1:]) + maturityTime := binary.BigEndian.Uint64(iterator.Value()) + + maturingVSCPacket = append(maturingVSCPacket, consumertypes.MaturingVSCPacket{ + VscId: vscId, + MaturityTime: maturityTime, + }) + } + return maturingVSCPacket } // SetPacketMaturityTime sets the maturity time for a given received VSC packet id @@ -299,23 +325,27 @@ func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { store.Delete(types.HeightValsetUpdateIDKey(height)) } -// IterateHeightToValsetUpdateID iterates over the block height to valset update ID mapping in store -func (k Keeper) IterateHeightToValsetUpdateID(ctx sdk.Context, cb func(height, vscID uint64) (stop bool)) { +// GetAllHeightToValsetUpdateIDs returns a list of all the block heights to valset update IDs in the store +// +// Note that the block height to vscID mapping is stored under keys with the following format: +// HeightValsetUpdateIDBytePrefix | height +// Thus, the returned array is in ascending order of heights. +func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUpdateIDs []types.HeightToValsetUpdateID) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.HeightValsetUpdateIDBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - heightBytes := iterator.Key()[1:] - height := binary.BigEndian.Uint64(heightBytes) - + height := binary.BigEndian.Uint64(iterator.Key()[1:]) vscID := binary.BigEndian.Uint64(iterator.Value()) - stop := cb(height, vscID) - if stop { - break - } + heightToValsetUpdateIDs = append(heightToValsetUpdateIDs, types.HeightToValsetUpdateID{ + Height: height, + ValsetUpdateId: vscID, + }) } + + return heightToValsetUpdateIDs } // OutstandingDowntime returns the outstanding downtime flag for a given validator @@ -341,8 +371,12 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { store.Delete(types.OutstandingDowntimeKey(consAddr)) } -// IterateOutstandingDowntime iterates over the validator addresses of outstanding downtime flags -func (k Keeper) IterateOutstandingDowntime(ctx sdk.Context, cb func(address string) (stop bool)) { +// GetAllOutstandingDowntimes gets an array of the validator addresses of outstanding downtime flags +// +// Note that the outstanding downtime flags are stored under keys with the following format: +// OutstandingDowntimeBytePrefix | consAddress +// Thus, the returned array is in ascending order of consAddresses. +func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []consumertypes.OutstandingDowntime) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.OutstandingDowntimeBytePrefix}) @@ -350,11 +384,13 @@ func (k Keeper) IterateOutstandingDowntime(ctx sdk.Context, cb func(address stri for ; iterator.Valid(); iterator.Next() { addrBytes := iterator.Key()[1:] addr := sdk.ConsAddress(addrBytes).String() - stop := cb(addr) - if stop { - break - } + + downtimes = append(downtimes, consumertypes.OutstandingDowntime{ + ValidatorConsensusAddress: addr, + }) } + + return downtimes } // SetCCValidator sets a cross-chain validator under its validator address @@ -385,6 +421,10 @@ func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { } // GetAllCCValidator returns all cross-chain validators +// +// Note that the cross-chain validators are stored under keys with the following format: +// CrossChainValidatorBytePrefix | address +// Thus, the returned array is in ascending order of addresses. func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChainValidator) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.CrossChainValidatorBytePrefix}) @@ -439,31 +479,3 @@ func (k Keeper) AppendPendingPacket(ctx sdk.Context, packet ...types.ConsumerPac list := append(pending.GetList(), packet...) k.SetPendingPackets(ctx, types.ConsumerPackets{List: list}) } - -// GetHeightToValsetUpdateIDs returns all height to valset update id mappings in store -func (k Keeper) GetHeightToValsetUpdateIDs(ctx sdk.Context) []types.HeightToValsetUpdateID { - heightToVCIDs := []types.HeightToValsetUpdateID{} - k.IterateHeightToValsetUpdateID(ctx, func(height, vscID uint64) (stop bool) { - hv := types.HeightToValsetUpdateID{ - Height: height, - ValsetUpdateId: vscID, - } - heightToVCIDs = append(heightToVCIDs, hv) - return false // do not stop iteration - }) - - return heightToVCIDs -} - -// GetOutstandingDowntimes returns all outstanding downtimes in store -func (k Keeper) GetOutstandingDowntimes(ctx sdk.Context) []consumertypes.OutstandingDowntime { - outstandingDowntimes := []types.OutstandingDowntime{} - k.IterateOutstandingDowntime(ctx, func(addr string) bool { - od := types.OutstandingDowntime{ - ValidatorConsensusAddress: addr, - } - outstandingDowntimes = append(outstandingDowntimes, od) - return false - }) - return outstandingDowntimes -} diff --git a/x/ccv/consumer/keeper/keeper_test.go b/x/ccv/consumer/keeper/keeper_test.go index 195783b036..245287adc9 100644 --- a/x/ccv/consumer/keeper/keeper_test.go +++ b/x/ccv/consumer/keeper/keeper_test.go @@ -1,7 +1,10 @@ package keeper_test import ( + "bytes" + "sort" "testing" + "time" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -83,39 +86,64 @@ func TestPendingChanges(t *testing.T) { // TestPacketMaturityTime tests getter, setter, and iterator functionality for the packet maturity time of a received VSC packet func TestPacketMaturityTime(t *testing.T) { - - consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - consumerKeeper.SetPacketMaturityTime(ctx, 1, 10) - consumerKeeper.SetPacketMaturityTime(ctx, 2, 25) - consumerKeeper.SetPacketMaturityTime(ctx, 5, 15) - consumerKeeper.SetPacketMaturityTime(ctx, 6, 40) + now := time.Now().UTC() + nsNow := uint64(now.UnixNano()) + packets := []types.MaturingVSCPacket{ + { + VscId: 2, + MaturityTime: nsNow, + }, + { + VscId: 1, + MaturityTime: nsNow - 15, + }, + { + VscId: 5, + MaturityTime: nsNow - 30, + }, + { + VscId: 6, + MaturityTime: nsNow + 10, + }, + } + expectedGetAllOrder := packets + // sorting by VscId + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].VscId < expectedGetAllOrder[j].VscId + }) + expectedGetElapsedOrder := []types.MaturingVSCPacket{} + for _, packet := range packets { + // only packets with MaturityTime <= nsNow + if packet.MaturityTime <= nsNow { + expectedGetElapsedOrder = append(expectedGetElapsedOrder, packet) + } + } + // sorting by VscId + sort.Slice(expectedGetElapsedOrder, func(i, j int) bool { + return expectedGetElapsedOrder[i].VscId < expectedGetElapsedOrder[j].VscId + }) - consumerKeeper.DeletePacketMaturityTimes(ctx, 6) + for _, packet := range packets { + ck.SetPacketMaturityTime(ctx, packet.VscId, packet.MaturityTime) + } - require.Equal(t, uint64(10), consumerKeeper.GetPacketMaturityTime(ctx, 1)) - require.Equal(t, uint64(25), consumerKeeper.GetPacketMaturityTime(ctx, 2)) - require.Equal(t, uint64(15), consumerKeeper.GetPacketMaturityTime(ctx, 5)) - require.Equal(t, uint64(0), consumerKeeper.GetPacketMaturityTime(ctx, 3)) - require.Equal(t, uint64(0), consumerKeeper.GetPacketMaturityTime(ctx, 6)) + for _, packet := range packets { + require.Equal(t, packet.MaturityTime, ck.GetPacketMaturityTime(ctx, packet.VscId)) + } - orderedTimes := [][]uint64{{1, 10}, {2, 25}, {5, 15}} - i := 0 + maturingVSCPackets := ck.GetAllPacketMaturityTimes(ctx) + require.Len(t, maturingVSCPackets, len(packets)) + require.Equal(t, expectedGetAllOrder, maturingVSCPackets) - consumerKeeper.IteratePacketMaturityTime(ctx, func(seq, time uint64) (stop bool) { - // require that we iterate through unbonding time in order of sequence - require.Equal(t, orderedTimes[i][0], seq) - require.Equal(t, orderedTimes[i][1], time) - i++ - return false // do not stop the iteration - }) + elapsedMaturingVSCPackets := ck.GetElapsedPacketMaturityTimes(ctx.WithBlockTime(now)) + require.Equal(t, expectedGetElapsedOrder, elapsedMaturingVSCPackets) - // delete all vscs remaining in state - consumerKeeper.DeletePacketMaturityTimes(ctx, 1, 2, 5) - require.Equal(t, uint64(0), consumerKeeper.GetPacketMaturityTime(ctx, 1)) - require.Equal(t, uint64(0), consumerKeeper.GetPacketMaturityTime(ctx, 2)) - require.Equal(t, uint64(0), consumerKeeper.GetPacketMaturityTime(ctx, 5)) + ck.DeletePacketMaturityTimes(ctx, 6) + require.Equal(t, uint64(0), ck.GetPacketMaturityTime(ctx, 3)) + require.Equal(t, uint64(0), ck.GetPacketMaturityTime(ctx, 6)) } // TestCrossChainValidator tests the getter, setter, and deletion method for cross chain validator records @@ -160,6 +188,35 @@ func TestCrossChainValidator(t *testing.T) { require.False(t, found) } +// TestGetAllCCValidator tests GetAllCCValidator behaviour correctness +func TestGetAllCCValidator(t *testing.T) { + keeperParams := testkeeper.NewInMemKeeperParams(t) + // Explicitly register codec with public key interface + keeperParams.RegisterSdkCryptoCodecInterfaces() + ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, keeperParams) + defer ctrl.Finish() + + numValidators := 4 + validators := []types.CrossChainValidator{} + for i := 0; i < numValidators; i++ { + validators = append(validators, testkeeper.GetNewCrossChainValidator(t)) + } + // sorting by CrossChainValidator.Address + expectedGetAllOrder := validators + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return bytes.Compare(expectedGetAllOrder[i].Address, expectedGetAllOrder[j].Address) == -1 + }) + + for _, val := range validators { + ck.SetCCValidator(ctx, val) + } + + // iterate and check all results are returned in the expected order + result := ck.GetAllCCValidator(ctx) + require.Len(t, result, len(validators)) + require.Equal(t, result, expectedGetAllOrder) +} + func TestSetPendingPackets(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) @@ -301,3 +358,74 @@ func TestVerifyProviderChain(t *testing.T) { ctrl.Finish() } } + +// TestGetAllHeightToValsetUpdateIDs tests GetAllHeightToValsetUpdateIDs behaviour correctness +func TestGetAllHeightToValsetUpdateIDs(t *testing.T) { + ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + cases := []types.HeightToValsetUpdateID{ + { + ValsetUpdateId: 2, + Height: 22, + }, + { + ValsetUpdateId: 1, + Height: 11, + }, + { + // normal execution should not have two HeightToValsetUpdateID + // with the same ValsetUpdateId, but let's test it anyway + ValsetUpdateId: 1, + Height: 44, + }, + { + ValsetUpdateId: 3, + Height: 33, + }, + } + expectedGetAllOrder := cases + // sorting by Height + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].Height < expectedGetAllOrder[j].Height + }) + + for _, c := range cases { + ck.SetHeightValsetUpdateID(ctx, c.Height, c.ValsetUpdateId) + } + + // iterate and check all results are returned + result := ck.GetAllHeightToValsetUpdateIDs(ctx) + require.Len(t, result, len(cases)) + require.Equal(t, expectedGetAllOrder, result) +} + +// TestGetAllOutstandingDowntimes tests GetAllOutstandingDowntimes behaviour correctness +func TestGetAllOutstandingDowntimes(t *testing.T) { + ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + addresses := []sdk.ConsAddress{ + sdk.ConsAddress([]byte("consAddress2")), + sdk.ConsAddress([]byte("consAddress1")), + sdk.ConsAddress([]byte("consAddress4")), + sdk.ConsAddress([]byte("consAddress3")), + } + expectedGetAllOrder := []types.OutstandingDowntime{} + for _, addr := range addresses { + expectedGetAllOrder = append(expectedGetAllOrder, types.OutstandingDowntime{ValidatorConsensusAddress: addr.String()}) + } + // sorting by ConsAddress + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return bytes.Compare(addresses[i], addresses[j]) == -1 + }) + + for _, addr := range addresses { + ck.SetOutstandingDowntime(ctx, addr) + } + + // iterate and check all results are returned in the expected order + result := ck.GetAllOutstandingDowntimes(ctx) + require.Len(t, result, len(addresses)) + require.Equal(t, result, expectedGetAllOrder) +} diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index 05b48085f7..023efd7e43 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -1,7 +1,6 @@ package keeper import ( - "encoding/binary" "fmt" "strconv" @@ -86,46 +85,36 @@ func (k Keeper) OnRecvVSCPacket(ctx sdk.Context, packet channeltypes.Packet, new // operations that resulted in validator updates included in that VSC have matured on // the consumer chain. func (k Keeper) QueueVSCMaturedPackets(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) - maturityIterator := sdk.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) - defer maturityIterator.Close() - currentTime := uint64(ctx.BlockTime().UnixNano()) - maturedVscIds := []uint64{} - for maturityIterator.Valid() { - vscId := types.IdFromPacketMaturityTimeKey(maturityIterator.Key()) - if currentTime >= binary.BigEndian.Uint64(maturityIterator.Value()) { - // construct validator set change packet data - vscPacket := ccv.NewVSCMaturedPacketData(vscId) - - // append VSCMatured packet to pending packets - // sending packets is attempted each EndBlock - // unsent packets remain in the queue until sent - k.AppendPendingPacket(ctx, types.ConsumerPacket{ - Type: types.VscMaturedPacket, - Data: vscPacket.GetBytes(), - }) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - ccv.EventTypeVSCMatured, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(ccv.AttributeChainID, ctx.ChainID()), - sdk.NewAttribute(ccv.AttributeConsumerHeight, strconv.Itoa(int(ctx.BlockHeight()))), - sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(vscId))), - sdk.NewAttribute(ccv.AttributeTimestamp, strconv.Itoa(int(currentTime))), - ), - ) - - maturedVscIds = append(maturedVscIds, vscId) - } else { - break + for _, maturityTime := range k.GetElapsedPacketMaturityTimes(ctx) { + if currentTime < maturityTime.MaturityTime { + panic(fmt.Errorf("maturity time %d is greater than current time %d", maturityTime.MaturityTime, currentTime)) } - maturityIterator.Next() - } + // construct validator set change packet data + vscPacket := ccv.NewVSCMaturedPacketData(maturityTime.VscId) + + // append VSCMatured packet to pending packets + // sending packets is attempted each EndBlock + // unsent packets remain in the queue until sent + k.AppendPendingPacket(ctx, types.ConsumerPacket{ + Type: types.VscMaturedPacket, + Data: vscPacket.GetBytes(), + }) - k.DeletePacketMaturityTimes(ctx, maturedVscIds...) + k.DeletePacketMaturityTimes(ctx, uint64(maturityTime.VscId)) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeVSCMatured, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeChainID, ctx.ChainID()), + sdk.NewAttribute(ccv.AttributeConsumerHeight, strconv.Itoa(int(ctx.BlockHeight()))), + sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(maturityTime.VscId))), + sdk.NewAttribute(ccv.AttributeTimestamp, strconv.Itoa(int(currentTime))), + ), + ) + } } // QueueSlashPacket appends a slash packet containing the given validator data and slashing info to queue. diff --git a/x/ccv/provider/keeper/genesis.go b/x/ccv/provider/keeper/genesis.go index ae090035ab..94ccefdc03 100644 --- a/x/ccv/provider/keeper/genesis.go +++ b/x/ccv/provider/keeper/genesis.go @@ -2,12 +2,10 @@ package keeper import ( "fmt" - "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" - tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) // InitGenesis initializes the CCV provider state and binds to PortID. @@ -32,13 +30,12 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { for _, prop := range genState.ConsumerAdditionProposals { // prevent implicit memory aliasing - prop := prop - if err := k.SetPendingConsumerAdditionProp(ctx, &prop); err != nil { - panic(fmt.Errorf("pending create consumer chain proposal could not be persisted: %w", err)) - } + p := prop + k.SetPendingConsumerAdditionProp(ctx, &p) } for _, prop := range genState.ConsumerRemovalProposals { - k.SetPendingConsumerRemovalProp(ctx, prop.ChainId, prop.StopTime) + p := prop + k.SetPendingConsumerRemovalProp(ctx, &p) } for _, ubdOp := range genState.UnbondingOps { k.SetUnbondingOp(ctx, ubdOp) @@ -57,16 +54,15 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { if err := k.SetConsumerGenesis(ctx, chainID, cs.ConsumerGenesis); err != nil { panic(fmt.Errorf("consumer chain genesis could not be persisted: %w", err)) } + for _, ubdOpIndex := range cs.UnbondingOpsIndex { + k.SetUnbondingOpIndex(ctx, chainID, ubdOpIndex.GetVscId(), ubdOpIndex.GetUnbondingOpIds()) + } // check if the CCV channel was established if cs.ChannelId != "" { k.SetChannelToChain(ctx, cs.ChannelId, chainID) k.SetChainToChannel(ctx, chainID, cs.ChannelId) k.SetInitChainHeight(ctx, chainID, cs.InitialHeight) - k.SetSlashAcks(ctx, cs.ChainId, cs.SlashDowntimeAck) - for _, ubdOpIndex := range cs.UnbondingOpsIndex { - k.SetUnbondingOpIndex(ctx, chainID, ubdOpIndex.ValsetUpdateId, ubdOpIndex.UnbondingOpIndex) - } } else { k.AppendPendingVSCPackets(ctx, chainID, cs.PendingValsetChanges...) } @@ -93,122 +89,65 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { // ExportGenesis returns the CCV provider module's exported genesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - var consumerStates []types.ConsumerState + // get a list of all registered consumer chains + registeredChains := k.GetAllConsumerChains(ctx) + // export states for each consumer chains - k.IterateConsumerChains(ctx, func(ctx sdk.Context, chainID, clientID string) (stop bool) { - gen, found := k.GetConsumerGenesis(ctx, chainID) + var consumerStates []types.ConsumerState + for _, chain := range registeredChains { + gen, found := k.GetConsumerGenesis(ctx, chain.ChainId) if !found { - panic(fmt.Errorf("cannot find genesis for consumer chain %s with client %s", chainID, clientID)) + panic(fmt.Errorf("cannot find genesis for consumer chain %s with client %s", chain.ChainId, chain.ClientId)) } // initial consumer chain states cs := types.ConsumerState{ - ChainId: chainID, - ClientId: clientID, - ConsumerGenesis: gen, + ChainId: chain.ChainId, + ClientId: chain.ClientId, + ConsumerGenesis: gen, + UnbondingOpsIndex: k.GetAllUnbondingOpIndexes(ctx, chain.ChainId), } // try to find channel id for the current consumer chain - channelId, found := k.GetChainToChannel(ctx, chainID) + channelId, found := k.GetChainToChannel(ctx, chain.ChainId) if found { cs.ChannelId = channelId - cs.InitialHeight, found = k.GetInitChainHeight(ctx, chainID) + cs.InitialHeight, found = k.GetInitChainHeight(ctx, chain.ChainId) if !found { - panic(fmt.Errorf("cannot find genesis for consumer chain %s with client %s", chainID, clientID)) + panic(fmt.Errorf("cannot find genesis for consumer chain %s with client %s", chain.ChainId, chain.ClientId)) } - cs.SlashDowntimeAck = k.GetSlashAcks(ctx, chainID) - k.IterateOverUnbondingOpIndex(ctx, chainID, func(vscID uint64, ubdIndex []uint64) (stop bool) { - cs.UnbondingOpsIndex = append(cs.UnbondingOpsIndex, - types.UnbondingOpIndex{ValsetUpdateId: vscID, UnbondingOpIndex: ubdIndex}, - ) - return false // do not stop the iteration - }) + cs.SlashDowntimeAck = k.GetSlashAcks(ctx, chain.ChainId) } - cs.PendingValsetChanges = k.GetPendingVSCPackets(ctx, chainID) + cs.PendingValsetChanges = k.GetPendingVSCPackets(ctx, chain.ChainId) consumerStates = append(consumerStates, cs) - return false // do not stop the iteration - }) - - // export provider chain state - vscID := k.GetValidatorSetUpdateId(ctx) - vscIDToHeights := []types.ValsetUpdateIdToHeight{} - k.IterateValsetUpdateBlockHeight(ctx, func(vscID, height uint64) (stop bool) { - vscIDToHeights = append(vscIDToHeights, types.ValsetUpdateIdToHeight{ValsetUpdateId: vscID, Height: height}) - return false // do not stop the iteration - }) - - ubdOps := []ccv.UnbondingOp{} - k.IterateOverUnbondingOps(ctx, func(id uint64, ubdOp ccv.UnbondingOp) (stop bool) { - ubdOps = append(ubdOps, ubdOp) - return false // do not stop the iteration - }) + + } matureUbdOps, err := k.GetMaturedUnbondingOps(ctx) if err != nil { panic(err) } - addProps := []types.ConsumerAdditionProposal{} - k.IteratePendingConsumerAdditionProps(ctx, func(_ time.Time, prop types.ConsumerAdditionProposal) (stop bool) { - addProps = append(addProps, prop) - return false // do not stop the iteration - }) - - remProps := []types.ConsumerRemovalProposal{} - k.IteratePendingConsumerRemovalProps(ctx, func(_ time.Time, prop types.ConsumerRemovalProposal) (stop bool) { - remProps = append(remProps, prop) - return false // do not stop the iteration - }) - - // Export key assignment states - validatorConsumerPubKeys := []types.ValidatorConsumerPubKey{} - k.IterateAllValidatorConsumerPubKeys(ctx, func(chainID string, providerAddr sdk.ConsAddress, consumerKey tmcrypto.PublicKey) (stop bool) { - validatorConsumerPubKeys = append(validatorConsumerPubKeys, types.ValidatorConsumerPubKey{ - ChainId: chainID, - ProviderAddr: providerAddr, - ConsumerKey: &consumerKey, - }) - return false // do not stop the iteration - }) - - validatorsByConsumerAddr := []types.ValidatorByConsumerAddr{} - k.IterateAllValidatorsByConsumerAddr(ctx, func(chainID string, consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - validatorsByConsumerAddr = append(validatorsByConsumerAddr, types.ValidatorByConsumerAddr{ - ChainId: chainID, - ConsumerAddr: consumerAddr, - ProviderAddr: providerAddr, - }) - return false // do not stop the iteration - }) - - consumerAddrsToPrune := []types.ConsumerAddrsToPrune{} // ConsumerAddrsToPrune are added only for registered consumer chains - k.IterateConsumerChains(ctx, func(ctx sdk.Context, chainID string, _ string) (stopOuter bool) { - k.IterateConsumerAddrsToPrune(ctx, chainID, func(vscID uint64, consumerAddrs types.AddressList) (stopInner bool) { - consumerAddrsToPrune = append(consumerAddrsToPrune, types.ConsumerAddrsToPrune{ - ChainId: chainID, - VscId: vscID, - ConsumerAddrs: &consumerAddrs, - }) - return false // do not stop the iteration - }) - return false // do not stop the iteration - }) + consumerAddrsToPrune := []types.ConsumerAddrsToPrune{} + for _, chain := range registeredChains { + consumerAddrsToPrune = append(consumerAddrsToPrune, k.GetAllConsumerAddrsToPrune(ctx, chain.ChainId)...) + } params := k.GetParams(ctx) return types.NewGenesisState( - vscID, - vscIDToHeights, + k.GetValidatorSetUpdateId(ctx), + k.GetAllValsetUpdateBlockHeights(ctx), consumerStates, - ubdOps, + k.GetAllUnbondingOps(ctx), &ccv.MaturedUnbondingOps{Ids: matureUbdOps}, - addProps, - remProps, + k.GetAllPendingConsumerAdditionProps(ctx), + k.GetAllPendingConsumerRemovalProps(ctx), params, - validatorConsumerPubKeys, - validatorsByConsumerAddr, + k.GetAllValidatorConsumerPubKeys(ctx, nil), + k.GetAllValidatorsByConsumerAddr(ctx, nil), consumerAddrsToPrune, ) } diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index 22e4223da0..8304e11849 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -45,8 +45,8 @@ func TestInitAndExportGenesis(t *testing.T) { "channel", initHeight, *consumertypes.DefaultGenesisState(), - []providertypes.UnbondingOpIndex{ - {ValsetUpdateId: vscID, UnbondingOpIndex: ubdIndex}, + []providertypes.VscUnbondingOps{ + {VscId: vscID, UnbondingOpIds: ubdIndex}, }, []ccv.ValidatorSetChangePacketData{}, []string{"slashedValidatorConsAddress"}, @@ -62,7 +62,7 @@ func TestInitAndExportGenesis(t *testing.T) { nil, ), }, - []ccv.UnbondingOp{{ + []providertypes.UnbondingOp{{ Id: vscID, UnbondingConsumerChains: []string{cChainIDs[0]}, }}, @@ -143,7 +143,7 @@ func TestInitAndExportGenesis(t *testing.T) { addProp, found := pk.GetPendingConsumerAdditionProp(ctx, oneHourFromNow, cChainIDs[0]) require.True(t, found) require.Equal(t, provGenesis.ConsumerAdditionProposals[0], addProp) - require.True(t, pk.GetPendingConsumerRemovalProp(ctx, cChainIDs[0], oneHourFromNow)) + require.True(t, pk.PendingConsumerRemovalPropExists(ctx, cChainIDs[0], oneHourFromNow)) require.Equal(t, provGenesis.Params, pk.GetParams(ctx)) gotConsTmPubKey, found := pk.GetValidatorConsumerPubKey(ctx, cChainIDs[0], provAddr) @@ -193,9 +193,9 @@ func assertConsumerChainStates(ctx sdk.Context, t *testing.T, pk keeper.Keeper, } for _, ubdOpIdx := range cs.UnbondingOpsIndex { - ubdIndex, found := pk.GetUnbondingOpIndex(ctx, chainID, ubdOpIdx.ValsetUpdateId) + ubdIndex, found := pk.GetUnbondingOpIndex(ctx, chainID, ubdOpIdx.VscId) require.True(t, found) - require.Equal(t, ubdOpIdx.UnbondingOpIndex, ubdIndex) + require.Equal(t, ubdOpIdx.UnbondingOpIds, ubdIndex) } require.Equal(t, cs.SlashDowntimeAck, pk.GetSlashAcks(ctx, chainID)) diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 83b89d41f2..98418ddad6 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -40,15 +40,14 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu } ctx := sdk.UnwrapSDKContext(goCtx) + + // convert to array of pointers chains := []*types.Chain{} - cb := func(ctx sdk.Context, chainID, clientID string) (stop bool) { - chains = append(chains, &types.Chain{ - ChainId: chainID, - ClientId: clientID, - }) - return false // do not stop the iteration + for _, chain := range k.GetAllConsumerChains(ctx) { + // prevent implicit memory aliasing + c := chain + chains = append(chains, &c) } - k.IterateConsumerChains(ctx, cb) return &types.QueryConsumerChainsResponse{Chains: chains}, nil } @@ -59,9 +58,15 @@ func (k Keeper) QueryConsumerChainStarts(goCtx context.Context, req *types.Query } ctx := sdk.UnwrapSDKContext(goCtx) - props := k.GetAllConsumerAdditionProps(ctx) + var props []*types.ConsumerAdditionProposal - return &types.QueryConsumerChainStartProposalsResponse{Proposals: &props}, nil + for _, prop := range k.GetAllPendingConsumerAdditionProps(ctx) { + // prevent implicit memory aliasing + p := prop + props = append(props, &p) + } + + return &types.QueryConsumerChainStartProposalsResponse{Proposals: &types.ConsumerAdditionProposals{Pending: props}}, nil } func (k Keeper) QueryConsumerChainStops(goCtx context.Context, req *types.QueryConsumerChainStopProposalsRequest) (*types.QueryConsumerChainStopProposalsResponse, error) { @@ -70,9 +75,14 @@ func (k Keeper) QueryConsumerChainStops(goCtx context.Context, req *types.QueryC } ctx := sdk.UnwrapSDKContext(goCtx) - props := k.GetAllConsumerRemovalProps(ctx) + var props []*types.ConsumerRemovalProposal + for _, prop := range k.GetAllPendingConsumerRemovalProps(ctx) { + // prevent implicit memory aliasing + p := prop + props = append(props, &p) + } - return &types.QueryConsumerChainStopProposalsResponse{Proposals: &props}, nil + return &types.QueryConsumerChainStopProposalsResponse{Proposals: &types.ConsumerRemovalProposals{Pending: props}}, nil } func (k Keeper) QueryValidatorConsumerAddr(goCtx context.Context, req *types.QueryValidatorConsumerAddrRequest) (*types.QueryValidatorConsumerAddrResponse, error) { diff --git a/x/ccv/provider/keeper/hooks.go b/x/ccv/provider/keeper/hooks.go index 21d0deb57f..65e3a1c86f 100644 --- a/x/ccv/provider/keeper/hooks.go +++ b/x/ccv/provider/keeper/hooks.go @@ -4,10 +4,9 @@ import ( "fmt" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - ccv "github.com/cosmos/interchain-security/x/ccv/types" + "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/utils" ) @@ -27,16 +26,16 @@ func (k *Keeper) Hooks() Hooks { func (h Hooks) AfterUnbondingInitiated(ctx sdk.Context, ID uint64) error { var consumerChainIDS []string - h.k.IterateConsumerChains(ctx, func(ctx sdk.Context, chainID, clientID string) (stop bool) { - consumerChainIDS = append(consumerChainIDS, chainID) - return false // do not stop the iteration - }) + for _, chain := range h.k.GetAllConsumerChains(ctx) { + consumerChainIDS = append(consumerChainIDS, chain.ChainId) + } + if len(consumerChainIDS) == 0 { // Do not put the unbonding op on hold if there are no consumer chains return nil } valsetUpdateID := h.k.GetValidatorSetUpdateId(ctx) - unbondingOp := ccv.UnbondingOp{ + unbondingOp := types.UnbondingOp{ Id: ID, UnbondingConsumerChains: consumerChainIDS, } @@ -74,15 +73,12 @@ func ValidatorConsensusKeyInUse(k *Keeper, ctx sdk.Context, valAddr sdk.ValAddre inUse := false - // Search over all consumer keys which have been assigned in order to - // check if the validator being added is, or was, a consumer chain validator - k.IterateAllValidatorsByConsumerAddr(ctx, func(_ string, consumerAddr sdk.ConsAddress, _ sdk.ConsAddress) (stop bool) { - if consumerAddr.Equals(consensusAddr) { + for _, validatorConsumerAddrs := range k.GetAllValidatorsByConsumerAddr(ctx, nil) { + if sdk.ConsAddress(validatorConsumerAddrs.ConsumerAddr).Equals(consensusAddr) { inUse = true - return true + break } - return false - }) + } return inUse } @@ -95,31 +91,12 @@ func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { } func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, valConsAddr sdk.ConsAddress, valAddr sdk.ValAddress) { - type StoreKey struct { - ChainID string - ProviderAddr sdk.ConsAddress - ConsumerKey tmprotocrypto.PublicKey - } - toDelete := []StoreKey{} - h.k.IterateAllValidatorConsumerPubKeys(ctx, func( - chainID string, - providerAddr sdk.ConsAddress, - consumerKey tmprotocrypto.PublicKey, - ) (stop bool) { - if providerAddr.Equals(valConsAddr) { - toDelete = append(toDelete, - StoreKey{ - ChainID: chainID, - ProviderAddr: providerAddr, - ConsumerKey: consumerKey, - }) + for _, validatorConsumerPubKey := range h.k.GetAllValidatorConsumerPubKeys(ctx, nil) { + if sdk.ConsAddress(validatorConsumerPubKey.ProviderAddr).Equals(valConsAddr) { + consumerAddr := utils.TMCryptoPublicKeyToConsAddr(*validatorConsumerPubKey.ConsumerKey) + h.k.DeleteValidatorByConsumerAddr(ctx, validatorConsumerPubKey.ChainId, consumerAddr) + h.k.DeleteValidatorConsumerPubKey(ctx, validatorConsumerPubKey.ChainId, validatorConsumerPubKey.ProviderAddr) } - return false // do not stop - }) - for _, key := range toDelete { - consumerAddr := utils.TMCryptoPublicKeyToConsAddr(key.ConsumerKey) - h.k.DeleteValidatorByConsumerAddr(ctx, key.ChainID, consumerAddr) - h.k.DeleteValidatorConsumerPubKey(ctx, key.ChainID, key.ProviderAddr) } } diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 9daf0101f3..03c27ba9ec 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -133,10 +133,13 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { store.Delete(types.ChainToChannelKey(chainID)) } -// IterateConsumerChains iterates over all of the consumer chains that the provider module controls -// It calls the provided callback function which takes in a chainID and client ID to return -// a stop boolean which will stop the iteration. -func (k Keeper) IterateConsumerChains(ctx sdk.Context, cb func(ctx sdk.Context, chainID, clientID string) (stop bool)) { +// GetAllConsumerChains gets all of the consumer chains, for which the provider module +// created IBC clients. Consumer chains with created clients are also referred to as registered. +// +// Note that the registered consumer chains are stored under keys with the following format: +// ChainToClientBytePrefix | chainID +// Thus, the returned array is in ascending order of chainIDs. +func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.ChainToClientBytePrefix}) defer iterator.Close() @@ -146,11 +149,13 @@ func (k Keeper) IterateConsumerChains(ctx sdk.Context, cb func(ctx sdk.Context, chainID := string(iterator.Key()[1:]) clientID := string(iterator.Value()) - stop := cb(ctx, chainID, clientID) - if stop { - return - } + chains = append(chains, types.Chain{ + ChainId: chainID, + ClientId: clientID, + }) } + + return chains } // SetChannelToChain sets the mapping from the CCV channel ID to the consumer chainID. @@ -169,15 +174,20 @@ func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bo return string(bz), true } -// DeleteChannelToChain deletes the consumer chain ID for a given CCV channe lID +// DeleteChannelToChain deletes the consumer chain ID for a given CCV channelID func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.ChannelToChainKey(channelID)) } -// IterateChannelToChain iterates over the channel to chain mappings and calls the provided callback until the iteration ends -// or the callback returns stop=true -func (k Keeper) IterateChannelToChain(ctx sdk.Context, cb func(ctx sdk.Context, channelID, chainID string) (stop bool)) { +// GetAllChannelToChains gets all channel to chain mappings. If a mapping exists, +// then the CCV channel to that consumer chain is established. +// +// Note that mapping from CCV channel IDs to consumer chainIDs +// is stored under keys with the following format: +// ChannelToChainBytePrefix | channelID +// Thus, the returned array is in ascending order of channelIDs. +func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.ChannelToChain) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.ChannelToChainBytePrefix}) defer iterator.Close() @@ -185,14 +195,15 @@ func (k Keeper) IterateChannelToChain(ctx sdk.Context, cb func(ctx sdk.Context, for ; iterator.Valid(); iterator.Next() { // remove prefix from key to retrieve channelID channelID := string(iterator.Key()[1:]) - chainID := string(iterator.Value()) - stop := cb(ctx, channelID, chainID) - if stop { - break - } + channels = append(channels, types.ChannelToChain{ + ChannelId: channelID, + ChainId: chainID, + }) } + + return channels } func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen consumertypes.GenesisState) error { @@ -300,8 +311,8 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { return nil } -// Save UnbondingOp by unique ID -func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp ccv.UnbondingOp) { +// SetUnbondingOp sets the UnbondingOp by its unique ID +func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { store := ctx.KVStore(k.storeKey) bz, err := unbondingOp.Marshal() if err != nil { @@ -310,23 +321,36 @@ func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp ccv.UnbondingOp) { store.Set(types.UnbondingOpKey(unbondingOp.Id), bz) } -// Get UnbondingOp by unique ID -func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (ccv.UnbondingOp, bool) { +// GetUnbondingOp gets a UnbondingOp by its unique ID +func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.UnbondingOpKey(id)) if bz == nil { - return ccv.UnbondingOp{}, false + return types.UnbondingOp{}, false + } + + var unbondingOp types.UnbondingOp + if err := unbondingOp.Unmarshal(bz); err != nil { + panic(fmt.Errorf("failed to unmarshal UnbondingOp: %w", err)) } - return types.MustUnmarshalUnbondingOp(k.cdc, bz), true + return unbondingOp, true } +// DeleteUnbondingOp deletes a UnbondingOp given its ID func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { store := ctx.KVStore(k.storeKey) store.Delete(types.UnbondingOpKey(id)) } -func (k Keeper) IterateOverUnbondingOps(ctx sdk.Context, cb func(id uint64, ubdOp ccv.UnbondingOp) (stop bool)) { +// GetAllUnbondingOps gets all UnbondingOps, where each UnbondingOp consists +// of its unique ID and a list of consumer chainIDs that the unbonding operation +// is waiting on. +// +// Note that UnbondingOps are stored under keys with the following format: +// UnbondingOpBytePrefix | ID +// Thus, the iteration is in ascending order of IDs. +func (k Keeper) GetAllUnbondingOps(ctx sdk.Context) (ops []types.UnbondingOp) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.UnbondingOpBytePrefix}) @@ -337,84 +361,88 @@ func (k Keeper) IterateOverUnbondingOps(ctx sdk.Context, cb func(id uint64, ubdO if bz == nil { panic(fmt.Errorf("unbonding operation is nil for id %d", id)) } - ubdOp := types.MustUnmarshalUnbondingOp(k.cdc, bz) - - stop := cb(id, ubdOp) - if stop { - break + var unbondingOp types.UnbondingOp + if err := unbondingOp.Unmarshal(bz); err != nil { + panic(fmt.Errorf("failed to unmarshal UnbondingOp: %w", err)) } + + ops = append(ops, unbondingOp) } + + return ops } -// This index allows retreiving UnbondingDelegationEntries by chainID and valsetUpdateID -func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64, IDs []uint64) { +// SetUnbondingOpIndex sets the IDs of unbonding operations that are waiting for +// a VSCMaturedPacket with vscID from a consumer with chainID +func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64, IDs []uint64) { store := ctx.KVStore(k.storeKey) - index := ccv.UnbondingOpsIndex{ - Ids: IDs, + vscUnbondingOps := types.VscUnbondingOps{ + VscId: vscID, + UnbondingOpIds: IDs, } - bz, err := index.Marshal() + bz, err := vscUnbondingOps.Marshal() if err != nil { - panic("Failed to marshal UnbondingOpsIndex") + panic(fmt.Errorf("failed to marshal VscUnbondingOps: %w", err)) } - store.Set(types.UnbondingOpIndexKey(chainID, valsetUpdateID), bz) + store.Set(types.UnbondingOpIndexKey(chainID, vscID), bz) } -// IterateOverUnbondingOpIndex iterates over the unbonding indexes for a given chain id. -func (k Keeper) IterateOverUnbondingOpIndex( - ctx sdk.Context, - chainID string, - cb func(vscID uint64, ubdIndex []uint64) (stop bool), -) { +// GetAllUnbondingOpIndexes gets all unbonding indexes for a given chain id, +// i.e., all the IDs of unbonding operations that are waiting for +// VSCMaturedPackets from a consumer with chainID. +// +// Note that the unbonding indexes for a given chainID are stored under keys with the following format: +// UnbondingOpIndexBytePrefix | len(chainID) | chainID | vscID +// Thus, the returned array is in ascending order of vscIDs. +func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (indexes []types.VscUnbondingOps) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - // parse key to get the current VSC ID - _, vscID, err := types.ParseUnbondingOpIndexKey(iterator.Key()) - if err != nil { - panic(fmt.Errorf("failed to parse UnbondingOpIndexKey: %w", err)) - } - - var index ccv.UnbondingOpsIndex - if err = index.Unmarshal(iterator.Value()); err != nil { - panic("Failed to unmarshal JSON") + var vscUnbondingOps types.VscUnbondingOps + if err := vscUnbondingOps.Unmarshal(iterator.Value()); err != nil { + panic(fmt.Errorf("failed to unmarshal VscUnbondingOps: %w", err)) } - stop := cb(vscID, index.GetIds()) - if stop { - return - } + indexes = append(indexes, types.VscUnbondingOps{ + VscId: vscUnbondingOps.GetVscId(), + UnbondingOpIds: vscUnbondingOps.GetUnbondingOpIds(), + }) } + + return indexes } -// This index allows retrieving UnbondingDelegationEntries by chainID and valsetUpdateID -func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64) ([]uint64, bool) { +// GetUnbondingOpIndex gets the IDs of unbonding operations that are waiting for +// a VSCMaturedPacket with vscID from a consumer with chainID +func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) ([]uint64, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UnbondingOpIndexKey(chainID, valsetUpdateID)) + bz := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) if bz == nil { return []uint64{}, false } - var idx ccv.UnbondingOpsIndex - if err := idx.Unmarshal(bz); err != nil { - panic("Failed to unmarshal UnbondingOpsIndex") + var vscUnbondingOps types.VscUnbondingOps + if err := vscUnbondingOps.Unmarshal(bz); err != nil { + panic(fmt.Errorf("failed to unmarshal VscUnbondingOps: %w", err)) } - return idx.GetIds(), true + return vscUnbondingOps.GetUnbondingOpIds(), true } -// This index allows retreiving UnbondingDelegationEntries by chainID and valsetUpdateID -func (k Keeper) DeleteUnbondingOpIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64) { +// DeleteUnbondingOpIndex deletes the IDs of unbonding operations that are waiting for +// a VSCMaturedPacket with vscID from a consumer with chainID +func (k Keeper) DeleteUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) { store := ctx.KVStore(k.storeKey) - store.Delete(types.UnbondingOpIndexKey(chainID, valsetUpdateID)) + store.Delete(types.UnbondingOpIndexKey(chainID, vscID)) } -// Retrieve UnbondingDelegationEntries by chainID and valsetUpdateID -func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64) (entries []ccv.UnbondingOp, found bool) { +// GetUnbondingOpsFromIndex gets the unbonding ops waiting for a given chainID and vscID +func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64) (entries []types.UnbondingOp, found bool) { ids, found := k.GetUnbondingOpIndex(ctx, chainID, valsetUpdateID) if !found { return entries, false @@ -422,7 +450,6 @@ func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valset for _, id := range ids { entry, found := k.GetUnbondingOp(ctx, id) if !found { - // TODO JEHAN: is this the correct way to deal with this? panic("did not find UnbondingOp according to index- index was probably not correctly updated") } entries = append(entries, entry) @@ -559,22 +586,27 @@ func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint6 return binary.BigEndian.Uint64(bz), true } -// IterateSlashAcks iterates through the slash acks set in the store -func (k Keeper) IterateValsetUpdateBlockHeight(ctx sdk.Context, cb func(valsetUpdateId, height uint64) (stop bool)) { +// GetAllValsetUpdateBlockHeights gets all the block heights for all valset updates +// +// Note that the mapping from vscIDs to block heights is stored under keys with the following format: +// ValsetUpdateBlockHeightBytePrefix | vscID +// Thus, the returned array is in ascending order of vscIDs. +func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlockHeights []types.ValsetUpdateIdToHeight) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.ValsetUpdateBlockHeightBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - valsetUpdateId := binary.BigEndian.Uint64(iterator.Key()[1:]) height := binary.BigEndian.Uint64(iterator.Value()) - stop := cb(valsetUpdateId, height) - if stop { - return - } + valsetUpdateBlockHeights = append(valsetUpdateBlockHeights, types.ValsetUpdateIdToHeight{ + ValsetUpdateId: valsetUpdateId, + Height: height, + }) } + + return valsetUpdateBlockHeights } // DeleteValsetUpdateBlockHeight deletes the block height value for a given vaset update id @@ -623,30 +655,6 @@ func (k Keeper) ConsumeSlashAcks(ctx sdk.Context, chainID string) (acks []string return } -// IterateSlashAcks iterates through the slash acks set in the store. -// Note: this method is only used in testing -func (k Keeper) IterateSlashAcks(ctx sdk.Context, cb func(chainID string, acks []string) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.SlashAcksBytePrefix}) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - - chainID := string(iterator.Key()[1:]) - - var sa types.SlashAcks - err := sa.Unmarshal(iterator.Value()) - if err != nil { - panic(fmt.Errorf("failed to unmarshal SlashAcks: %w", err)) - } - - stop := cb(chainID, sa.GetAddresses()) - if stop { - return - } - } -} - // AppendSlashAck appends the given slash ack to the given chain ID slash acks in store func (k Keeper) AppendSlashAck(ctx sdk.Context, chainID, ack string) { acks := k.GetSlashAcks(ctx, chainID) @@ -762,9 +770,12 @@ func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { store.Delete(types.InitTimeoutTimestampKey(chainID)) } -// IterateInitTimeoutTimestamp iterates through the init timeout timestamps in the store. -// Note: as the keys have the `bytePrefix | chainID` format, the iteration is NOT done in timestamp order. -func (k Keeper) IterateInitTimeoutTimestamp(ctx sdk.Context, cb func(chainID string, ts uint64) (stop bool)) { +// GetAllInitTimeoutTimestamps gets all init timeout timestamps in the store. +// +// Note that the init timeout timestamps are stored under keys with the following format: +// InitTimeoutTimestampBytePrefix | chainID +// Thus, the returned array is in ascending order of chainIDs (NOT in timestamp order). +func (k Keeper) GetAllInitTimeoutTimestamps(ctx sdk.Context) (initTimeoutTimestamps []types.InitTimeoutTimestamp) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.InitTimeoutTimestampBytePrefix}) @@ -773,11 +784,13 @@ func (k Keeper) IterateInitTimeoutTimestamp(ctx sdk.Context, cb func(chainID str chainID := string(iterator.Key()[1:]) ts := binary.BigEndian.Uint64(iterator.Value()) - stop := cb(chainID, ts) - if stop { - return - } + initTimeoutTimestamps = append(initTimeoutTimestamps, types.InitTimeoutTimestamp{ + ChainId: chainID, + Timestamp: ts, + }) } + + return initTimeoutTimestamps } // SetVscSendTimestamp sets the VSC send timestamp @@ -821,20 +834,18 @@ func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID ui store.Delete(types.VscSendingTimestampKey(chainID, vscID)) } -// IterateVscSendTimestamps iterates in order (lowest first) -// over the vsc send timestamps of the given chainID. -func (k Keeper) IterateVscSendTimestamps( - ctx sdk.Context, - chainID string, - cb func(vscID uint64, ts time.Time) (stop bool), -) { +// GetAllVscSendTimestamps gets an array of all the vsc send timestamps of the given chainID. +// +// Note that the vsc send timestamps of a given chainID are stored under keys with the following format: +// VscSendTimestampBytePrefix | len(chainID) | chainID | vscID +// Thus, the iteration is in ascending order of vscIDs, and as a result in send timestamp order. +func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSendTimestamps []types.VscSendTimestamp) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - key := iterator.Key() - _, vscID, err := types.ParseVscSendingTimestampKey(key) + _, vscID, err := types.ParseVscSendingTimestampKey(iterator.Key()) if err != nil { panic(fmt.Errorf("failed to parse VscSendTimestampKey: %w", err)) } @@ -843,9 +854,36 @@ func (k Keeper) IterateVscSendTimestamps( panic(fmt.Errorf("failed to parse timestamp value: %w", err)) } - stop := cb(vscID, ts) - if stop { - return + vscSendTimestamps = append(vscSendTimestamps, types.VscSendTimestamp{ + VscId: vscID, + Timestamp: ts, + }) + } + + return vscSendTimestamps +} + +// GetFirstVscSendTimestamp gets the vsc send timestamp with the lowest vscID for the given chainID. +func (k Keeper) GetFirstVscSendTimestamp(ctx sdk.Context, chainID string) (vscSendTimestamp types.VscSendTimestamp, found bool) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) + defer iterator.Close() + + if iterator.Valid() { + _, vscID, err := types.ParseVscSendingTimestampKey(iterator.Key()) + if err != nil { + panic(fmt.Errorf("failed to parse VscSendTimestampKey: %w", err)) } + ts, err := sdk.ParseTimeBytes(iterator.Value()) + if err != nil { + panic(fmt.Errorf("failed to parse timestamp value: %w", err)) + } + + return types.VscSendTimestamp{ + VscId: vscID, + Timestamp: ts, + }, true } + + return types.VscSendTimestamp{}, false } diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index 895fb113c8..e0c94e1f91 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -2,15 +2,16 @@ package keeper_test import ( "fmt" + "sort" "testing" "time" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" ibcsimapp "github.com/cosmos/ibc-go/v3/testing/simapp" testkeeper "github.com/cosmos/interchain-security/testutil/keeper" + "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" abci "github.com/tendermint/tendermint/abci/types" tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" @@ -44,21 +45,52 @@ func TestValsetUpdateBlockHeight(t *testing.T) { require.Equal(t, blockHeight, uint64(4)) } -// TestSlashAcks tests the getter, setter, iteration, and deletion methods for stored slash acknowledgements -func TestSlashAcks(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +// TestGetAllValsetUpdateBlockHeights tests GetAllValsetUpdateBlockHeights behaviour correctness +func TestGetAllValsetUpdateBlockHeights(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - var chainsAcks [][]string + cases := []types.ValsetUpdateIdToHeight{ + { + ValsetUpdateId: 2, + Height: 22, + }, + { + ValsetUpdateId: 1, + Height: 11, + }, + { + // normal execution should not have two ValsetUpdateIdToHeight + // with the same Height, but let's test it anyway + ValsetUpdateId: 4, + Height: 11, + }, + { + ValsetUpdateId: 3, + Height: 33, + }, + } + expectedGetAllOrder := cases + // sorting by ValsetUpdateId + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].ValsetUpdateId < expectedGetAllOrder[j].ValsetUpdateId + }) - penaltiesfN := func() (penalties []string) { - providerKeeper.IterateSlashAcks(ctx, func(id string, acks []string) (stop bool) { - chainsAcks = append(chainsAcks, acks) - return false // do not stop iteration - }) - return + for _, c := range cases { + pk.SetValsetUpdateBlockHeight(ctx, c.ValsetUpdateId, c.Height) } + // iterate and check all results are returned in the expected order + result := pk.GetAllValsetUpdateBlockHeights(ctx) + require.Len(t, result, len(cases)) + require.Equal(t, expectedGetAllOrder, result) +} + +// TestSlashAcks tests the getter, setter, iteration, and deletion methods for stored slash acknowledgements +func TestSlashAcks(t *testing.T) { + providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + chainID := "consumer" acks := providerKeeper.GetSlashAcks(ctx, chainID) @@ -83,8 +115,9 @@ func TestSlashAcks(t *testing.T) { providerKeeper.SetSlashAcks(ctx, c, p) } - penaltiesfN() - require.Len(t, chainsAcks, len(chains)) + for _, c := range chains { + require.Equal(t, p, providerKeeper.GetSlashAcks(ctx, c)) + } } // TestAppendSlashAck tests the append method for stored slash acknowledgements @@ -183,30 +216,44 @@ func TestInitHeight(t *testing.T) { } } -func TestIterateOverUnbondingOpIndex(t *testing.T) { - - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +// TestGetAllUnbondingOpIndexes tests GetAllUnbondingOpIndexes behavior correctness +func TestGetAllUnbondingOpIndexes(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - chainID := "6" - - // mock an unbonding index - unbondingOpIndex := []uint64{0, 1, 2, 3, 4, 5, 6} + ops := []types.VscUnbondingOps{ + { + VscId: 2, + UnbondingOpIds: []uint64{4, 5, 6, 7}, + }, + { + VscId: 1, + UnbondingOpIds: []uint64{1, 2, 3}, + }, + { + VscId: 4, + UnbondingOpIds: []uint64{10}, + }, + { + VscId: 3, + UnbondingOpIds: []uint64{8, 9}, + }, + } + // sorting by CrossChainValidator.Address + expectedGetAllOrder := ops + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].VscId < expectedGetAllOrder[j].VscId + }) - // set ubd ops by varying vsc ids and index slices - for i := 1; i < len(unbondingOpIndex); i++ { - providerKeeper.SetUnbondingOpIndex(ctx, chainID, uint64(i), unbondingOpIndex[:i]) + pk.SetUnbondingOpIndex(ctx, "chain-2", 1, []uint64{1, 2, 3}) + for _, op := range ops { + pk.SetUnbondingOpIndex(ctx, "chain-1", op.VscId, op.UnbondingOpIds) } - // check iterator returns expected entries - i := 1 - providerKeeper.IterateOverUnbondingOpIndex(ctx, chainID, func(vscID uint64, ubdIndex []uint64) (stop bool) { - require.Equal(t, uint64(i), vscID) - require.EqualValues(t, unbondingOpIndex[:i], ubdIndex) - i++ - return false // do not stop the iteration - }) - require.Equal(t, len(unbondingOpIndex), i) + // iterate and check all results are returned in the expected order + result := pk.GetAllUnbondingOpIndexes(ctx, "chain-1") + require.Len(t, result, len(ops)) + require.Equal(t, result, expectedGetAllOrder) } func TestMaturedUnbondingOps(t *testing.T) { @@ -230,44 +277,55 @@ func TestMaturedUnbondingOps(t *testing.T) { } func TestInitTimeoutTimestamp(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - tc := []struct { - chainID string - expected uint64 - }{ - // ordered alphabetically - descending - {expected: 5, chainID: "z-chain"}, - {expected: 12, chainID: "b-chain"}, - {expected: 10, chainID: "a-chain"}, + now := time.Now().UTC() + nsNow := uint64(now.UnixNano()) + timeoutTimestamps := []types.InitTimeoutTimestamp{ + { + ChainId: "chain-2", + Timestamp: nsNow, + }, + { + ChainId: "chain-1", + Timestamp: nsNow + 10, + }, + { + ChainId: "chain-4", + Timestamp: nsNow - 10, + }, + { + ChainId: "chain-3", + Timestamp: nsNow, + }, } - _, found := providerKeeper.GetInitTimeoutTimestamp(ctx, tc[0].chainID) + expectedGetAllOrder := timeoutTimestamps + // sorting by ChainId + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].ChainId < expectedGetAllOrder[j].ChainId + }) + + _, found := pk.GetInitTimeoutTimestamp(ctx, timeoutTimestamps[0].ChainId) require.False(t, found) - providerKeeper.SetInitTimeoutTimestamp(ctx, tc[0].chainID, tc[0].expected) - providerKeeper.SetInitTimeoutTimestamp(ctx, tc[1].chainID, tc[1].expected) - providerKeeper.SetInitTimeoutTimestamp(ctx, tc[2].chainID, tc[2].expected) - - i := 2 - // store is iterated in alphabetical ascending order - // not in the order of insertion - providerKeeper.IterateInitTimeoutTimestamp(ctx, func(chainID string, ts uint64) (stop bool) { - require.Equal(t, chainID, tc[i].chainID) - require.Equal(t, ts, tc[i].expected) - i-- - return false // do not stop the iteration - }) + for _, tt := range timeoutTimestamps { + pk.SetInitTimeoutTimestamp(ctx, tt.ChainId, tt.Timestamp) + } - for _, tc := range tc { - ts, found := providerKeeper.GetInitTimeoutTimestamp(ctx, tc.chainID) + for _, tt := range timeoutTimestamps { + _, found := pk.GetInitTimeoutTimestamp(ctx, tt.ChainId) require.True(t, found) - require.Equal(t, tc.expected, ts) } - providerKeeper.DeleteInitTimeoutTimestamp(ctx, tc[1].chainID) - _, found = providerKeeper.GetInitTimeoutTimestamp(ctx, tc[1].chainID) + // iterate and check all results are returned in the expected order + result := pk.GetAllInitTimeoutTimestamps(ctx) + require.Len(t, result, len(timeoutTimestamps)) + require.Equal(t, result, expectedGetAllOrder) + + pk.DeleteInitTimeoutTimestamp(ctx, timeoutTimestamps[0].ChainId) + _, found = pk.GetInitTimeoutTimestamp(ctx, timeoutTimestamps[0].ChainId) require.False(t, found) } @@ -276,199 +334,136 @@ func TestVscSendTimestamp(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - now := ctx.BlockTime() + now := time.Now().UTC() testCases := []struct { chainID string ts time.Time vscID uint64 }{ - {chainID: "chain", ts: now.Add(time.Hour), vscID: 1}, {chainID: "chain", ts: now.Add(2 * time.Hour), vscID: 2}, + {chainID: "chain", ts: now.Add(time.Hour), vscID: 1}, + {chainID: "chain", ts: now.Add(time.Hour), vscID: 3}, + // this is not possible since the ts is the timestamp of sending, + // which means it must be in the same order as vscIDs, + // but it still worth testing + {chainID: "chain", ts: now.Add(-time.Hour), vscID: 4}, {chainID: "chain1", ts: now.Add(time.Hour), vscID: 1}, {chainID: "chain2", ts: now.Add(time.Hour), vscID: 1}, } - - i := 0 - chainID := "chain" - providerKeeper.IterateVscSendTimestamps(ctx, chainID, func(_ uint64, _ time.Time) (stop bool) { - i++ - return false // do not stop + chainID := testCases[0].chainID + expectedGetAllOrder := []types.VscSendTimestamp{} + for _, tc := range testCases { + if tc.chainID == chainID { + expectedGetAllOrder = append(expectedGetAllOrder, types.VscSendTimestamp{VscId: tc.vscID, Timestamp: tc.ts}) + } + } + // sorting by vscID + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].VscId < expectedGetAllOrder[j].VscId }) - require.Equal(t, 0, i) + + require.Empty(t, providerKeeper.GetAllVscSendTimestamps(ctx, chainID)) for _, tc := range testCases { providerKeeper.SetVscSendTimestamp(ctx, tc.chainID, tc.vscID, tc.ts) } - i = 0 - providerKeeper.IterateVscSendTimestamps(ctx, testCases[0].chainID, func(vscID uint64, ts time.Time) (stop bool) { - require.Equal(t, vscID, testCases[i].vscID) - require.Equal(t, ts, testCases[i].ts) - i++ - return false // do not stop - }) - require.Equal(t, 2, i) + // iterate and check all results are returned in the expected order + vscSendTimestamps := providerKeeper.GetAllVscSendTimestamps(ctx, chainID) + require.Equal(t, expectedGetAllOrder, vscSendTimestamps) + + vscSendTimestamp, found := providerKeeper.GetFirstVscSendTimestamp(ctx, chainID) + require.True(t, found) + require.Equal(t, vscSendTimestamp, expectedGetAllOrder[0]) // delete VSC send timestamps - var ids []uint64 - providerKeeper.IterateVscSendTimestamps(ctx, testCases[0].chainID, func(vscID uint64, _ time.Time) (stop bool) { - ids = append(ids, vscID) - return false // do not stop - }) - for _, vscID := range ids { - providerKeeper.DeleteVscSendTimestamp(ctx, testCases[0].chainID, vscID) + for _, vscSendTimestamp := range providerKeeper.GetAllVscSendTimestamps(ctx, chainID) { + providerKeeper.DeleteVscSendTimestamp(ctx, chainID, vscSendTimestamp.VscId) } - i = 0 - providerKeeper.IterateVscSendTimestamps(ctx, testCases[0].chainID, func(_ uint64, _ time.Time) (stop bool) { - i++ - return false // do not stop - }) - require.Equal(t, 0, i) + require.Empty(t, providerKeeper.GetAllVscSendTimestamps(ctx, chainID)) } -// TestIterateConsumerChains tests IterateConsumerChains behaviour correctness -func TestIterateConsumerChains(t *testing.T) { +// TestGetAllConsumerChains tests GetAllConsumerChains behaviour correctness +func TestGetAllConsumerChains(t *testing.T) { pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - chainIDs := []string{"chain-1", "chain-2"} - for _, c := range chainIDs { - pk.SetConsumerClientId(ctx, c, fmt.Sprintf("client-%s", c)) - } - - result := []string{} - testIterateAll := func(ctx sdk.Context, chainID, clientID string) (stop bool) { - result = append(result, chainID) - return false // will not stop iteration + chainIDs := []string{"chain-2", "chain-1", "chain-4", "chain-3"} + expectedGetAllOrder := []types.Chain{} + for i, chainID := range chainIDs { + clientID := fmt.Sprintf("client-%d", len(chainIDs)-i) + pk.SetConsumerClientId(ctx, chainID, clientID) + expectedGetAllOrder = append(expectedGetAllOrder, types.Chain{ChainId: chainID, ClientId: clientID}) } + // sorting by chainID + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].ChainId < expectedGetAllOrder[j].ChainId + }) - require.Empty(t, result, "initial result not empty") - require.Len(t, chainIDs, 2, "initial chainIDs not len 2") - - // iterate and check all chains are returned - pk.IterateConsumerChains(ctx, testIterateAll) - require.Len(t, result, 2, "wrong result len - should be 2, got %d", len(result)) - require.Contains(t, result, chainIDs[0], "result does not contain '%s'", chainIDs[0]) - require.Contains(t, result, chainIDs[1], "result does not contain '%s'", chainIDs[1]) - - result = []string{} - testGetFirst := func(ctx sdk.Context, chainID, clientID string) (stop bool) { - result = append(result, chainID) - return true // will stop iteration after iterating 1 element - } - require.Empty(t, result, "initial result not empty") - // iterate and check first chain is - pk.IterateConsumerChains(ctx, testGetFirst) - require.Len(t, result, 1, "wrong result len - should be 1, got %d", len(result)) - require.Contains(t, result, chainIDs[0], "result does not contain '%s'", chainIDs[0]) - require.NotContains(t, result, chainIDs[1], "result should not contain '%s'", chainIDs[1]) + result := pk.GetAllConsumerChains(ctx) + require.Len(t, result, len(chainIDs)) + require.Equal(t, expectedGetAllOrder, result) } -// TestIterateConsumerChains tests IterateConsumerChains behaviour correctness -func TestIterateChannelToChain(t *testing.T) { +// TestGetAllChannelToChains tests GetAllChannelToChains behaviour correctness +func TestGetAllChannelToChains(t *testing.T) { pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - type chanToChain struct { - chainID string - channelID string - } - - cases := []chanToChain{ - { - chainID: "chain-1", - channelID: "channel-1", - }, - { - chainID: "chain-2", - channelID: "channel-2", - }, - } - - for _, c := range cases { - pk.SetChannelToChain(ctx, c.channelID, c.chainID) - } - - result := []chanToChain{} - testIterateAll := func(ctx sdk.Context, channelID, chainID string) (stop bool) { - result = append(result, chanToChain{ - chainID: chainID, - channelID: channelID, - }) - return false // will not stop iteration - } - - require.Empty(t, result, "initial result not empty") - - // iterate and check all results are returned - pk.IterateChannelToChain(ctx, testIterateAll) - require.Len(t, result, 2, "wrong result len - should be 2, got %d", len(result)) - require.Contains(t, result, cases[0], "result does not contain '%s'", cases[0]) - require.Contains(t, result, cases[1], "result does not contain '%s'", cases[1]) - - result = []chanToChain{} - testGetFirst := func(ctx sdk.Context, channelID, chainID string) (stop bool) { - result = append(result, chanToChain{ - chainID: chainID, - channelID: channelID, - }) - return true // will stop iteration + chainIDs := []string{"chain-2", "chain-1", "chain-4", "chain-3"} + expectedGetAllOrder := []types.ChannelToChain{} + for i, chainID := range chainIDs { + channelID := fmt.Sprintf("client-%d", len(chainIDs)-i) + pk.SetChannelToChain(ctx, channelID, chainID) + expectedGetAllOrder = append(expectedGetAllOrder, types.ChannelToChain{ChainId: chainID, ChannelId: channelID}) } + // sorting by channelID + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].ChannelId < expectedGetAllOrder[j].ChannelId + }) - require.Empty(t, result, "initial result not empty") - // iterate and check 1 result is returned - pk.IterateChannelToChain(ctx, testGetFirst) - require.Len(t, result, 1, "wrong result len - should be 1, got %d", len(result)) - require.Contains(t, result, cases[0], "result does not contain '%s'", cases[0]) - require.NotContains(t, result, cases[1], "result should not contain '%s'", cases[1]) + result := pk.GetAllChannelToChains(ctx) + require.Len(t, result, len(chainIDs)) + require.Equal(t, expectedGetAllOrder, result) } -// IterateOverUnbondingOps tests IterateOverUnbondingOps behaviour correctness -func TestIterateOverUnbondingOps(t *testing.T) { +// TestGetAllUnbondingOps tests GetAllUnbondingOps behaviour correctness +func TestGetAllUnbondingOps(t *testing.T) { pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - ops := []ccv.UnbondingOp{ + ops := []types.UnbondingOp{ + { + Id: 2, + UnbondingConsumerChains: []string{"chain-2", "chain-1"}, + }, { Id: 1, - UnbondingConsumerChains: []string{"test"}, + UnbondingConsumerChains: []string{"chain-1", "chain-2"}, }, { - Id: 2, - UnbondingConsumerChains: []string{"test"}, + Id: 4, + UnbondingConsumerChains: []string{"chain-2"}, + }, + { + Id: 3, + UnbondingConsumerChains: []string{"chain-3", "chain-1", "chain-2"}, }, } + expectedGetAllOrder := ops + // sorting by Id + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].Id < expectedGetAllOrder[j].Id + }) for _, op := range ops { pk.SetUnbondingOp(ctx, op) } - result := []ccv.UnbondingOp{} - testIterateAll := func(id uint64, ubdOp ccv.UnbondingOp) (stop bool) { - result = append(result, ubdOp) - return false // will not stop iteration - } - - require.Empty(t, result, "initial result not empty") - // iterate and check all results are returned - pk.IterateOverUnbondingOps(ctx, testIterateAll) - require.Len(t, result, 2, "wrong result len - should be 2, got %d", len(result)) - require.Contains(t, result, ops[0], "result does not contain '%s'", ops[0]) - require.Contains(t, result, ops[1], "result does not contain '%s'", ops[1]) - - result = []ccv.UnbondingOp{} - testGetFirst := func(id uint64, ubdOp ccv.UnbondingOp) (stop bool) { - result = append(result, ubdOp) - return true // will stop iteration - } - - require.Empty(t, result, "initial result not empty") - // iterate and check 1 result is returned - pk.IterateOverUnbondingOps(ctx, testGetFirst) - require.Len(t, result, 1, "wrong result len - should be 1, got %d", len(result)) - require.Contains(t, result, ops[0], "result does not contain '%s'", ops[0]) - require.NotContains(t, result, ops[1], "result should not contain '%s'", ops[1]) + result := pk.GetAllUnbondingOps(ctx) + require.Len(t, result, len(ops)) + require.Equal(t, expectedGetAllOrder, result) } diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index 0c4f7f4c7a..07aff19d0b 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -45,58 +45,45 @@ func (k Keeper) SetValidatorConsumerPubKey( store.Set(types.ConsumerValidatorsKey(chainID, providerAddr), bz) } -// IterateValidatorConsumerPubKeys iterates over the validators public keys assigned for a consumer chain -func (k Keeper) IterateValidatorConsumerPubKeys( - ctx sdk.Context, - chainID string, - cb func(providerAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool), -) { +// GetAllValidatorConsumerPubKeys gets all the validators public keys assigned for a consumer chain +// If chainID is nil, it returns all the validators public keys assigned for all consumer chains +// +// Note that the validators public keys assigned for a consumer chain are stored under keys +// with the following format: UnbondingOpIndexBytePrefix | len(chainID) | chainID | providerAddress +// Thus, the returned array is +// - in ascending order of providerAddresses, if chainID is not nil; +// - in undetermined order, if chainID is nil. +func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) (validatorConsumerPubKeys []types.ValidatorConsumerPubKey) { store := ctx.KVStore(k.storeKey) - prefix := types.ChainIdWithLenKey(types.ConsumerValidatorsBytePrefix, chainID) - iter := sdk.KVStorePrefixIterator(store, prefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - _, providerAddr, err := types.ParseChainIdAndConsAddrKey(types.ConsumerValidatorsBytePrefix, iter.Key()) - if err != nil { - panic(err) - } - var consumerKey tmprotocrypto.PublicKey - err = consumerKey.Unmarshal(iter.Value()) - if err != nil { - panic(err) - } - stop := cb(providerAddr, consumerKey) - if stop { - break - } + var prefix []byte + if chainID == nil { + // iterate over the validators public keys assigned for all consumer chains + prefix = []byte{types.ConsumerValidatorsBytePrefix} + } else { + // iterate over the validators public keys assigned for chainID + prefix = types.ChainIdWithLenKey(types.ConsumerValidatorsBytePrefix, *chainID) } -} - -// IterateAllValidatorConsumerPubKeys iterates over the validators public keys assigned for all consumer chain. -// Note that IterateValidatorConsumerPubKeys cannot be used as consumer keys can be assigned for chain IDs -// that are not yet known to the provider. -func (k Keeper) IterateAllValidatorConsumerPubKeys( - ctx sdk.Context, - cb func(chainID string, providerAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool), -) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, []byte{types.ConsumerValidatorsBytePrefix}) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - chainID, providerAddr, err := types.ParseChainIdAndConsAddrKey(types.ConsumerValidatorsBytePrefix, iter.Key()) + iterator := sdk.KVStorePrefixIterator(store, prefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + chainID, providerAddr, err := types.ParseChainIdAndConsAddrKey(types.ConsumerValidatorsBytePrefix, iterator.Key()) if err != nil { panic(err) } var consumerKey tmprotocrypto.PublicKey - err = consumerKey.Unmarshal(iter.Value()) + err = consumerKey.Unmarshal(iterator.Value()) if err != nil { panic(err) } - stop := cb(chainID, providerAddr, consumerKey) - if stop { - break - } + + validatorConsumerPubKeys = append(validatorConsumerPubKeys, types.ValidatorConsumerPubKey{ + ChainId: chainID, + ProviderAddr: providerAddr, + ConsumerKey: &consumerKey, + }) } + + return validatorConsumerPubKeys } // DeleteValidatorConsumerPubKey deletes a validator's public key assigned for a consumer chain @@ -140,60 +127,46 @@ func (k Keeper) SetValidatorByConsumerAddr( store.Set(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr), bz) } -// IterateValidatorsByConsumerAddr iterates over all the mappings from consensus addresses -// on a given consumer chain to consensus addresses on the provider chain -func (k Keeper) IterateValidatorsByConsumerAddr( - ctx sdk.Context, - chainID string, - cb func(consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool), -) { +// GetValidatorsByConsumerAddrs gets all the mappings from consensus addresses +// on a given consumer chain to consensus addresses on the provider chain. +// If chainID is nil, it returns all the mappings from consensus addresses on all consumer chains. +// +// Note that the mappings for a consumer chain are stored under keys with the following format: +// ValidatorsByConsumerAddrBytePrefix | len(chainID) | chainID | consumerAddress +// Thus, the returned array is +// - in ascending order of consumerAddresses, if chainID is not nil; +// - in undetermined order, if chainID is nil. +func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) (validatorConsumerAddrs []types.ValidatorByConsumerAddr) { store := ctx.KVStore(k.storeKey) - prefix := types.ChainIdWithLenKey(types.ValidatorsByConsumerAddrBytePrefix, chainID) - iter := sdk.KVStorePrefixIterator(store, prefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - _, consumerAddr, err := types.ParseChainIdAndConsAddrKey(types.ValidatorsByConsumerAddrBytePrefix, iter.Key()) - if err != nil { - panic(err) - } - var providerAddr sdk.ConsAddress - err = providerAddr.Unmarshal(iter.Value()) - if err != nil { - panic(err) - } - stop := cb(consumerAddr, providerAddr) - if stop { - break - } + var prefix []byte + if chainID == nil { + // iterate over the mappings from consensus addresses on all consumer chains + prefix = []byte{types.ValidatorsByConsumerAddrBytePrefix} + } else { + // iterate over the mappings from consensus addresses on chainID + prefix = types.ChainIdWithLenKey(types.ValidatorsByConsumerAddrBytePrefix, *chainID) } -} - -// IterateAllValidatorsByConsumerAddr iterates over all the mappings from consensus addresses -// on any consumer chain to consensus addresses on the provider chain. -// Note that IterateValidatorsByConsumerAddr cannot be used as consumer keys can be assigned -// for chain IDs that are not yet known to the provider. -func (k Keeper) IterateAllValidatorsByConsumerAddr( - ctx sdk.Context, - cb func(chainID string, consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool), -) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, []byte{types.ValidatorsByConsumerAddrBytePrefix}) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - chainID, consumerAddr, err := types.ParseChainIdAndConsAddrKey(types.ValidatorsByConsumerAddrBytePrefix, iter.Key()) + iterator := sdk.KVStorePrefixIterator(store, prefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + chainID, consumerAddr, err := types.ParseChainIdAndConsAddrKey(types.ValidatorsByConsumerAddrBytePrefix, iterator.Key()) if err != nil { panic(err) } var providerAddr sdk.ConsAddress - err = providerAddr.Unmarshal(iter.Value()) + err = providerAddr.Unmarshal(iterator.Value()) if err != nil { panic(err) } - stop := cb(chainID, consumerAddr, providerAddr) - if stop { - break - } + + validatorConsumerAddrs = append(validatorConsumerAddrs, types.ValidatorByConsumerAddr{ + ConsumerAddr: consumerAddr, + ProviderAddr: providerAddr, + ChainId: chainID, + }) } + + return validatorConsumerAddrs } // DeleteValidatorByConsumerAddr deletes the mapping from a validator's consensus address on a consumer @@ -244,13 +217,13 @@ func (k Keeper) SetKeyAssignmentReplacement( store.Set(types.KeyAssignmentReplacementsKey(chainID, providerAddr), bz) } -// IterateKeyAssignmentReplacements iterates through all pairs of previous assigned consumer keys +// GetAllKeyAssignmentReplacements gets all pairs of previous assigned consumer keys // and current powers for all provider validator for which key assignments were received in this block. -func (k Keeper) IterateKeyAssignmentReplacements( - ctx sdk.Context, - chainID string, - cb func(providerAddr sdk.ConsAddress, prevCKey tmprotocrypto.PublicKey, power int64) (stop bool), -) { +// +// Note that the pairs are stored under keys with the following format: +// KeyAssignmentReplacementsBytePrefix | len(chainID) | chainID | providerAddress +// Thus, the iteration is in ascending order of providerAddresses. +func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) (replacements []types.KeyAssignmentReplacement) { store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.KeyAssignmentReplacementsBytePrefix, chainID) iterator := sdk.KVStorePrefixIterator(store, iteratorPrefix) @@ -265,11 +238,15 @@ func (k Keeper) IterateKeyAssignmentReplacements( if err != nil { panic(err) } - stop := cb(providerAddr, pubKeyAndPower.PubKey, pubKeyAndPower.Power) - if stop { - break - } + + replacements = append(replacements, types.KeyAssignmentReplacement{ + ProviderAddr: providerAddr, + PrevCKey: &pubKeyAndPower.PubKey, + Power: pubKeyAndPower.Power, + }) } + + return replacements } // DeleteKeyAssignmentReplacement deletes the previous assigned consumer key and the current power @@ -325,11 +302,12 @@ func (k Keeper) GetConsumerAddrsToPrune( return } -func (k Keeper) IterateConsumerAddrsToPrune( - ctx sdk.Context, - chainID string, - cb func(vscID uint64, consumerAddrsToPrune types.AddressList) (stop bool), -) { +// GetAllConsumerAddrsToPrune gets all consumer addresses that can be pruned for a given chainID. +// +// Note that the list of all consumer addresses is stored under keys with the following format: +// ConsumerAddrsToPruneBytePrefix | len(chainID) | chainID | vscID +// Thus, the returned array is in ascending order of vscIDs. +func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (consumerAddrsToPrune []types.ConsumerAddrsToPrune) { store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.ConsumerAddrsToPruneBytePrefix, chainID) iterator := sdk.KVStorePrefixIterator(store, iteratorPrefix) @@ -339,16 +317,20 @@ func (k Keeper) IterateConsumerAddrsToPrune( if err != nil { panic(err) } - var consumerAddrsToPrune types.AddressList - err = consumerAddrsToPrune.Unmarshal(iterator.Value()) + var addrs types.AddressList + err = addrs.Unmarshal(iterator.Value()) if err != nil { panic(err) } - stop := cb(vscID, consumerAddrsToPrune) - if stop { - break - } + + consumerAddrsToPrune = append(consumerAddrsToPrune, types.ConsumerAddrsToPrune{ + VscId: vscID, + ConsumerAddrs: &addrs, + ChainId: chainID, + }) } + + return consumerAddrsToPrune } // DeleteConsumerAddrsToPrune deletes the list of consumer addresses mapped to a given VSC ID @@ -514,37 +496,21 @@ func (k Keeper) ApplyKeyAssignmentToValUpdates( // For any key assignment replacements that did not have a corresponding validator update already, // set the old consumer key's power to 0 and the new consumer key's power to the // power in the pending key assignment. - var addrToRemove []sdk.ConsAddress - k.IterateKeyAssignmentReplacements(ctx, chainID, func( - pAddr sdk.ConsAddress, - prevCKey tmprotocrypto.PublicKey, - power int64, - ) (stop bool) { - addrToRemove = append(addrToRemove, pAddr) + for _, replacement := range k.GetAllKeyAssignmentReplacements(ctx, chainID) { + k.DeleteKeyAssignmentReplacement(ctx, chainID, replacement.ProviderAddr) newUpdates = append(newUpdates, abci.ValidatorUpdate{ - PubKey: prevCKey, + PubKey: *replacement.PrevCKey, Power: 0, }) - newConsumerKey, found := k.GetValidatorConsumerPubKey(ctx, chainID, pAddr) + newConsumerKey, found := k.GetValidatorConsumerPubKey(ctx, chainID, replacement.ProviderAddr) if !found { - err = sdkerrors.Wrapf(types.ErrConsumerKeyNotFound, "consumer key not found for %s", pAddr) - return true + return newUpdates, sdkerrors.Wrapf(types.ErrConsumerKeyNotFound, "consumer key not found for %s", replacement.ProviderAddr) } newUpdates = append(newUpdates, abci.ValidatorUpdate{ PubKey: newConsumerKey, - Power: power, + Power: replacement.Power, }) - - return false - }) - if err != nil { - return newUpdates, err - } - - // Remove the key assignment replacements - for _, addr := range addrToRemove { - k.DeleteKeyAssignmentReplacement(ctx, chainID, addr) } return newUpdates, nil @@ -577,39 +543,22 @@ func (k Keeper) PruneKeyAssignments(ctx sdk.Context, chainID string, vscID uint6 // DeleteKeyAssignments deletes all the state needed for key assignments on a consumer chain func (k Keeper) DeleteKeyAssignments(ctx sdk.Context, chainID string) { // delete ValidatorConsumerPubKey - var addrs []sdk.ConsAddress - k.IterateValidatorConsumerPubKeys(ctx, chainID, func(providerAddr sdk.ConsAddress, _ tmprotocrypto.PublicKey) (stop bool) { - addrs = append(addrs, providerAddr) - return false // do not stop the iteration - }) - for _, addr := range addrs { - k.DeleteValidatorConsumerPubKey(ctx, chainID, addr) + for _, validatorConsumerAddr := range k.GetAllValidatorConsumerPubKeys(ctx, &chainID) { + k.DeleteValidatorConsumerPubKey(ctx, chainID, validatorConsumerAddr.ProviderAddr) } + // delete ValidatorsByConsumerAddr - addrs = nil - k.IterateValidatorsByConsumerAddr(ctx, chainID, func(consumerAddr sdk.ConsAddress, _ sdk.ConsAddress) (stop bool) { - addrs = append(addrs, consumerAddr) - return false // do not stop the iteration - }) - for _, addr := range addrs { - k.DeleteValidatorByConsumerAddr(ctx, chainID, addr) + for _, validatorConsumerAddr := range k.GetAllValidatorsByConsumerAddr(ctx, &chainID) { + k.DeleteValidatorByConsumerAddr(ctx, chainID, validatorConsumerAddr.ConsumerAddr) } + // delete KeyAssignmentReplacements - addrs = nil - k.IterateKeyAssignmentReplacements(ctx, chainID, func(providerAddr sdk.ConsAddress, _ tmprotocrypto.PublicKey, _ int64) (stop bool) { - addrs = append(addrs, providerAddr) - return false // do not stop the iteration - }) - for _, addr := range addrs { - k.DeleteKeyAssignmentReplacement(ctx, chainID, addr) + for _, keyAssignmentReplacement := range k.GetAllKeyAssignmentReplacements(ctx, chainID) { + k.DeleteKeyAssignmentReplacement(ctx, chainID, keyAssignmentReplacement.ProviderAddr) } + // delete ValidatorConsumerPubKey - var ids []uint64 - k.IterateConsumerAddrsToPrune(ctx, chainID, func(vscID uint64, _ types.AddressList) (stop bool) { - ids = append(ids, vscID) - return false // do not stop the iteration - }) - for _, id := range ids { - k.DeleteConsumerAddrsToPrune(ctx, chainID, id) + for _, consumerAddrsToPrune := range k.GetAllConsumerAddrsToPrune(ctx, chainID) { + k.DeleteConsumerAddrsToPrune(ctx, chainID, consumerAddrsToPrune.VscId) } } diff --git a/x/ccv/provider/keeper/key_assignment_test.go b/x/ccv/provider/keeper/key_assignment_test.go index 0bcd00b81e..e441d60fe2 100644 --- a/x/ccv/provider/keeper/key_assignment_test.go +++ b/x/ccv/provider/keeper/key_assignment_test.go @@ -1,7 +1,10 @@ package keeper_test import ( + "bytes" + "sort" "testing" + "time" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -14,19 +17,11 @@ import ( "math/rand" providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + "github.com/cosmos/interchain-security/x/ccv/provider/types" "github.com/cosmos/interchain-security/x/ccv/utils" "github.com/golang/mock/gomock" ) -type testAssignment struct { - chainID string - providerAddr sdk.ConsAddress - consumerAddr sdk.ConsAddress - consumerPubKey tmprotocrypto.PublicKey - pubKeyAndPower abci.ValidatorUpdate -} - func TestValidatorConsumerPubKeyCRUD(t *testing.T) { chainID := "consumer" providerAddr := sdk.ConsAddress([]byte("providerAddr")) @@ -49,123 +44,59 @@ func TestValidatorConsumerPubKeyCRUD(t *testing.T) { require.NotEqual(t, consumerPubKey, consumerKey) } -func TestIterateValidatorConsumerPubKeys(t *testing.T) { - - chainID := "consumer" - testAssignments := []testAssignment{ - { - providerAddr: sdk.ConsAddress([]byte("validator-1")), - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(1).TMProtoCryptoPublicKey(), - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-2")), - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(2).TMProtoCryptoPublicKey(), - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-3")), - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(3).TMProtoCryptoPublicKey(), - }, - } - - keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +func TestGetAllValidatorConsumerPubKey(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - for _, assignment := range testAssignments { - keeper.SetValidatorConsumerPubKey(ctx, chainID, assignment.providerAddr, assignment.consumerPubKey) - } - - result := []testAssignment{} - cbIterateAll := func(iteratorProviderAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool) { - result = append(result, testAssignment{ - providerAddr: iteratorProviderAddr, - consumerPubKey: consumerKey, - }) - return false - } - - keeper.IterateValidatorConsumerPubKeys(ctx, chainID, cbIterateAll) - require.Len(t, result, len(testAssignments), "incorrect result len - should be %d, got %d", len(testAssignments), len(result)) - - for i, res := range result { - require.Equal(t, testAssignments[i], res, "mismatched consumer key assignment in case %d", i) - } - - result = []testAssignment{} - cbIterateOne := func(iteratorProviderAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool) { - result = append(result, testAssignment{ - providerAddr: iteratorProviderAddr, - consumerPubKey: consumerKey, - }) - return true + rand.Seed(time.Now().Unix()) + chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"} + numAssignments := 10 + testAssignments := []types.ValidatorConsumerPubKey{} + for i := 0; i < numAssignments; i++ { + consumerKey := cryptotestutil.NewCryptoIdentityFromIntSeed(i).TMProtoCryptoPublicKey() + providerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(numAssignments + i).SDKConsAddress() + testAssignments = append(testAssignments, + types.ValidatorConsumerPubKey{ + ChainId: chainIDs[rand.Intn(len(chainIDs))], + ProviderAddr: providerAddr, + ConsumerKey: &consumerKey, + }, + ) } - - keeper.IterateValidatorConsumerPubKeys(ctx, chainID, cbIterateOne) - require.Len(t, result, 1, "incorrect result len - should be 1, got %d", len(result)) - - require.Equal(t, testAssignments[0], result[0], "mismatched consumer key assignment in iterate one") - -} - -func TestIterateAllValidatorConsumerPubKeys(t *testing.T) { - providerAddr := sdk.ConsAddress([]byte("validator-1")) - testAssignments := []testAssignment{ - { - chainID: "consumer-1", - providerAddr: providerAddr, - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(1).TMProtoCryptoPublicKey(), - }, - { - chainID: "consumer-2", - providerAddr: providerAddr, - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(2).TMProtoCryptoPublicKey(), - }, - { - chainID: "consumer-3", - providerAddr: providerAddr, - consumerPubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(3).TMProtoCryptoPublicKey(), - }, + // select a chainID with more than two assignments + var chainID string + for i := range chainIDs { + chainID = chainIDs[i] + count := 0 + for _, assignment := range testAssignments { + if assignment.ChainId == chainID { + count++ + } + } + if count > 2 { + break + } } - - keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - + expectedGetAllOneConsumerOrder := []types.ValidatorConsumerPubKey{} for _, assignment := range testAssignments { - keeper.SetValidatorConsumerPubKey(ctx, assignment.chainID, assignment.providerAddr, assignment.consumerPubKey) - } - - result := []testAssignment{} - cbIterateAll := func(chainID string, iteratorProviderAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool) { - require.Equal(t, providerAddr, iteratorProviderAddr, "unexpected provider address in iterator - expecting just 1 provider address") - result = append(result, testAssignment{ - chainID: chainID, - providerAddr: iteratorProviderAddr, - consumerPubKey: consumerKey, - }) - return false - } - - keeper.IterateAllValidatorConsumerPubKeys(ctx, cbIterateAll) - require.Len(t, result, len(testAssignments), "incorrect result len - should be %d, got %d", len(testAssignments), len(result)) - - for i, res := range result { - require.Equal(t, testAssignments[i], res, "mismatched consumer key assignment in case %d", i) + if assignment.ChainId == chainID { + expectedGetAllOneConsumerOrder = append(expectedGetAllOneConsumerOrder, assignment) + } } + // sorting by ValidatorConsumerPubKey.ProviderAddr + sort.Slice(expectedGetAllOneConsumerOrder, func(i, j int) bool { + return bytes.Compare(expectedGetAllOneConsumerOrder[i].ProviderAddr, expectedGetAllOneConsumerOrder[j].ProviderAddr) == -1 + }) - result = []testAssignment{} - cbIterateOne := func(chainID string, iteratorProviderAddr sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool) { - require.Equal(t, providerAddr, iteratorProviderAddr, "unexpected provider address in iterator - expecting just 1 provider address") - result = append(result, testAssignment{ - chainID: chainID, - providerAddr: iteratorProviderAddr, - consumerPubKey: consumerKey, - }) - return false + for _, assignment := range testAssignments { + pk.SetValidatorConsumerPubKey(ctx, assignment.ChainId, assignment.ProviderAddr, *assignment.ConsumerKey) } - keeper.IterateAllValidatorConsumerPubKeys(ctx, cbIterateOne) - require.Len(t, result, len(testAssignments), "incorrect result len - should be 1, got %d", len(result)) + result := pk.GetAllValidatorConsumerPubKeys(ctx, &chainID) + require.Equal(t, expectedGetAllOneConsumerOrder, result) - require.Equal(t, testAssignments[0], result[0], "mismatched consumer key assignment in iterate one") + result = pk.GetAllValidatorConsumerPubKeys(ctx, nil) + require.Len(t, result, len(testAssignments)) } func TestValidatorByConsumerAddrCRUD(t *testing.T) { @@ -190,120 +121,59 @@ func TestValidatorByConsumerAddrCRUD(t *testing.T) { require.NotEqual(t, providerAddr, providerAddrResult) } -func TestIterateValidatorsByConsumerAddr(t *testing.T) { - chainID := "consumer" - testAssignments := []testAssignment{ - { - providerAddr: sdk.ConsAddress([]byte("validator-1")), - consumerAddr: sdk.ConsAddress([]byte("consumer-1")), - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-2")), - consumerAddr: sdk.ConsAddress([]byte("consumer-2")), - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-3")), - consumerAddr: sdk.ConsAddress([]byte("consumer-3")), - }, - } - - keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +func TestGetAllValidatorsByConsumerAddr(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - for _, assignment := range testAssignments { - keeper.SetValidatorByConsumerAddr(ctx, chainID, assignment.consumerAddr, assignment.providerAddr) - } - - result := []testAssignment{} - cbIterateAll := func(consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - result = append(result, testAssignment{ - providerAddr: providerAddr, - consumerAddr: consumerAddr, - }) - return false // continue iteration - } - - keeper.IterateValidatorsByConsumerAddr(ctx, chainID, cbIterateAll) - require.Len(t, result, len(testAssignments), "incorrect result len - should be %d, got %d", len(testAssignments), len(result)) - - for i, res := range result { - require.Equal(t, testAssignments[i], res, "mismatched consumer address assignment in case %d", i) - } - - result = []testAssignment{} - cbIterateOne := func(consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - result = append(result, testAssignment{ - providerAddr: providerAddr, - consumerAddr: consumerAddr, - }) - return true // stop after first + rand.Seed(time.Now().Unix()) + chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"} + numAssignments := 10 + testAssignments := []types.ValidatorByConsumerAddr{} + for i := 0; i < numAssignments; i++ { + consumerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(i).SDKConsAddress() + providerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(numAssignments + i).SDKConsAddress() + testAssignments = append(testAssignments, + types.ValidatorByConsumerAddr{ + ChainId: chainIDs[rand.Intn(len(chainIDs))], + ConsumerAddr: consumerAddr, + ProviderAddr: providerAddr, + }, + ) } - - keeper.IterateValidatorsByConsumerAddr(ctx, chainID, cbIterateOne) - require.Len(t, result, 1, "incorrect result len - should be 1, got %d", len(result)) - - require.Equal(t, testAssignments[0], result[0], "mismatched consumer address assignment in iterate one") -} - -func TestIterateAllValidatorsByConsumerAddr(t *testing.T) { - providerAddr := sdk.ConsAddress([]byte("validator-1")) - testAssignments := []testAssignment{ - { - chainID: "consumer-1", - providerAddr: providerAddr, - consumerAddr: sdk.ConsAddress([]byte("consumer-1")), - }, - { - chainID: "consumer-2", - providerAddr: providerAddr, - consumerAddr: sdk.ConsAddress([]byte("consumer-2")), - }, - { - chainID: "consumer-3", - providerAddr: providerAddr, - consumerAddr: sdk.ConsAddress([]byte("consumer-3")), - }, + // select a chainID with more than two assignments + var chainID string + for i := range chainIDs { + chainID = chainIDs[i] + count := 0 + for _, assignment := range testAssignments { + if assignment.ChainId == chainID { + count++ + } + } + if count > 2 { + break + } } - - keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - + expectedGetAllOneConsumerOrder := []types.ValidatorByConsumerAddr{} for _, assignment := range testAssignments { - keeper.SetValidatorByConsumerAddr(ctx, assignment.chainID, assignment.consumerAddr, assignment.providerAddr) - } - - result := []testAssignment{} - cbIterateAll := func(chainID string, consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - result = append(result, testAssignment{ - chainID: chainID, - providerAddr: providerAddr, - consumerAddr: consumerAddr, - }) - return false // continue iteration - } - - keeper.IterateAllValidatorsByConsumerAddr(ctx, cbIterateAll) - require.Len(t, result, len(testAssignments), "incorrect result len - should be %d, got %d", len(testAssignments), len(result)) - - for i, res := range result { - require.Equal(t, testAssignments[i], res, "mismatched consumer address assignment in case %d", i) + if assignment.ChainId == chainID { + expectedGetAllOneConsumerOrder = append(expectedGetAllOneConsumerOrder, assignment) + } } + // sorting by ValidatorByConsumerAddr.ConsumerAddr + sort.Slice(expectedGetAllOneConsumerOrder, func(i, j int) bool { + return bytes.Compare(expectedGetAllOneConsumerOrder[i].ConsumerAddr, expectedGetAllOneConsumerOrder[j].ConsumerAddr) == -1 + }) - result = []testAssignment{} - cbIterateOne := func(chainID string, consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - result = append(result, testAssignment{ - chainID: chainID, - - providerAddr: providerAddr, - consumerAddr: consumerAddr, - }) - return true // stop after first + for _, assignment := range testAssignments { + pk.SetValidatorByConsumerAddr(ctx, assignment.ChainId, assignment.ConsumerAddr, assignment.ProviderAddr) } - keeper.IterateAllValidatorsByConsumerAddr(ctx, cbIterateOne) - require.Len(t, result, 1, "incorrect result len - should be 1, got %d", len(result)) + result := pk.GetAllValidatorsByConsumerAddr(ctx, &chainID) + require.Equal(t, expectedGetAllOneConsumerOrder, result) - require.Equal(t, testAssignments[0], result[0], "mismatched consumer address assignment in iterate one") + result = pk.GetAllValidatorsByConsumerAddr(ctx, nil) + require.Len(t, result, len(testAssignments)) } func TestKeyAssignmentReplacementCRUD(t *testing.T) { @@ -327,68 +197,40 @@ func TestKeyAssignmentReplacementCRUD(t *testing.T) { require.False(t, found, "key assignment replacement found") } -func TestIterateKeyAssignmentReplacements(t *testing.T) { - chainID := "consumer" - testAssignments := []testAssignment{ - { - providerAddr: sdk.ConsAddress([]byte("validator-1")), - pubKeyAndPower: abci.ValidatorUpdate{ - Power: 100, - PubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(1).TMProtoCryptoPublicKey(), - }, - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-2")), - pubKeyAndPower: abci.ValidatorUpdate{ - Power: 100, - PubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(2).TMProtoCryptoPublicKey(), - }, - }, - { - providerAddr: sdk.ConsAddress([]byte("validator-3")), - pubKeyAndPower: abci.ValidatorUpdate{ - Power: 100, - PubKey: cryptotestutil.NewCryptoIdentityFromIntSeed(3).TMProtoCryptoPublicKey(), - }, - }, - } - - keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +func TestGetAllKeyAssignmentReplacements(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - for _, assignment := range testAssignments { - keeper.SetKeyAssignmentReplacement(ctx, chainID, assignment.providerAddr, assignment.pubKeyAndPower.PubKey, assignment.pubKeyAndPower.Power) - } - - result := []testAssignment{} - cbIterateAll := func(providerAddr sdk.ConsAddress, prevCKey tmprotocrypto.PublicKey, power int64) (stop bool) { - result = append(result, testAssignment{ - providerAddr: providerAddr, - pubKeyAndPower: abci.ValidatorUpdate{PubKey: prevCKey, Power: power}, - }) - return false // continue iteration - } - - keeper.IterateKeyAssignmentReplacements(ctx, chainID, cbIterateAll) - require.Len(t, result, len(testAssignments), "incorrect result len - should be %d, got %d", len(testAssignments), len(result)) - - for i, res := range result { - require.Equal(t, testAssignments[i], res, "mismatched key assignment replacement in case %d", i) + chainID := "consumer-1" + + rand.Seed(time.Now().Unix()) + numAssignments := 10 + testAssignments := []types.KeyAssignmentReplacement{} + for i := 0; i < numAssignments; i++ { + consumerKey := cryptotestutil.NewCryptoIdentityFromIntSeed(i).TMProtoCryptoPublicKey() + providerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(numAssignments + i).SDKConsAddress() + testAssignments = append(testAssignments, + types.KeyAssignmentReplacement{ + ProviderAddr: providerAddr, + PrevCKey: &consumerKey, + Power: rand.Int63(), + }, + ) } + expectedGetAllOrder := testAssignments + // sorting by KeyAssignmentReplacement.ProviderAddr + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return bytes.Compare(expectedGetAllOrder[i].ProviderAddr, expectedGetAllOrder[j].ProviderAddr) == -1 + }) - result = []testAssignment{} - cbIterateOne := func(providerAddr sdk.ConsAddress, prevCKey tmprotocrypto.PublicKey, power int64) (stop bool) { - result = append(result, testAssignment{ - providerAddr: providerAddr, - pubKeyAndPower: abci.ValidatorUpdate{PubKey: prevCKey, Power: power}, - }) - return true // stop after first + pk.SetKeyAssignmentReplacement(ctx, "consumer-2", testAssignments[0].ProviderAddr, *testAssignments[0].PrevCKey, testAssignments[0].Power) + for _, assignment := range testAssignments { + pk.SetKeyAssignmentReplacement(ctx, chainID, assignment.ProviderAddr, *assignment.PrevCKey, assignment.Power) } - keeper.IterateKeyAssignmentReplacements(ctx, chainID, cbIterateOne) - require.Len(t, result, 1, "incorrect result len - should be 1, got %d", len(result)) - - require.Equal(t, testAssignments[0], result[0], "mismatched key assignment replacement in iterate one") + result := pk.GetAllKeyAssignmentReplacements(ctx, chainID) + require.Len(t, result, len(testAssignments)) + require.Equal(t, expectedGetAllOrder, result) } func TestConsumerAddrsToPruneCRUD(t *testing.T) { @@ -411,6 +253,63 @@ func TestConsumerAddrsToPruneCRUD(t *testing.T) { require.Empty(t, addrToPrune, "address to prune was returned") } +func TestGetAllConsumerAddrsToPrune(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + rand.Seed(time.Now().Unix()) + chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"} + numAssignments := 10 + testAssignments := []types.ConsumerAddrsToPrune{} + for i := 0; i < numAssignments; i++ { + consumerAddresses := types.AddressList{} + for j := 0; j < 2*(i+1); j++ { + consumerAddresses.Addresses = append(consumerAddresses.Addresses, + cryptotestutil.NewCryptoIdentityFromIntSeed(i*j).SDKConsAddress()) + } + testAssignments = append(testAssignments, + types.ConsumerAddrsToPrune{ + ChainId: chainIDs[rand.Intn(len(chainIDs))], + VscId: rand.Uint64(), + ConsumerAddrs: &consumerAddresses, + }, + ) + } + // select a chainID with more than two assignments + var chainID string + for i := range chainIDs { + chainID = chainIDs[i] + count := 0 + for _, assignment := range testAssignments { + if assignment.ChainId == chainID { + count++ + } + } + if count > 2 { + break + } + } + expectedGetAllOrder := []types.ConsumerAddrsToPrune{} + for _, assignment := range testAssignments { + if assignment.ChainId == chainID { + expectedGetAllOrder = append(expectedGetAllOrder, assignment) + } + } + // sorting by ConsumerAddrsToPrune.VscId + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + return expectedGetAllOrder[i].VscId < expectedGetAllOrder[j].VscId + }) + + for _, assignment := range testAssignments { + for _, addr := range assignment.ConsumerAddrs.Addresses { + pk.AppendConsumerAddrsToPrune(ctx, assignment.ChainId, assignment.VscId, addr) + } + } + + result := pk.GetAllConsumerAddrsToPrune(ctx, chainID) + require.Equal(t, expectedGetAllOrder, result) +} + // checkCorrectPruningProperty checks that the pruning property is correct for a given // consumer chain. See AppendConsumerAddrsToPrune for a formulation of the property. func checkCorrectPruningProperty(ctx sdk.Context, k providerkeeper.Keeper, chainID string) bool { @@ -421,37 +320,35 @@ func checkCorrectPruningProperty(ctx sdk.Context, k providerkeeper.Keeper, chain - or there exists a vscID in ConsumerAddrsToPrune s.t. cAddr in ConsumerAddrsToPrune(vscID) */ willBePruned := map[string]bool{} - k.IterateConsumerAddrsToPrune(ctx, chainID, func(vscID uint64, addrList providertypes.AddressList) (stop bool) { - for _, cAddr := range addrList.Addresses { + for _, consAddrToPrune := range k.GetAllConsumerAddrsToPrune(ctx, chainID) { + for _, cAddr := range consAddrToPrune.ConsumerAddrs.Addresses { addr := sdk.ConsAddress(cAddr) willBePruned[addr.String()] = true } - return false - }) + } + good := true - k.IterateAllValidatorsByConsumerAddr(ctx, func(chainID string, consumerAddr sdk.ConsAddress, providerAddr sdk.ConsAddress) (stop bool) { - if _, ok := willBePruned[consumerAddr.String()]; ok { + for _, valByConsAddr := range k.GetAllValidatorsByConsumerAddr(ctx, nil) { + if _, ok := willBePruned[sdk.ConsAddress(valByConsAddr.ConsumerAddr).String()]; ok { // Address will be pruned, everything is fine. - return false + continue } // Try to find a validator who has this consumer address currently assigned isCurrentlyAssigned := false - k.IterateValidatorConsumerPubKeys(ctx, chainID, - func(_ sdk.ConsAddress, consumerKey tmprotocrypto.PublicKey) (stop bool) { - if utils.TMCryptoPublicKeyToConsAddr(consumerKey).Equals(consumerAddr) { - isCurrentlyAssigned = true - return true // stop iterating early - } - return false - }, - ) + for _, valconsPubKey := range k.GetAllValidatorConsumerPubKeys(ctx, &valByConsAddr.ChainId) { + if utils.TMCryptoPublicKeyToConsAddr(*valconsPubKey.ConsumerKey).Equals(sdk.ConsAddress(valByConsAddr.ConsumerAddr)) { + isCurrentlyAssigned = true + break + } + } + if !isCurrentlyAssigned { // Will not be pruned, and is not currently assigned: violation good = false - return true // breakout early + break } - return false - }) + } + return good } diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 11244640fb..3fa977d305 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -35,10 +35,7 @@ func (k Keeper) HandleConsumerAdditionProposal(ctx sdk.Context, p *types.Consume return err } - err := k.SetPendingConsumerAdditionProp(ctx, p) - if err != nil { - return err - } + k.SetPendingConsumerAdditionProp(ctx, p) return nil } @@ -127,7 +124,7 @@ func (k Keeper) HandleConsumerRemovalProposal(ctx sdk.Context, p *types.Consumer return err } - k.SetPendingConsumerRemovalProp(ctx, p.ChainId, p.StopTime) + k.SetPendingConsumerRemovalProp(ctx, p) return nil } @@ -159,13 +156,8 @@ func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan boo k.DeleteChannelToChain(ctx, channelID) // delete VSC send timestamps - var ids []uint64 - k.IterateVscSendTimestamps(ctx, chainID, func(vscID uint64, ts time.Time) (stop bool) { - ids = append(ids, vscID) - return false // do not stop the iteration - }) - for _, vscID := range ids { - k.DeleteVscSendTimestamp(ctx, chainID, vscID) + for _, vscSendTimestamp := range k.GetAllVscSendTimestamps(ctx, chainID) { + k.DeleteVscSendTimestamp(ctx, chainID, vscSendTimestamp.VscId) } } @@ -174,16 +166,13 @@ func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan boo k.DeletePendingVSCPackets(ctx, chainID) // release unbonding operations - var vscIDs []uint64 - // iterate over the consumer chain's unbonding operation VSC ids - k.IterateOverUnbondingOpIndex(ctx, chainID, func(vscID uint64, ids []uint64) (stop bool) { + for _, unbondingOpsIndex := range k.GetAllUnbondingOpIndexes(ctx, chainID) { // iterate over the unbonding operations for the current VSC ID var maturedIds []uint64 - for _, id := range ids { + for _, id := range unbondingOpsIndex.UnbondingOpIds { unbondingOp, found := k.GetUnbondingOp(ctx, id) if !found { - err = fmt.Errorf("could not find UnbondingOp according to index - id: %d", id) - return true // stop the iteration + return fmt.Errorf("could not find UnbondingOp according to index - id: %d", id) } // remove consumer chain ID from unbonding op record unbondingOp.UnbondingConsumerChains, _ = removeStringFromSlice(unbondingOp.UnbondingConsumerChains, chainID) @@ -199,18 +188,7 @@ func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan boo } } k.AppendMaturedUnbondingOps(ctx, maturedIds) - - vscIDs = append(vscIDs, vscID) - return false // do not stop the iteration - }) - - if err != nil { - return err - } - - // clean up indexes - for _, id := range vscIDs { - k.DeleteUnbondingOpIndex(ctx, chainID, id) + k.DeleteUnbondingOpIndex(ctx, chainID, unbondingOpsIndex.VscId) } // Remove any existing throttling related entries from the global queue, @@ -318,44 +296,47 @@ func (k Keeper) MakeConsumerGenesis(ctx sdk.Context, prop *types.ConsumerAdditio return gen, hash, nil } -// SetPendingConsumerAdditionProp stores a pending proposal to create a consumer chain client -func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, clientInfo *types.ConsumerAdditionProposal) error { +// SetPendingConsumerAdditionProp stores a pending consumer addition proposal. +// +// Note that the pending consumer addition proposals are stored under keys with +// the following format: PendingCAPBytePrefix | spawnTime | chainID +// Thus, if multiple consumer addition proposal for the same chain will pass at +// the same time, then only the last one will be stored. +func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, prop *types.ConsumerAdditionProposal) { store := ctx.KVStore(k.storeKey) - bz, err := k.cdc.Marshal(clientInfo) + bz, err := prop.Marshal() if err != nil { - return err + panic(fmt.Errorf("failed to marshal consumer addition proposal: %w", err)) } - - store.Set(types.PendingCAPKey(clientInfo.SpawnTime, clientInfo.ChainId), bz) - return nil + store.Set(types.PendingCAPKey(prop.SpawnTime, prop.ChainId), bz) } -// GetPendingConsumerAdditionProp retrieves a pending proposal to create a consumer chain client (by spawn time and chain id) +// GetPendingConsumerAdditionProp retrieves a pending consumer addition proposal +// by spawn time and chain id. +// +// Note: this method is only used in testing func (k Keeper) GetPendingConsumerAdditionProp(ctx sdk.Context, spawnTime time.Time, chainID string) (prop types.ConsumerAdditionProposal, found bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.PendingCAPKey(spawnTime, chainID)) - if len(bz) == 0 { + if bz == nil { return prop, false } - k.cdc.MustUnmarshal(bz, &prop) + err := prop.Unmarshal(bz) + if err != nil { + panic(fmt.Errorf("failed to unmarshal consumer addition proposal: %w", err)) + } return prop, true } -// PendingConsumerAdditionPropIterator returns an iterator for iterating through pending consumer addition proposals -func (k Keeper) PendingConsumerAdditionPropIterator(ctx sdk.Context) sdk.Iterator { - store := ctx.KVStore(k.storeKey) - return sdk.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) -} - // BeginBlockInit iterates over the pending consumer addition proposals in order, and creates // clients for props in which the spawn time has passed. Executed proposals are deleted. // // See: https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/methods.md#ccv-pcf-bblock-init1 // Spec tag:[CCV-PCF-BBLOCK-INIT.1] func (k Keeper) BeginBlockInit(ctx sdk.Context) { - propsToExecute := k.ConsumerAdditionPropsToExecute(ctx) + propsToExecute := k.GetConsumerAdditionPropsToExecute(ctx) for _, prop := range propsToExecute { // create consumer client in a cached context to handle errors @@ -375,68 +356,54 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) { k.DeletePendingConsumerAdditionProps(ctx, propsToExecute...) } -// ConsumerAdditionPropsToExecute iterates over the pending consumer addition proposals -// and returns an ordered list of proposals to be executed, ie. consumer clients to be created. +// GetConsumerAdditionPropsToExecute returns the pending consumer addition proposals +// that are ready to be executed, i.e., consumer clients to be created. // A prop is included in the returned list if its proposed spawn time has passed. // // Note: this method is split out from BeginBlockInit to be easily unit tested. -func (k Keeper) ConsumerAdditionPropsToExecute(ctx sdk.Context) []types.ConsumerAdditionProposal { - - // store the (to be) executed proposals in order - propsToExecute := []types.ConsumerAdditionProposal{} - - iterator := k.PendingConsumerAdditionPropIterator(ctx) - defer iterator.Close() - - k.IteratePendingConsumerAdditionProps(ctx, func(spawnTime time.Time, prop types.ConsumerAdditionProposal) (stop bool) { - if !ctx.BlockTime().Before(spawnTime) { - propsToExecute = append(propsToExecute, prop) - return false // do not stop the iteration - } - return true // stop iteration, proposals are ordered by spawn time, so no additional pending props are ready to act upon - }) - - return propsToExecute -} - -func (k Keeper) IteratePendingConsumerAdditionProps( - ctx sdk.Context, - cb func(spawnTime time.Time, prop types.ConsumerAdditionProposal) (stop bool), -) { - iterator := k.PendingConsumerAdditionPropIterator(ctx) +func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecute []types.ConsumerAdditionProposal) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - key := iterator.Key() - spawnTime, _, err := types.ParsePendingCAPKey(key) + var prop types.ConsumerAdditionProposal + err := prop.Unmarshal(iterator.Value()) if err != nil { - panic(fmt.Errorf("failed to parse pending client key: %w", err)) + panic(fmt.Errorf("failed to unmarshal consumer addition proposal: %w", err)) } - var prop types.ConsumerAdditionProposal - k.cdc.MustUnmarshal(iterator.Value(), &prop) - - stop := cb(spawnTime, prop) - if stop { + if !ctx.BlockTime().Before(prop.SpawnTime) { + propsToExecute = append(propsToExecute, prop) + } else { break } } -} -// GetAllConsumerAdditionProps returns all consumer addition proposals separated into matured and pending. -func (k Keeper) GetAllConsumerAdditionProps(ctx sdk.Context) types.ConsumerAdditionProposals { - props := types.ConsumerAdditionProposals{} + return propsToExecute +} +// GetAllPendingConsumerAdditionProps gets all pending consumer addition proposals. +// +// Note that the pending consumer addition proposals are stored under keys with the following format: +// PendingCAPBytePrefix | spawnTime.UnixNano() | chainID +// Thus, the returned array is in spawnTime order. If two proposals have the same spawnTime, +// then they are ordered by chainID. +func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []types.ConsumerAdditionProposal) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var prop types.ConsumerAdditionProposal - k.cdc.MustUnmarshal(iterator.Value(), &prop) + err := prop.Unmarshal(iterator.Value()) + if err != nil { + panic(fmt.Errorf("failed to unmarshal consumer addition proposal: %w", err)) + } - props.Pending = append(props.Pending, &prop) + props = append(props, prop) } + return props } @@ -449,15 +416,26 @@ func (k Keeper) DeletePendingConsumerAdditionProps(ctx sdk.Context, proposals .. } } -// SetPendingConsumerRemovalProp stores a pending proposal to remove and stop a consumer chain -func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, chainID string, timestamp time.Time) { +// SetPendingConsumerRemovalProp stores a pending consumer removal proposal. +// +// Note that the pending removal addition proposals are stored under keys with +// the following format: PendingCRPBytePrefix | stopTime | chainID +// Thus, if multiple removal addition proposal for the same chain will pass at +// the same time, then only the last one will be stored. +func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, prop *types.ConsumerRemovalProposal) { store := ctx.KVStore(k.storeKey) - store.Set(types.PendingCRPKey(timestamp, chainID), []byte{}) + bz, err := prop.Marshal() + if err != nil { + panic(fmt.Errorf("failed to marshal consumer removal proposal: %w", err)) + } + store.Set(types.PendingCRPKey(prop.StopTime, prop.ChainId), bz) } -// GetPendingConsumerRemovalProp returns a boolean if a pending consumer removal proposal -// exists for the given consumer chain ID and timestamp -func (k Keeper) GetPendingConsumerRemovalProp(ctx sdk.Context, chainID string, timestamp time.Time) bool { +// PendingConsumerRemovalPropExists checks whether a pending consumer removal proposal +// exists for the given consumer chain ID and stopTime +// +// Note: this method is only used in testing +func (k Keeper) PendingConsumerRemovalPropExists(ctx sdk.Context, chainID string, timestamp time.Time) bool { store := ctx.KVStore(k.storeKey) bz := store.Get(types.PendingCRPKey(timestamp, chainID)) @@ -474,12 +452,6 @@ func (k Keeper) DeletePendingConsumerRemovalProps(ctx sdk.Context, proposals ... } } -// PendingConsumerRemovalPropIterator returns an iterator for iterating through pending consumer removal proposals -func (k Keeper) PendingConsumerRemovalPropIterator(ctx sdk.Context) sdk.Iterator { - store := ctx.KVStore(k.storeKey) - return sdk.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) -} - // BeginBlockCCR iterates over the pending consumer removal proposals // in order and stop/removes the chain if the stop time has passed, // otherwise it will break out of loop and return. Executed proposals are deleted. @@ -487,7 +459,7 @@ func (k Keeper) PendingConsumerRemovalPropIterator(ctx sdk.Context) sdk.Iterator // See: https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/methods.md#ccv-pcf-bblock-ccr1 // Spec tag: [CCV-PCF-BBLOCK-CCR.1] func (k Keeper) BeginBlockCCR(ctx sdk.Context) { - propsToExecute := k.ConsumerRemovalPropsToExecute(ctx) + propsToExecute := k.GetConsumerRemovalPropsToExecute(ctx) for _, prop := range propsToExecute { // stop consumer chain in a cached context to handle errors @@ -507,68 +479,58 @@ func (k Keeper) BeginBlockCCR(ctx sdk.Context) { k.DeletePendingConsumerRemovalProps(ctx, propsToExecute...) } -// ConsumerRemovalPropsToExecute iterates over the pending consumer removal proposals +// GetConsumerRemovalPropsToExecute iterates over the pending consumer removal proposals // and returns an ordered list of consumer removal proposals to be executed, // ie. consumer chains to be stopped and removed from the provider chain. // A prop is included in the returned list if its proposed stop time has passed. // // Note: this method is split out from BeginBlockCCR to be easily unit tested. -func (k Keeper) ConsumerRemovalPropsToExecute(ctx sdk.Context) []types.ConsumerRemovalProposal { +func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.ConsumerRemovalProposal { // store the (to be) executed consumer removal proposals in order propsToExecute := []types.ConsumerRemovalProposal{} - k.IteratePendingConsumerRemovalProps(ctx, func(stopTime time.Time, prop types.ConsumerRemovalProposal) (stop bool) { - if !ctx.BlockTime().Before(stopTime) { - propsToExecute = append(propsToExecute, prop) - return false // do not stop the iteration - } - // No more proposals to check, since they're stored/ordered by timestamp. - return true // stop - }) - - return propsToExecute -} - -func (k Keeper) IteratePendingConsumerRemovalProps( - ctx sdk.Context, - cb func(stopTime time.Time, prop types.ConsumerRemovalProposal) (stop bool), -) { - iterator := k.PendingConsumerRemovalPropIterator(ctx) + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - - key := iterator.Key() - stopTime, chainID, err := types.ParsePendingCRPKey(key) + var prop types.ConsumerRemovalProposal + err := prop.Unmarshal(iterator.Value()) if err != nil { - panic(fmt.Errorf("failed to parse pending consumer removal proposal key: %w", err)) + panic(fmt.Errorf("failed to unmarshal consumer removal proposal: %w", err)) } - stop := cb(stopTime, types.ConsumerRemovalProposal{ChainId: chainID, StopTime: stopTime}) - if stop { + // If current block time is equal to or after stop time, proposal is ready to be executed + if !ctx.BlockTime().Before(prop.StopTime) { + propsToExecute = append(propsToExecute, prop) + } else { + // No more proposals to check, since they're stored/ordered by timestamp. break } } -} -// GetAllConsumerRemovalProps returns all consumer removal proposals separated into matured and pending. -func (k Keeper) GetAllConsumerRemovalProps(ctx sdk.Context) types.ConsumerRemovalProposals { - props := types.ConsumerRemovalProposals{} + return propsToExecute +} +// GetAllPendingConsumerRemovalProps iterates through the pending consumer removal proposals. +// +// Note that the pending consumer removal proposals are stored under keys with the following format: +// PendingCRPBytePrefix | stopTime.UnixNano() | chainID +// Thus, the returned array is in stopTime order. +func (k Keeper) GetAllPendingConsumerRemovalProps(ctx sdk.Context) (props []types.ConsumerRemovalProposal) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - key := iterator.Key() - stopTime, chainID, err := types.ParsePendingCRPKey(key) + var prop types.ConsumerRemovalProposal + err := prop.Unmarshal(iterator.Value()) if err != nil { - panic(fmt.Errorf("failed to parse pending consumer removal proposal key: %w", err)) + panic(fmt.Errorf("failed to unmarshal consumer removal proposal: %w", err)) } - props.Pending = append(props.Pending, - &types.ConsumerRemovalProposal{ChainId: chainID, StopTime: stopTime}) + props = append(props, prop) } return props diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index fcb744bb48..ec1599e5bb 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -1,7 +1,9 @@ package keeper_test import ( + "bytes" "encoding/json" + "sort" "testing" "time" @@ -11,7 +13,6 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" "github.com/golang/mock/gomock" abci "github.com/tendermint/tendermint/abci/types" - tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" "github.com/stretchr/testify/require" @@ -233,13 +234,12 @@ func TestPendingConsumerAdditionPropDeletion(t *testing.T) { defer ctrl.Finish() for _, tc := range testCases { - err := providerKeeper.SetPendingConsumerAdditionProp(ctx, &tc.ConsumerAdditionProposal) - require.NoError(t, err) + providerKeeper.SetPendingConsumerAdditionProp(ctx, &tc.ConsumerAdditionProposal) } ctx = ctx.WithBlockTime(time.Now().UTC()) - propsToExecute := providerKeeper.ConsumerAdditionPropsToExecute(ctx) + propsToExecute := providerKeeper.GetConsumerAdditionPropsToExecute(ctx) // Delete consumer addition proposals, same as what would be done by BeginBlockInit providerKeeper.DeletePendingConsumerAdditionProps(ctx, propsToExecute...) numDeleted := 0 @@ -256,50 +256,65 @@ func TestPendingConsumerAdditionPropDeletion(t *testing.T) { } } -// TestPendingConsumerAdditionPropOrder tests that pending consumer addition proposals -// are accessed in order by timestamp via the iterator -func TestPendingConsumerAdditionPropOrder(t *testing.T) { +// TestGetConsumerAdditionPropsToExecute tests that pending consumer addition proposals +// that are ready to execute are accessed in order by timestamp via the iterator +func TestGetConsumerAdditionPropsToExecute(t *testing.T) { now := time.Now().UTC() - - // props with unique chain ids and spawn times - sampleProp1 := providertypes.ConsumerAdditionProposal{ChainId: "1", SpawnTime: now} - sampleProp2 := providertypes.ConsumerAdditionProposal{ChainId: "2", SpawnTime: now.Add(1 * time.Hour)} - sampleProp3 := providertypes.ConsumerAdditionProposal{ChainId: "3", SpawnTime: now.Add(2 * time.Hour)} - sampleProp4 := providertypes.ConsumerAdditionProposal{ChainId: "4", SpawnTime: now.Add(3 * time.Hour)} - sampleProp5 := providertypes.ConsumerAdditionProposal{ChainId: "5", SpawnTime: now.Add(4 * time.Hour)} + sampleProp1 := providertypes.ConsumerAdditionProposal{ChainId: "chain-2", SpawnTime: now} + sampleProp2 := providertypes.ConsumerAdditionProposal{ChainId: "chain-1", SpawnTime: now.Add(time.Hour)} + sampleProp3 := providertypes.ConsumerAdditionProposal{ChainId: "chain-4", SpawnTime: now.Add(-time.Hour)} + sampleProp4 := providertypes.ConsumerAdditionProposal{ChainId: "chain-3", SpawnTime: now} + sampleProp5 := providertypes.ConsumerAdditionProposal{ChainId: "chain-1", SpawnTime: now.Add(2 * time.Hour)} + + getExpectedOrder := func(props []providertypes.ConsumerAdditionProposal, accessTime time.Time) []providertypes.ConsumerAdditionProposal { + expectedOrder := []providertypes.ConsumerAdditionProposal{} + for _, prop := range props { + if !accessTime.Before(prop.SpawnTime) { + expectedOrder = append(expectedOrder, prop) + } + } + if len(expectedOrder) == 0 { + return nil + } + // sorting by SpawnTime.UnixNano() + sort.Slice(expectedOrder, func(i, j int) bool { + if expectedOrder[i].SpawnTime.UTC() == expectedOrder[j].SpawnTime.UTC() { + // proposals with same SpawnTime + return expectedOrder[i].ChainId < expectedOrder[j].ChainId + } + return expectedOrder[i].SpawnTime.UTC().Before(expectedOrder[j].SpawnTime.UTC()) + }) + return expectedOrder + } testCases := []struct { - propSubmitOrder []providertypes.ConsumerAdditionProposal - accessTime time.Time - expectedOrderedProps []providertypes.ConsumerAdditionProposal + propSubmitOrder []providertypes.ConsumerAdditionProposal + accessTime time.Time }{ { propSubmitOrder: []providertypes.ConsumerAdditionProposal{ sampleProp1, sampleProp2, sampleProp3, sampleProp4, sampleProp5, }, - accessTime: now.Add(30 * time.Minute), - expectedOrderedProps: []providertypes.ConsumerAdditionProposal{ - sampleProp1, - }, + accessTime: now, }, { propSubmitOrder: []providertypes.ConsumerAdditionProposal{ sampleProp3, sampleProp2, sampleProp1, sampleProp5, sampleProp4, }, - accessTime: now.Add(3 * time.Hour).Add(30 * time.Minute), - expectedOrderedProps: []providertypes.ConsumerAdditionProposal{ - sampleProp1, sampleProp2, sampleProp3, sampleProp4, - }, + accessTime: now.Add(time.Hour), }, { propSubmitOrder: []providertypes.ConsumerAdditionProposal{ sampleProp5, sampleProp4, sampleProp3, sampleProp2, sampleProp1, }, - accessTime: now.Add(5 * time.Hour), - expectedOrderedProps: []providertypes.ConsumerAdditionProposal{ - sampleProp1, sampleProp2, sampleProp3, sampleProp4, sampleProp5, + accessTime: now.Add(-2 * time.Hour), + }, + { + propSubmitOrder: []providertypes.ConsumerAdditionProposal{ + sampleProp5, sampleProp4, sampleProp3, sampleProp2, sampleProp1, }, + accessTime: now.Add(3 * time.Hour), }, } @@ -307,17 +322,54 @@ func TestPendingConsumerAdditionPropOrder(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - ctx = ctx.WithBlockTime(tc.accessTime) + expectedOrderedProps := getExpectedOrder(tc.propSubmitOrder, tc.accessTime) for _, prop := range tc.propSubmitOrder { - err := providerKeeper.SetPendingConsumerAdditionProp(ctx, &prop) - require.NoError(t, err) + cpProp := prop + providerKeeper.SetPendingConsumerAdditionProp(ctx, &cpProp) } - propsToExecute := providerKeeper.ConsumerAdditionPropsToExecute(ctx) - require.Equal(t, tc.expectedOrderedProps, propsToExecute) + propsToExecute := providerKeeper.GetConsumerAdditionPropsToExecute(ctx.WithBlockTime(tc.accessTime)) + require.Equal(t, expectedOrderedProps, propsToExecute) } } +// Test getting both matured and pending consumer addition proposals +func TestGetAllConsumerAdditionProps(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + now := time.Now().UTC() + props := []providertypes.ConsumerAdditionProposal{ + {ChainId: "chain-2", SpawnTime: now}, + {ChainId: "chain-1", SpawnTime: now.Add(2 * time.Hour)}, + {ChainId: "chain-4", SpawnTime: now.Add(-time.Hour)}, + {ChainId: "chain-3", SpawnTime: now.Add(4 * time.Hour)}, + {ChainId: "chain-1", SpawnTime: now}, + } + expectedGetAllOrder := props + // sorting by SpawnTime.UnixNano() + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + tsi := uint64(expectedGetAllOrder[i].SpawnTime.UTC().UnixNano()) + tsj := uint64(expectedGetAllOrder[j].SpawnTime.UTC().UnixNano()) + cmpTimestamps := bytes.Compare(sdk.Uint64ToBigEndian(tsi), sdk.Uint64ToBigEndian(tsj)) + if cmpTimestamps == 0 { + // proposals with same SpawnTime + return expectedGetAllOrder[i].ChainId < expectedGetAllOrder[j].ChainId + } + return cmpTimestamps == -1 + }) + + for _, prop := range props { + cpProp := prop // bring into loop scope - avoids using iterator pointer instead of value pointer + pk.SetPendingConsumerAdditionProp(ctx, &cpProp) + } + + // iterate and check all results are returned in the expected order + result := pk.GetAllPendingConsumerAdditionProps(ctx.WithBlockTime(now)) + require.Len(t, result, len(props)) + require.Equal(t, expectedGetAllOrder, result) +} + // // Consumer Chain Removal sub-protocol related tests of proposal.go // @@ -397,14 +449,14 @@ func TestHandleConsumerRemovalProposal(t *testing.T) { require.NoError(t, err) // Proposal should be stored as pending - found := providerKeeper.GetPendingConsumerRemovalProp(ctx, tc.prop.ChainId, tc.prop.StopTime) + found := providerKeeper.PendingConsumerRemovalPropExists(ctx, tc.prop.ChainId, tc.prop.StopTime) require.True(t, found) } else { require.Error(t, err) // Expect no pending proposal to exist - found := providerKeeper.GetPendingConsumerRemovalProp(ctx, tc.prop.ChainId, tc.prop.StopTime) + found := providerKeeper.PendingConsumerRemovalPropExists(ctx, tc.prop.ChainId, tc.prop.StopTime) require.False(t, found) } @@ -508,38 +560,14 @@ func testProviderStateIsCleaned(t *testing.T, ctx sdk.Context, providerKeeper pr require.Empty(t, acks) _, found = providerKeeper.GetInitTimeoutTimestamp(ctx, expectedChainID) require.False(t, found) - found = false - providerKeeper.IterateVscSendTimestamps(ctx, expectedChainID, func(_ uint64, _ time.Time) (stop bool) { - found = true - return true // stop the iteration - }) - require.False(t, found) + + require.Empty(t, providerKeeper.GetAllVscSendTimestamps(ctx, expectedChainID)) // test key assignment state is cleaned - found = false - providerKeeper.IterateValidatorConsumerPubKeys(ctx, expectedChainID, func(_ sdk.ConsAddress, _ tmprotocrypto.PublicKey) (stop bool) { - found = true - return true // stop the iteration - }) - require.False(t, found) - found = false - providerKeeper.IterateValidatorsByConsumerAddr(ctx, expectedChainID, func(_ sdk.ConsAddress, _ sdk.ConsAddress) (stop bool) { - found = true - return true // stop the iteration - }) - require.False(t, found) - found = false - providerKeeper.IterateKeyAssignmentReplacements(ctx, expectedChainID, func(_ sdk.ConsAddress, _ tmprotocrypto.PublicKey, _ int64) (stop bool) { - found = true - return true // stop the iteration - }) - require.False(t, found) - found = false - providerKeeper.IterateConsumerAddrsToPrune(ctx, expectedChainID, func(_ uint64, _ providertypes.AddressList) (stop bool) { - found = true - return true // stop the iteration - }) - require.False(t, found) + require.Empty(t, providerKeeper.GetAllValidatorConsumerPubKeys(ctx, &expectedChainID)) + require.Empty(t, providerKeeper.GetAllValidatorsByConsumerAddr(ctx, &expectedChainID)) + require.Empty(t, providerKeeper.GetAllKeyAssignmentReplacements(ctx, expectedChainID)) + require.Empty(t, providerKeeper.GetAllConsumerAddrsToPrune(ctx, expectedChainID)) allGlobalEntries := providerKeeper.GetAllGlobalSlashEntries(ctx) for _, entry := range allGlobalEntries { @@ -572,17 +600,17 @@ func TestPendingConsumerRemovalPropDeletion(t *testing.T) { defer ctrl.Finish() for _, tc := range testCases { - providerKeeper.SetPendingConsumerRemovalProp(ctx, tc.ChainId, tc.StopTime) + providerKeeper.SetPendingConsumerRemovalProp(ctx, &tc.ConsumerRemovalProposal) } ctx = ctx.WithBlockTime(time.Now().UTC()) - propsToExecute := providerKeeper.ConsumerRemovalPropsToExecute(ctx) + propsToExecute := providerKeeper.GetConsumerRemovalPropsToExecute(ctx) // Delete consumer removal proposals, same as what would be done by BeginBlockCCR providerKeeper.DeletePendingConsumerRemovalProps(ctx, propsToExecute...) numDeleted := 0 for _, tc := range testCases { - res := providerKeeper.GetPendingConsumerRemovalProp(ctx, tc.ChainId, tc.StopTime) + res := providerKeeper.PendingConsumerRemovalPropExists(ctx, tc.ChainId, tc.StopTime) if !tc.ExpDeleted { require.NotEmpty(t, res, "consumer removal prop was deleted: %s %s", tc.ChainId, tc.StopTime.String()) continue @@ -593,63 +621,114 @@ func TestPendingConsumerRemovalPropDeletion(t *testing.T) { } } -// Tests that pending consumer removal proposals are accessed in order by timestamp via the iterator -func TestPendingConsumerRemovalPropOrder(t *testing.T) { - +// TestGetConsumerRemovalPropsToExecute tests that pending consumer removal proposals +// that are ready to execute are accessed in order by timestamp via the iterator +func TestGetConsumerRemovalPropsToExecute(t *testing.T) { now := time.Now().UTC() - - // props with unique chain ids and spawn times - sampleProp1 := providertypes.ConsumerRemovalProposal{ChainId: "1", StopTime: now} - sampleProp2 := providertypes.ConsumerRemovalProposal{ChainId: "2", StopTime: now.Add(1 * time.Hour)} - sampleProp3 := providertypes.ConsumerRemovalProposal{ChainId: "3", StopTime: now.Add(2 * time.Hour)} - sampleProp4 := providertypes.ConsumerRemovalProposal{ChainId: "4", StopTime: now.Add(3 * time.Hour)} - sampleProp5 := providertypes.ConsumerRemovalProposal{ChainId: "5", StopTime: now.Add(4 * time.Hour)} + sampleProp1 := providertypes.ConsumerRemovalProposal{ChainId: "chain-2", StopTime: now} + sampleProp2 := providertypes.ConsumerRemovalProposal{ChainId: "chain-1", StopTime: now.Add(time.Hour)} + sampleProp3 := providertypes.ConsumerRemovalProposal{ChainId: "chain-4", StopTime: now.Add(-time.Hour)} + sampleProp4 := providertypes.ConsumerRemovalProposal{ChainId: "chain-3", StopTime: now} + sampleProp5 := providertypes.ConsumerRemovalProposal{ChainId: "chain-1", StopTime: now.Add(2 * time.Hour)} + + getExpectedOrder := func(props []providertypes.ConsumerRemovalProposal, accessTime time.Time) []providertypes.ConsumerRemovalProposal { + expectedOrder := []providertypes.ConsumerRemovalProposal{} + for _, prop := range props { + if !accessTime.Before(prop.StopTime) { + expectedOrder = append(expectedOrder, prop) + } + } + // sorting by SpawnTime.UnixNano() + sort.Slice(expectedOrder, func(i, j int) bool { + if expectedOrder[i].StopTime.UTC() == expectedOrder[j].StopTime.UTC() { + // proposals with same StopTime + return expectedOrder[i].ChainId < expectedOrder[j].ChainId + } + return expectedOrder[i].StopTime.UTC().Before(expectedOrder[j].StopTime.UTC()) + }) + return expectedOrder + } testCases := []struct { - propSubmitOrder []providertypes.ConsumerRemovalProposal - accessTime time.Time - expectedOrderedProps []providertypes.ConsumerRemovalProposal + propSubmitOrder []providertypes.ConsumerRemovalProposal + accessTime time.Time }{ { propSubmitOrder: []providertypes.ConsumerRemovalProposal{ sampleProp1, sampleProp2, sampleProp3, sampleProp4, sampleProp5, }, - accessTime: now.Add(30 * time.Minute), - expectedOrderedProps: []providertypes.ConsumerRemovalProposal{ - sampleProp1, - }, + accessTime: now, }, { propSubmitOrder: []providertypes.ConsumerRemovalProposal{ sampleProp3, sampleProp2, sampleProp1, sampleProp5, sampleProp4, }, - accessTime: now.Add(3 * time.Hour).Add(30 * time.Minute), - expectedOrderedProps: []providertypes.ConsumerRemovalProposal{ - sampleProp1, sampleProp2, sampleProp3, sampleProp4, - }, + accessTime: now.Add(time.Hour), }, { propSubmitOrder: []providertypes.ConsumerRemovalProposal{ sampleProp5, sampleProp4, sampleProp3, sampleProp2, sampleProp1, }, - accessTime: now.Add(5 * time.Hour), - expectedOrderedProps: []providertypes.ConsumerRemovalProposal{ - sampleProp1, sampleProp2, sampleProp3, sampleProp4, sampleProp5, + accessTime: now.Add(-2 * time.Hour), + }, + { + propSubmitOrder: []providertypes.ConsumerRemovalProposal{ + sampleProp5, sampleProp4, sampleProp3, sampleProp2, sampleProp1, }, + accessTime: now.Add(3 * time.Hour), }, } for _, tc := range testCases { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - ctx = ctx.WithBlockTime(tc.accessTime) + + expectedOrderedProps := getExpectedOrder(tc.propSubmitOrder, tc.accessTime) for _, prop := range tc.propSubmitOrder { - providerKeeper.SetPendingConsumerRemovalProp(ctx, prop.ChainId, prop.StopTime) + cpProp := prop + providerKeeper.SetPendingConsumerRemovalProp(ctx, &cpProp) + } + propsToExecute := providerKeeper.GetConsumerRemovalPropsToExecute(ctx.WithBlockTime(tc.accessTime)) + require.Equal(t, expectedOrderedProps, propsToExecute) + } +} + +// Test getting both matured and pending consumer removal proposals +func TestGetAllConsumerRemovalProps(t *testing.T) { + pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + now := time.Now().UTC() + props := []providertypes.ConsumerRemovalProposal{ + {ChainId: "chain-2", StopTime: now}, + {ChainId: "chain-1", StopTime: now.Add(2 * time.Hour)}, + {ChainId: "chain-4", StopTime: now.Add(-time.Hour)}, + {ChainId: "chain-3", StopTime: now.Add(4 * time.Hour)}, + {ChainId: "chain-1", StopTime: now}, + } + expectedGetAllOrder := props + // sorting by StopTime.UnixNano() + sort.Slice(expectedGetAllOrder, func(i, j int) bool { + tsi := uint64(expectedGetAllOrder[i].StopTime.UTC().UnixNano()) + tsj := uint64(expectedGetAllOrder[j].StopTime.UTC().UnixNano()) + cmpTimestamps := bytes.Compare(sdk.Uint64ToBigEndian(tsi), sdk.Uint64ToBigEndian(tsj)) + if cmpTimestamps == 0 { + // proposals with same StopTime + return expectedGetAllOrder[i].ChainId < expectedGetAllOrder[j].ChainId } - propsToExecute := providerKeeper.ConsumerRemovalPropsToExecute(ctx) - require.Equal(t, tc.expectedOrderedProps, propsToExecute) + return cmpTimestamps == -1 + }) + + for _, prop := range props { + cpProp := prop // bring into loop scope - avoids using iterator pointer instead of value pointer + pk.SetPendingConsumerRemovalProp(ctx, &cpProp) } + + // iterate and check all results are returned in the expected order + result := pk.GetAllPendingConsumerRemovalProps(ctx.WithBlockTime(now)) + require.Len(t, result, len(props)) + require.Equal(t, expectedGetAllOrder, result) } // TestMakeConsumerGenesis tests the MakeConsumerGenesis keeper method. @@ -818,8 +897,7 @@ func TestBeginBlockInit(t *testing.T) { ) for _, prop := range pendingProps { - err := providerKeeper.SetPendingConsumerAdditionProp(ctx, prop) - require.NoError(t, err) + providerKeeper.SetPendingConsumerAdditionProp(ctx, prop) } providerKeeper.BeginBlockInit(ctx) @@ -898,14 +976,14 @@ func TestBeginBlockCCR(t *testing.T) { require.NoError(t, err) // Set removal props for all consumer chains - providerKeeper.SetPendingConsumerRemovalProp(ctx, prop.ChainId, prop.StopTime) + providerKeeper.SetPendingConsumerRemovalProp(ctx, prop) } // Add an invalid prop to the store with an non-existing chain id invalidProp := providertypes.NewConsumerRemovalProposal( "title", "description", "chain4", now.Add(-time.Hour).UTC(), ).(*providertypes.ConsumerRemovalProposal) - providerKeeper.SetPendingConsumerRemovalProp(ctx, invalidProp.ChainId, invalidProp.StopTime) + providerKeeper.SetPendingConsumerRemovalProp(ctx, invalidProp) // // Test execution @@ -913,72 +991,16 @@ func TestBeginBlockCCR(t *testing.T) { providerKeeper.BeginBlockCCR(ctx) // Only the 3rd (final) proposal is still stored as pending - found := providerKeeper.GetPendingConsumerRemovalProp( + found := providerKeeper.PendingConsumerRemovalPropExists( ctx, pendingProps[0].ChainId, pendingProps[0].StopTime) require.False(t, found) - found = providerKeeper.GetPendingConsumerRemovalProp( + found = providerKeeper.PendingConsumerRemovalPropExists( ctx, pendingProps[1].ChainId, pendingProps[1].StopTime) require.False(t, found) - found = providerKeeper.GetPendingConsumerRemovalProp( + found = providerKeeper.PendingConsumerRemovalPropExists( ctx, pendingProps[2].ChainId, pendingProps[2].StopTime) require.True(t, found) - found = providerKeeper.GetPendingConsumerRemovalProp( + found = providerKeeper.PendingConsumerRemovalPropExists( ctx, invalidProp.ChainId, invalidProp.StopTime) require.False(t, found) } - -// Test getting both matured and pending comnsumer addition proposals -func TestGetAllConsumerAdditionProps(t *testing.T) { - now := time.Now().UTC() - - props := []providertypes.ConsumerAdditionProposal{ - {ChainId: "1", SpawnTime: now.Add(1 * time.Hour)}, - {ChainId: "2", SpawnTime: now.Add(2 * time.Hour)}, - {ChainId: "3", SpawnTime: now.Add(3 * time.Hour)}, - {ChainId: "4", SpawnTime: now.Add(4 * time.Hour)}, - } - - keeperParams := testkeeper.NewInMemKeeperParams(t) - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) - defer ctrl.Finish() - - for _, prop := range props { - cpProp := prop // bring into loop scope - avoids using iterator pointer instead of value pointer - err := providerKeeper.SetPendingConsumerAdditionProp(ctx, &cpProp) - require.NoError(t, err) - } - - // advance the clock to be 1 minute after first proposal - ctx = ctx.WithBlockTime(now.Add(time.Minute)) - res := providerKeeper.GetAllConsumerAdditionProps(ctx) - require.NotEmpty(t, res, "GetAllConsumerAdditionProps returned empty result") - require.Len(t, res.Pending, 4, "wrong len for pending addition props") - require.Equal(t, props[0].ChainId, res.Pending[0].ChainId, "wrong chain ID for pending addition prop") -} - -// Test getting both matured and pending consumer removal proposals -func TestGetAllConsumerRemovalProps(t *testing.T) { - now := time.Now().UTC() - - props := []providertypes.ConsumerRemovalProposal{ - {ChainId: "1", StopTime: now.Add(1 * time.Hour)}, - {ChainId: "2", StopTime: now.Add(2 * time.Hour)}, - {ChainId: "3", StopTime: now.Add(3 * time.Hour)}, - {ChainId: "4", StopTime: now.Add(4 * time.Hour)}, - } - - keeperParams := testkeeper.NewInMemKeeperParams(t) - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, keeperParams) - defer ctrl.Finish() - - for _, prop := range props { - providerKeeper.SetPendingConsumerRemovalProp(ctx, prop.ChainId, prop.StopTime) - } - - // advance the clock to be 1 minute after first proposal - ctx = ctx.WithBlockTime(now.Add(time.Minute)) - res := providerKeeper.GetAllConsumerRemovalProps(ctx) - require.NotEmpty(t, res, "GetAllConsumerRemovalProps returned empty result") - require.Len(t, res.Pending, 4, "wrong len for pending removal props") - require.Equal(t, props[0].ChainId, res.Pending[0].ChainId, "wrong chain ID for pending removal prop") -} diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index de73ce99e6..3759ba7cbc 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -144,24 +144,23 @@ func (k Keeper) EndBlockVSU(ctx sdk.Context) { // collect validator updates k.QueueVSCPackets(ctx) - // try sending VSC packets to all chains - // if CCV channel is not established for consumer chain + // try sending VSC packets to all registered consumer chains; + // if the CCV channel is not established for a consumer chain, // the updates will remain queued until the channel is established k.SendVSCPackets(ctx) } -// SendVSCPackets iterates over chains and sends pending VSC packets to -// consumer chains with established CCV channels -// if CCV channel is not established for consumer chain +// SendVSCPackets iterates over all registered consumers and sends pending +// VSC packets to the chains with established CCV channels. +// If the CCV channel is not established for a consumer chain, // the updates will remain queued until the channel is established func (k Keeper) SendVSCPackets(ctx sdk.Context) { - k.IterateConsumerChains(ctx, func(ctx sdk.Context, chainID, clientID string) (stop bool) { + for _, chain := range k.GetAllConsumerChains(ctx) { // check if CCV channel is established and send - if channelID, found := k.GetChainToChannel(ctx, chainID); found { - k.SendVSCPacketsToChain(ctx, chainID, channelID) + if channelID, found := k.GetChainToChannel(ctx, chain.ChainId); found { + k.SendVSCPacketsToChain(ctx, chain.ChainId, channelID) } - return false // continue iterating chains - }) + } } // SendVSCPacketsToChain sends all queued VSC packets to the specified chain @@ -202,24 +201,23 @@ func (k Keeper) QueueVSCPackets(ctx sdk.Context) { // get the validator updates from the staking module valUpdates := k.stakingKeeper.GetValidatorUpdates(ctx) - k.IterateConsumerChains(ctx, func(ctx sdk.Context, chainID, clientID string) (stop bool) { + for _, chain := range k.GetAllConsumerChains(ctx) { // apply the key assignment to the validator updates - valUpdates, err := k.ApplyKeyAssignmentToValUpdates(ctx, chainID, valUpdates) + valUpdates, err := k.ApplyKeyAssignmentToValUpdates(ctx, chain.ChainId, valUpdates) if err != nil { - panic(fmt.Sprintf("could not apply key assignment to validator updates for chain %s: %s", chainID, err.Error())) + panic(fmt.Sprintf("could not apply key assignment to validator updates for chain %s: %s", chain.ChainId, err.Error())) } // check whether there are changes in the validator set; // note that this also entails unbonding operations // w/o changes in the voting power of the validators in the validator set - unbondingOps, _ := k.GetUnbondingOpsFromIndex(ctx, chainID, valUpdateID) + unbondingOps, _ := k.GetUnbondingOpsFromIndex(ctx, chain.ChainId, valUpdateID) if len(valUpdates) != 0 || len(unbondingOps) != 0 { // construct validator set change packet data - packet := ccv.NewValidatorSetChangePacketData(valUpdates, valUpdateID, k.ConsumeSlashAcks(ctx, chainID)) - k.AppendPendingVSCPackets(ctx, chainID, packet) + packet := ccv.NewValidatorSetChangePacketData(valUpdates, valUpdateID, k.ConsumeSlashAcks(ctx, chain.ChainId)) + k.AppendPendingVSCPackets(ctx, chain.ChainId, packet) } - return false // do not stop the iteration - }) + } k.IncrementValidatorSetUpdateId(ctx) } @@ -396,54 +394,35 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { currentTime := ctx.BlockTime() currentTimeUint64 := uint64(currentTime.UnixNano()) - // iterate over initTimeoutTimestamps - var chainIdsToRemove []string - k.IterateInitTimeoutTimestamp(ctx, func(chainID string, ts uint64) (stop bool) { - if currentTimeUint64 > ts { + for _, initTimeoutTimestamp := range k.GetAllInitTimeoutTimestamps(ctx) { + if currentTimeUint64 > initTimeoutTimestamp.Timestamp { // initTimeout expired - chainIdsToRemove = append(chainIdsToRemove, chainID) - } - // continue to iterate through all timed out consumers - return false - }) - // remove consumers that timed out - for _, chainID := range chainIdsToRemove { - // stop the consumer chain and unlock the unbonding. - // Note that the CCV channel was not established, - // thus closeChan is irrelevant - err := k.StopConsumerChain(ctx, chainID, false) - if err != nil { - panic(fmt.Errorf("consumer chain failed to stop: %w", err)) + // stop the consumer chain and unlock the unbonding. + // Note that the CCV channel was not established, + // thus closeChan is irrelevant + err := k.StopConsumerChain(ctx, initTimeoutTimestamp.ChainId, false) + if err != nil { + panic(fmt.Errorf("consumer chain failed to stop: %w", err)) + } } } - // empty slice - chainIdsToRemove = nil - - // Iterate over all consumers with established CCV channels and - // check if the first vscSendTimestamp in iterator + VscTimeoutPeriod - // exceed the current block time. - // Checking the first send timestamp for each chain is sufficient since - // timestamps are ordered by vsc ID. - k.IterateChannelToChain(ctx, func(ctx sdk.Context, _, chainID string) (stop bool) { - k.IterateVscSendTimestamps(ctx, chainID, func(_ uint64, ts time.Time) (stop bool) { - timeoutTimestamp := ts.Add(k.GetParams(ctx).VscTimeoutPeriod) + for _, channelToChain := range k.GetAllChannelToChains(ctx) { + // Check if the first vscSendTimestamp in iterator + VscTimeoutPeriod + // exceed the current block time. + // Checking the first send timestamp for each chain is sufficient since + // timestamps are ordered by vsc ID. + vscSendTimestamp, found := k.GetFirstVscSendTimestamp(ctx, channelToChain.ChainId) + if found { + timeoutTimestamp := vscSendTimestamp.Timestamp.Add(k.GetParams(ctx).VscTimeoutPeriod) if currentTime.After(timeoutTimestamp) { // vscTimeout expired - chainIdsToRemove = append(chainIdsToRemove, chainID) + // stop the consumer chain and release unbondings + err := k.StopConsumerChain(ctx, channelToChain.ChainId, true) + if err != nil { + panic(fmt.Errorf("consumer chain failed to stop: %w", err)) + } } - // break iteration since the send timestamps are sorted in descending order - return true - }) - // continue to iterate through all consumers - return false - }) - // remove consumers that timed out - for _, chainID := range chainIdsToRemove { - // stop the consumer chain and release unbondings - err := k.StopConsumerChain(ctx, chainID, true) - if err != nil { - panic(fmt.Errorf("consumer chain failed to stop: %w", err)) } } } diff --git a/x/ccv/provider/keeper/throttle.go b/x/ccv/provider/keeper/throttle.go index 47c07556c4..03746bdca6 100644 --- a/x/ccv/provider/keeper/throttle.go +++ b/x/ccv/provider/keeper/throttle.go @@ -201,7 +201,11 @@ func (k Keeper) DeleteGlobalSlashEntriesForConsumer(ctx sdktypes.Context, consum k.DeleteGlobalSlashEntries(ctx, entriesToDel...) } -// GetAllGlobalSlashEntries returns all global slash entries from the queue +// GetAllGlobalSlashEntries returns all global slash entries from the queue. +// +// Note global slash entries are stored under keys with the following format: +// GlobalSlashEntryBytePrefix | uint64 recv time | ibc seq num | consumer chain id +// Thus, the returned array is ordered by recv time, then ibc seq num. func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.GlobalSlashEntry { store := ctx.KVStore(k.storeKey) @@ -320,8 +324,9 @@ func (k Keeper) QueueThrottledPacketData( // GetSlashAndTrailingData returns the first slash packet data instance and any // trailing vsc matured packet data instances in the chain-specific throttled packet data queue. // -// Note: this method is not tested directly, but is covered indirectly -// by TestHandlePacketDataForChain and e2e tests. +// Note that throttled packet data is stored under keys with the following format: +// ThrottledPacketDataBytePrefix | len(chainID) | chainID | ibcSeqNum +// Thus, the returned array is in ascending order of ibc seq numbers. func (k Keeper) GetSlashAndTrailingData(ctx sdktypes.Context, consumerChainID string) ( slashFound bool, slashData ccvtypes.SlashPacketData, vscMaturedData []ccvtypes.VSCMaturedPacketData, // Note: this slice contains the IBC sequence numbers of the slash packet data @@ -372,6 +377,7 @@ func (k Keeper) GetSlashAndTrailingData(ctx sdktypes.Context, consumerChainID st // GetAllThrottledPacketData returns all throttled packet data for a specific consumer chain. // // Note: This method is only used by tests, hence why it returns redundant data as different types. +// This method is not unit tested, as it is a test util. func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID string) ( slashData []ccvtypes.SlashPacketData, vscMaturedData []ccvtypes.VSCMaturedPacketData, rawOrderedData []interface{}, ibcSeqNums []uint64) { diff --git a/x/ccv/provider/keeper/throttle_test.go b/x/ccv/provider/keeper/throttle_test.go index 2aa30b0516..b971147e2a 100644 --- a/x/ccv/provider/keeper/throttle_test.go +++ b/x/ccv/provider/keeper/throttle_test.go @@ -829,6 +829,115 @@ func TestThrottledPacketData(t *testing.T) { } } +func TestGetSlashAndTrailingData(t *testing.T) { + + // Instantiate some data to test against + someSlashData := []ccvtypes.SlashPacketData{} + for i := 0; i < 10; i++ { + someSlashData = append(someSlashData, testkeeper.GetNewSlashPacketData()) + } + someVSCMaturedData := []ccvtypes.VSCMaturedPacketData{} + for i := 0; i < 10; i++ { + someVSCMaturedData = append(someVSCMaturedData, testkeeper.GetNewVSCMaturedPacketData()) + } + + testCases := []struct { + name string + dataToQueue []throttledPacketDataInstance + expectedSlashFound bool + expectedSlashData ccvtypes.SlashPacketData + expectedVSCMaturedData []ccvtypes.VSCMaturedPacketData + expectedIBCSeqNums []uint64 + }{ + { + name: "Empty queue", + dataToQueue: []throttledPacketDataInstance{}, + expectedSlashFound: false, + expectedSlashData: ccvtypes.SlashPacketData{}, // single zero value returned. + expectedVSCMaturedData: []ccvtypes.VSCMaturedPacketData{}, + expectedIBCSeqNums: []uint64{}, + }, + { + name: "Queue only one slash data", + dataToQueue: []throttledPacketDataInstance{ + {IbcSeqNum: 1, Data: someSlashData[0]}, + }, + expectedSlashFound: true, + expectedSlashData: someSlashData[0], + expectedVSCMaturedData: []ccvtypes.VSCMaturedPacketData{}, + expectedIBCSeqNums: []uint64{1}, + }, + { + name: "Queue two vsc matured behind slash data", + dataToQueue: []throttledPacketDataInstance{ + {IbcSeqNum: 80, Data: someSlashData[3]}, + {IbcSeqNum: 82, Data: someVSCMaturedData[0]}, + {IbcSeqNum: 83, Data: someVSCMaturedData[1]}, + }, + expectedSlashFound: true, + expectedSlashData: someSlashData[3], + expectedVSCMaturedData: []ccvtypes.VSCMaturedPacketData{someVSCMaturedData[0], someVSCMaturedData[1]}, + expectedIBCSeqNums: []uint64{80, 82, 83}, + }, + { + name: "Queue two vsc matured behind 4 slash data", + dataToQueue: []throttledPacketDataInstance{ + {IbcSeqNum: 80, Data: someSlashData[1]}, // Only returned value + {IbcSeqNum: 82, Data: someSlashData[2]}, + {IbcSeqNum: 83, Data: someSlashData[3]}, + {IbcSeqNum: 84, Data: someSlashData[4]}, + {IbcSeqNum: 85, Data: someVSCMaturedData[1]}, + {IbcSeqNum: 86, Data: someVSCMaturedData[2]}, + }, + expectedSlashFound: true, + expectedSlashData: someSlashData[1], + expectedVSCMaturedData: []ccvtypes.VSCMaturedPacketData{}, + expectedIBCSeqNums: []uint64{80}, + }, + { + name: "Queue vsc matured data behind slash data, ending with another slash data", + dataToQueue: []throttledPacketDataInstance{ + {IbcSeqNum: 47238, Data: someSlashData[1]}, + {IbcSeqNum: 47239, Data: someVSCMaturedData[0]}, + {IbcSeqNum: 47240, Data: someVSCMaturedData[1]}, + {IbcSeqNum: 47241, Data: someVSCMaturedData[2]}, + {IbcSeqNum: 47242, Data: someVSCMaturedData[3]}, + {IbcSeqNum: 47243, Data: someSlashData[2]}, // Not returned + }, + expectedSlashFound: true, + expectedSlashData: someSlashData[1], + expectedVSCMaturedData: []ccvtypes.VSCMaturedPacketData{ + someVSCMaturedData[0], someVSCMaturedData[1], someVSCMaturedData[2], someVSCMaturedData[3], + }, + expectedIBCSeqNums: []uint64{47238, 47239, 47240, 47241, 47242}, + }, + } + + for _, tc := range testCases { + + providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) + defer ctrl.Finish() + providerKeeper.SetParams(ctx, providertypes.DefaultParams()) + + // Queue a slash and vsc matured packet data for some random chain. + // These values should never be returned. + providerKeeper.QueueThrottledSlashPacketData(ctx, "some-rando-chain", 77, testkeeper.GetNewSlashPacketData()) + providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "some-rando-chain", 97, testkeeper.GetNewVSCMaturedPacketData()) + + // Queue the data to test + for _, dataInstance := range tc.dataToQueue { + providerKeeper.QueueThrottledPacketData(ctx, "chain-49", dataInstance.IbcSeqNum, dataInstance.Data) + } + + // Retrieve the data, and assert that it is correct + slashFound, slashData, vscMaturedData, ibcSeqNums := providerKeeper.GetSlashAndTrailingData(ctx, "chain-49") + require.Equal(t, tc.expectedSlashFound, slashFound, tc.name) + require.Equal(t, tc.expectedSlashData, slashData, tc.name) + require.Equal(t, tc.expectedVSCMaturedData, vscMaturedData, tc.name) + require.Equal(t, tc.expectedIBCSeqNums, ibcSeqNums, tc.name) + } +} + // TestDeleteThrottledPacketDataForConsumer tests the DeleteThrottledPacketDataForConsumer method. func TestDeleteThrottledPacketDataForConsumer(t *testing.T) { diff --git a/x/ccv/provider/types/consumer.go b/x/ccv/provider/types/consumer.go index dfbd862cfe..de2d4cb4bf 100644 --- a/x/ccv/provider/types/consumer.go +++ b/x/ccv/provider/types/consumer.go @@ -11,7 +11,7 @@ func NewConsumerStates( channelID string, initialHeight uint64, genesis consumertypes.GenesisState, - unbondingOpsIndexes []UnbondingOpIndex, + unbondingOpsIndexes []VscUnbondingOps, pendingValsetChanges []ccv.ValidatorSetChangePacketData, slashDowntimeAck []string, ) ConsumerState { diff --git a/x/ccv/provider/types/genesis.go b/x/ccv/provider/types/genesis.go index 5cecaab19f..2237114e99 100644 --- a/x/ccv/provider/types/genesis.go +++ b/x/ccv/provider/types/genesis.go @@ -13,7 +13,7 @@ func NewGenesisState( vscID uint64, vscIdToHeights []ValsetUpdateIdToHeight, consumerStates []ConsumerState, - unbondingOps []ccv.UnbondingOp, + unbondingOps []UnbondingOp, matureUbdOps *ccv.MaturedUnbondingOps, additionProposals []ConsumerAdditionProposal, removalProposals []ConsumerRemovalProposal, @@ -122,10 +122,10 @@ func (cs ConsumerState) Validate() error { } for _, ubdOpIdx := range cs.UnbondingOpsIndex { - if ubdOpIdx.ValsetUpdateId == 0 { + if ubdOpIdx.VscId == 0 { return fmt.Errorf("valset update ID cannot be equal to zero") } - if len(ubdOpIdx.UnbondingOpIndex) == 0 { + if len(ubdOpIdx.UnbondingOpIds) == 0 { return fmt.Errorf("unbonding operation index cannot be empty: %#v", ubdOpIdx) } } diff --git a/x/ccv/provider/types/genesis.pb.go b/x/ccv/provider/types/genesis.pb.go index ed1cffcf32..e60b42a4ea 100644 --- a/x/ccv/provider/types/genesis.pb.go +++ b/x/ccv/provider/types/genesis.pb.go @@ -33,7 +33,7 @@ type GenesisState struct { // empty for a new chain ConsumerStates []ConsumerState `protobuf:"bytes,2,rep,name=consumer_states,json=consumerStates,proto3" json:"consumer_states" yaml:"consumer_states"` // empty for a new chain - UnbondingOps []types.UnbondingOp `protobuf:"bytes,3,rep,name=unbonding_ops,json=unbondingOps,proto3" json:"unbonding_ops"` + UnbondingOps []UnbondingOp `protobuf:"bytes,3,rep,name=unbonding_ops,json=unbondingOps,proto3" json:"unbonding_ops"` // empty for a new chain MatureUnbondingOps *types.MaturedUnbondingOps `protobuf:"bytes,4,opt,name=mature_unbonding_ops,json=matureUnbondingOps,proto3" json:"mature_unbonding_ops,omitempty"` // empty for a new chain @@ -98,7 +98,7 @@ func (m *GenesisState) GetConsumerStates() []ConsumerState { return nil } -func (m *GenesisState) GetUnbondingOps() []types.UnbondingOp { +func (m *GenesisState) GetUnbondingOps() []UnbondingOp { if m != nil { return m.UnbondingOps } @@ -176,8 +176,8 @@ type ConsumerState struct { // PendingValsetChanges defines the pending validator set changes for the consumer chain PendingValsetChanges []types.ValidatorSetChangePacketData `protobuf:"bytes,6,rep,name=pending_valset_changes,json=pendingValsetChanges,proto3" json:"pending_valset_changes"` SlashDowntimeAck []string `protobuf:"bytes,7,rep,name=slash_downtime_ack,json=slashDowntimeAck,proto3" json:"slash_downtime_ack,omitempty"` - // UnbondingOpsIndex defines the unbonding operations on the consumer chain - UnbondingOpsIndex []UnbondingOpIndex `protobuf:"bytes,8,rep,name=unbonding_ops_index,json=unbondingOpsIndex,proto3" json:"unbonding_ops_index"` + // UnbondingOpsIndex defines the unbonding operations waiting on this consumer chain + UnbondingOpsIndex []VscUnbondingOps `protobuf:"bytes,8,rep,name=unbonding_ops_index,json=unbondingOpsIndex,proto3" json:"unbonding_ops_index"` } func (m *ConsumerState) Reset() { *m = ConsumerState{} } @@ -262,67 +262,13 @@ func (m *ConsumerState) GetSlashDowntimeAck() []string { return nil } -func (m *ConsumerState) GetUnbondingOpsIndex() []UnbondingOpIndex { +func (m *ConsumerState) GetUnbondingOpsIndex() []VscUnbondingOps { if m != nil { return m.UnbondingOpsIndex } return nil } -// UnbondingOpIndex defines the genesis information for each unbonding operations index -// referenced by chain id and valset udpate id -type UnbondingOpIndex struct { - ValsetUpdateId uint64 `protobuf:"varint,1,opt,name=valset_update_id,json=valsetUpdateId,proto3" json:"valset_update_id,omitempty"` - UnbondingOpIndex []uint64 `protobuf:"varint,2,rep,packed,name=unbonding_op_index,json=unbondingOpIndex,proto3" json:"unbonding_op_index,omitempty"` -} - -func (m *UnbondingOpIndex) Reset() { *m = UnbondingOpIndex{} } -func (m *UnbondingOpIndex) String() string { return proto.CompactTextString(m) } -func (*UnbondingOpIndex) ProtoMessage() {} -func (*UnbondingOpIndex) Descriptor() ([]byte, []int) { - return fileDescriptor_48411d9c7900d48e, []int{2} -} -func (m *UnbondingOpIndex) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnbondingOpIndex) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnbondingOpIndex.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnbondingOpIndex) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnbondingOpIndex.Merge(m, src) -} -func (m *UnbondingOpIndex) XXX_Size() int { - return m.Size() -} -func (m *UnbondingOpIndex) XXX_DiscardUnknown() { - xxx_messageInfo_UnbondingOpIndex.DiscardUnknown(m) -} - -var xxx_messageInfo_UnbondingOpIndex proto.InternalMessageInfo - -func (m *UnbondingOpIndex) GetValsetUpdateId() uint64 { - if m != nil { - return m.ValsetUpdateId - } - return 0 -} - -func (m *UnbondingOpIndex) GetUnbondingOpIndex() []uint64 { - if m != nil { - return m.UnbondingOpIndex - } - return nil -} - // ValsetUpdateIdToHeight defines the genesis information for the mapping // of each valset udpate id to a block height type ValsetUpdateIdToHeight struct { @@ -334,7 +280,7 @@ func (m *ValsetUpdateIdToHeight) Reset() { *m = ValsetUpdateIdToHeight{} func (m *ValsetUpdateIdToHeight) String() string { return proto.CompactTextString(m) } func (*ValsetUpdateIdToHeight) ProtoMessage() {} func (*ValsetUpdateIdToHeight) Descriptor() ([]byte, []int) { - return fileDescriptor_48411d9c7900d48e, []int{3} + return fileDescriptor_48411d9c7900d48e, []int{2} } func (m *ValsetUpdateIdToHeight) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -389,7 +335,7 @@ func (m *ValidatorConsumerPubKey) Reset() { *m = ValidatorConsumerPubKey func (m *ValidatorConsumerPubKey) String() string { return proto.CompactTextString(m) } func (*ValidatorConsumerPubKey) ProtoMessage() {} func (*ValidatorConsumerPubKey) Descriptor() ([]byte, []int) { - return fileDescriptor_48411d9c7900d48e, []int{4} + return fileDescriptor_48411d9c7900d48e, []int{3} } func (m *ValidatorConsumerPubKey) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -451,7 +397,7 @@ func (m *ValidatorByConsumerAddr) Reset() { *m = ValidatorByConsumerAddr func (m *ValidatorByConsumerAddr) String() string { return proto.CompactTextString(m) } func (*ValidatorByConsumerAddr) ProtoMessage() {} func (*ValidatorByConsumerAddr) Descriptor() ([]byte, []int) { - return fileDescriptor_48411d9c7900d48e, []int{5} + return fileDescriptor_48411d9c7900d48e, []int{4} } func (m *ValidatorByConsumerAddr) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -513,7 +459,7 @@ func (m *ConsumerAddrsToPrune) Reset() { *m = ConsumerAddrsToPrune{} } func (m *ConsumerAddrsToPrune) String() string { return proto.CompactTextString(m) } func (*ConsumerAddrsToPrune) ProtoMessage() {} func (*ConsumerAddrsToPrune) Descriptor() ([]byte, []int) { - return fileDescriptor_48411d9c7900d48e, []int{6} + return fileDescriptor_48411d9c7900d48e, []int{5} } func (m *ConsumerAddrsToPrune) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -566,7 +512,6 @@ func (m *ConsumerAddrsToPrune) GetConsumerAddrs() *AddressList { func init() { proto.RegisterType((*GenesisState)(nil), "interchain_security.ccv.provider.v1.GenesisState") proto.RegisterType((*ConsumerState)(nil), "interchain_security.ccv.provider.v1.ConsumerState") - proto.RegisterType((*UnbondingOpIndex)(nil), "interchain_security.ccv.provider.v1.UnbondingOpIndex") proto.RegisterType((*ValsetUpdateIdToHeight)(nil), "interchain_security.ccv.provider.v1.ValsetUpdateIdToHeight") proto.RegisterType((*ValidatorConsumerPubKey)(nil), "interchain_security.ccv.provider.v1.ValidatorConsumerPubKey") proto.RegisterType((*ValidatorByConsumerAddr)(nil), "interchain_security.ccv.provider.v1.ValidatorByConsumerAddr") @@ -578,70 +523,69 @@ func init() { } var fileDescriptor_48411d9c7900d48e = []byte{ - // 1007 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xdd, 0x8e, 0xdb, 0x44, - 0x14, 0x5e, 0x77, 0xb3, 0xdb, 0xcd, 0x24, 0x59, 0xc2, 0xb0, 0xa4, 0x6e, 0xb6, 0xa4, 0xab, 0x14, - 0xc4, 0x4a, 0x14, 0x9b, 0x04, 0x21, 0x41, 0x01, 0xa1, 0x6e, 0x2b, 0x41, 0xb4, 0x20, 0x22, 0x77, - 0x5b, 0xa4, 0xde, 0x58, 0x93, 0xf1, 0x28, 0x19, 0xe2, 0x78, 0x2c, 0xcf, 0xd8, 0xd4, 0x42, 0x20, - 0x7e, 0x5e, 0x80, 0x6b,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 0xe1, 0x4f, 0x1a, 0x68, 0xe7, 0x2a, 0x02, 0x32, 0x63, 0x11, 0x72, 0x0b, 0x22, 0xae, 0x4b, - 0x11, 0x9f, 0x6c, 0x24, 0xc2, 0x4a, 0xb3, 0xcc, 0x69, 0xd0, 0xf1, 0x62, 0x98, 0xc3, 0x01, 0xd8, - 0xf5, 0x51, 0x80, 0x66, 0x5c, 0xdf, 0x93, 0x97, 0xfb, 0xce, 0x5a, 0x6c, 0x43, 0x19, 0xa2, 0x92, - 0xab, 0x04, 0xb2, 0x9a, 0x08, 0xb9, 0xd4, 0x41, 0x82, 0x05, 0x76, 0x5e, 0x97, 0x1f, 0x8e, 0x92, - 0x31, 0xd3, 0xab, 0x1b, 0x54, 0xf3, 0x24, 0x4b, 0x93, 0x95, 0x35, 0x0c, 0x47, 0xa7, 0x24, 0xce, - 0xaa, 0x89, 0x16, 0xc0, 0x09, 0x07, 0xfc, 0x59, 0x03, 0x87, 0x39, 0xc8, 0xed, 0x51, 0x6c, 0x17, - 0x2f, 0x39, 0xd0, 0xc1, 0xff, 0xd1, 0x70, 0x12, 0x17, 0x6e, 0x38, 0xb8, 0xa2, 0x81, 0x97, 0x71, - 0x18, 0x81, 0x1b, 0x25, 0x52, 0x9e, 0xf4, 0xb5, 0x1f, 0x84, 0x1e, 0xd1, 0x6b, 0x92, 0xfe, 0xa3, - 0x4d, 0xbb, 0x2a, 0xe0, 0x67, 0x6c, 0x98, 0x24, 0x50, 0xdc, 0x07, 0x78, 0x01, 0xd6, 0xfd, 0xa5, - 0x02, 0x1a, 0x25, 0x2b, 0x81, 0x37, 0xc1, 0x5e, 0x4a, 0xa2, 0x9c, 0xab, 0x6a, 0x5d, 0x97, 0xff, - 0x07, 0x0e, 0x7c, 0x03, 0x00, 0x3c, 0x41, 0x9e, 0x47, 0xdc, 0x04, 0xbc, 0x26, 0xc1, 0xaa, 0x5a, - 0x19, 0x38, 0xf0, 0x10, 0x54, 0xb1, 0x4b, 0x89, 0x27, 0x12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xe5, 0x57, 0xa3, 0x88, 0x7d, 0xc2, 0x47, 0xbb, 0xf2, 0xad, 0xf6, - 0xfe, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xec, 0xbc, 0x77, 0x59, 0xfa, 0x0a, 0x00, 0x00, + // 984 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xd1, 0x6e, 0xe3, 0x44, + 0x17, 0xae, 0xdb, 0x34, 0xdb, 0x4c, 0x92, 0xfe, 0xfd, 0x87, 0x92, 0xf5, 0xa6, 0x4b, 0xb6, 0xca, + 0x82, 0x54, 0x09, 0xb0, 0x49, 0xe0, 0x02, 0x16, 0x10, 0xda, 0xee, 0x4a, 0x10, 0x15, 0x44, 0xe4, + 0xed, 0x2e, 0xd2, 0x72, 0x61, 0x4d, 0xc6, 0xa3, 0x64, 0x88, 0xed, 0xb1, 0x3c, 0x63, 0xb3, 0x16, + 0x02, 0xb1, 0xe2, 0x05, 0xb8, 0xe6, 0x8e, 0xa7, 0x61, 0x2f, 0xf7, 0x92, 0xab, 0x15, 0x6a, 0xdf, + 0x80, 0x27, 0x40, 0x1e, 0x8f, 0x5d, 0xbb, 0x4d, 0x4a, 0xc2, 0x5d, 0x72, 0xbe, 0x39, 0xe7, 0xfb, + 0xce, 0xcc, 0x9c, 0x6f, 0x0c, 0x06, 0xd4, 0x17, 0x24, 0xc4, 0x33, 0x44, 0x7d, 0x9b, 0x13, 0x1c, + 0x85, 0x54, 0x24, 0x26, 0xc6, 0xb1, 0x19, 0x84, 0x2c, 0xa6, 0x0e, 0x09, 0xcd, 0x78, 0x60, 0x4e, + 0x89, 0x4f, 0x38, 0xe5, 0x46, 0x10, 0x32, 0xc1, 0xe0, 0xdd, 0x05, 0x29, 0x06, 0xc6, 0xb1, 0x91, + 0xa7, 0x18, 0xf1, 0xa0, 0xbb, 0x3f, 0x65, 0x53, 0x26, 0xd7, 0x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9f, 0xbf, 0x9a, 0xb5, 0x1d, 0x73, 0x3c, 0x72, 0xe0, 0x37, 0x60, 0xb7, 0xea, 0x1f, 0x6a, 0x37, + 0x56, 0x7b, 0xda, 0x53, 0x72, 0xc2, 0xf9, 0x97, 0x94, 0x0b, 0xab, 0x5d, 0xf1, 0x89, 0xe3, 0xd3, + 0x17, 0x67, 0x3d, 0xed, 0xe5, 0x59, 0x4f, 0xfb, 0xeb, 0xac, 0xa7, 0xfd, 0x7a, 0xde, 0xdb, 0x78, + 0x79, 0xde, 0xdb, 0xf8, 0xf3, 0xbc, 0xb7, 0xf1, 0xf4, 0xde, 0x94, 0x8a, 0x59, 0x34, 0x31, 0x30, + 0xf3, 0x4c, 0xcc, 0xb8, 0xc7, 0xb8, 0x79, 0xc1, 0xf5, 0x6e, 0xf1, 0x9d, 0xf5, 0xac, 0xfa, 0x45, + 0x27, 0x92, 0x80, 0xf0, 0x49, 0x5d, 0x7e, 0x47, 0xbd, 0xff, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x81, 0xaf, 0x62, 0x9d, 0x96, 0x0a, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -902,52 +846,6 @@ func (m *ConsumerState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *UnbondingOpIndex) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnbondingOpIndex) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UnbondingOpIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.UnbondingOpIndex) > 0 { - dAtA5 := make([]byte, len(m.UnbondingOpIndex)*10) - var j4 int - for _, num := range m.UnbondingOpIndex { - for num >= 1<<7 { - dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j4++ - } - dAtA5[j4] = uint8(num) - j4++ - } - i -= j4 - copy(dAtA[i:], dAtA5[:j4]) - i = encodeVarintGenesis(dAtA, i, uint64(j4)) - i-- - dAtA[i] = 0x12 - } - if m.ValsetUpdateId != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.ValsetUpdateId)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func (m *ValsetUpdateIdToHeight) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1242,25 +1140,6 @@ func (m *ConsumerState) Size() (n int) { return n } -func (m *UnbondingOpIndex) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ValsetUpdateId != 0 { - n += 1 + sovGenesis(uint64(m.ValsetUpdateId)) - } - if len(m.UnbondingOpIndex) > 0 { - l = 0 - for _, e := range m.UnbondingOpIndex { - l += sovGenesis(uint64(e)) - } - n += 1 + sovGenesis(uint64(l)) + l - } - return n -} - func (m *ValsetUpdateIdToHeight) Size() (n int) { if m == nil { return 0 @@ -1455,7 +1334,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UnbondingOps = append(m.UnbondingOps, types.UnbondingOp{}) + m.UnbondingOps = append(m.UnbondingOps, UnbondingOp{}) if err := m.UnbondingOps[len(m.UnbondingOps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2026,7 +1905,7 @@ func (m *ConsumerState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UnbondingOpsIndex = append(m.UnbondingOpsIndex, UnbondingOpIndex{}) + m.UnbondingOpsIndex = append(m.UnbondingOpsIndex, VscUnbondingOps{}) if err := m.UnbondingOpsIndex[len(m.UnbondingOpsIndex)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2052,151 +1931,6 @@ func (m *ConsumerState) Unmarshal(dAtA []byte) error { } return nil } -func (m *UnbondingOpIndex) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnbondingOpIndex: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnbondingOpIndex: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ValsetUpdateId", wireType) - } - m.ValsetUpdateId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ValsetUpdateId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnbondingOpIndex = append(m.UnbondingOpIndex, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.UnbondingOpIndex) == 0 { - m.UnbondingOpIndex = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnbondingOpIndex = append(m.UnbondingOpIndex, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field UnbondingOpIndex", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *ValsetUpdateIdToHeight) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/ccv/provider/types/genesis_test.go b/x/ccv/provider/types/genesis_test.go index ca43ca4c3a..e65b39b268 100644 --- a/x/ccv/provider/types/genesis_test.go +++ b/x/ccv/provider/types/genesis_test.go @@ -126,7 +126,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultValsetUpdateID, nil, nil, - []ccv.UnbondingOp{{UnbondingConsumerChains: nil}}, + []types.UnbondingOp{{UnbondingConsumerChains: nil}}, nil, nil, nil, @@ -491,7 +491,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultValsetUpdateID, nil, []types.ConsumerState{{ChainId: "chainid", ChannelId: "channel-0", ClientId: "client-id", - UnbondingOpsIndex: []types.UnbondingOpIndex{{}}}}, + UnbondingOpsIndex: []types.VscUnbondingOps{{}}}}, nil, nil, nil, @@ -509,7 +509,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultValsetUpdateID, nil, []types.ConsumerState{{ChainId: "chainid", ChannelId: "channel-0", ClientId: "client-id", - UnbondingOpsIndex: []types.UnbondingOpIndex{{ValsetUpdateId: 1}}}}, + UnbondingOpsIndex: []types.VscUnbondingOps{{VscId: 1}}}}, nil, nil, nil, diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index 3f8a3beeb0..30a473b90d 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -73,14 +73,14 @@ const ( PendingCRPBytePrefix // UnbondingOpBytePrefix is the byte prefix that stores a record of all the ids of consumer chains that - // need to unbond before a given delegation can unbond on this chain. + // need to unbond before a given unbonding operation can unbond on this chain. UnbondingOpBytePrefix // UnbondingOpIndexBytePrefix is byte prefix of the index for looking up which unbonding - // delegation entries are waiting for a given consumer chain to unbond + // operations are waiting for a given consumer chain to unbond UnbondingOpIndexBytePrefix - // ValsetUpdateBlockHeightBytePrefix is the byte prefix that will store the mapping from valset update ID to block height + // ValsetUpdateBlockHeightBytePrefix is the byte prefix that will store the mapping from vscIDs to block heights ValsetUpdateBlockHeightBytePrefix // ConsumerGenesisBytePrefix stores consumer genesis state material (consensus state and client state) indexed by consumer chain id @@ -169,25 +169,32 @@ func InitTimeoutTimestampKey(chainID string) []byte { return append([]byte{InitTimeoutTimestampBytePrefix}, []byte(chainID)...) } -// PendingCAPKey returns the key under which a pending consumer addition proposal is stored +// PendingCAPKey returns the key under which a pending consumer addition proposal is stored. +// The key has the following format: PendingCAPBytePrefix | timestamp.UnixNano() | chainID func PendingCAPKey(timestamp time.Time, chainID string) []byte { - return TsAndChainIdKey(PendingCAPBytePrefix, timestamp, chainID) -} - -// ParsePendingCAPKey returns the time and chain ID for a pending consumer addition proposal key -// or an error if unparsable -func ParsePendingCAPKey(bz []byte) (time.Time, string, error) { - return ParseTsAndChainIdKey(PendingCAPBytePrefix, bz) + ts := uint64(timestamp.UTC().UnixNano()) + return AppendMany( + // Append the prefix + []byte{PendingCAPBytePrefix}, + // Append the time + sdk.Uint64ToBigEndian(ts), + // Append the chainId + []byte(chainID), + ) } -// PendingCRPKey returns the key under which pending consumer removal proposals are stored +// PendingCRPKey returns the key under which pending consumer removal proposals are stored. +// The key has the following format: PendingCRPBytePrefix | timestamp.UnixNano() | chainID func PendingCRPKey(timestamp time.Time, chainID string) []byte { - return TsAndChainIdKey(PendingCRPBytePrefix, timestamp, chainID) -} - -// ParsePendingCRPKey returns the time and chain ID for a pending consumer removal proposal key or an error if unparseable -func ParsePendingCRPKey(bz []byte) (time.Time, string, error) { - return ParseTsAndChainIdKey(PendingCRPBytePrefix, bz) + ts := uint64(timestamp.UTC().UnixNano()) + return AppendMany( + // Append the prefix + []byte{PendingCRPBytePrefix}, + // Append the time + sdk.Uint64ToBigEndian(ts), + // Append the chainId + []byte(chainID), + ) } // UnbondingOpIndexKey returns an unbonding op index key @@ -204,7 +211,7 @@ func ParseUnbondingOpIndexKey(key []byte) (string, uint64, error) { } // UnbondingOpKey returns the key that stores a record of all the ids of consumer chains that -// need to unbond before a given delegation can unbond on this chain +// need to unbond before a given unbonding operation can unbond on this chain. func UnbondingOpKey(id uint64) []byte { bz := make([]byte, 8) binary.BigEndian.PutUint64(bz, id) @@ -342,42 +349,6 @@ func AppendMany(byteses ...[]byte) (out []byte) { return out } -// TsAndChainIdKey returns the key with the following format: -// bytePrefix | len(timestamp) | timestamp | chainID -func TsAndChainIdKey(prefix byte, timestamp time.Time, chainID string) []byte { - timeBz := sdk.FormatTimeBytes(timestamp) - timeBzL := len(timeBz) - - return AppendMany( - // Append the prefix - []byte{prefix}, - // Append the time length - sdk.Uint64ToBigEndian(uint64(timeBzL)), - // Append the time bytes - timeBz, - // Append the chainId - []byte(chainID), - ) -} - -// ParseTsAndChainIdKey returns the time and chain ID for a TsAndChainId key -func ParseTsAndChainIdKey(prefix byte, bz []byte) (time.Time, string, error) { - expectedPrefix := []byte{prefix} - prefixL := len(expectedPrefix) - if prefix := bz[:prefixL]; !bytes.Equal(prefix, expectedPrefix) { - return time.Time{}, "", fmt.Errorf("invalid prefix; expected: %X, got: %X", expectedPrefix, prefix) - } - - timeBzL := sdk.BigEndianToUint64(bz[prefixL : prefixL+8]) - timestamp, err := sdk.ParseTimeBytes(bz[prefixL+8 : prefixL+8+int(timeBzL)]) - if err != nil { - return time.Time{}, "", err - } - - chainID := string(bz[prefixL+8+int(timeBzL):]) - return timestamp, chainID, nil -} - // ChainIdAndTsKey returns the key with the following format: // bytePrefix | len(chainID) | chainID | timestamp func ChainIdAndTsKey(prefix byte, chainID string, timestamp time.Time) []byte { diff --git a/x/ccv/provider/types/keys_test.go b/x/ccv/provider/types/keys_test.go index f3da9f1ec8..cc5a96e09f 100644 --- a/x/ccv/provider/types/keys_test.go +++ b/x/ccv/provider/types/keys_test.go @@ -70,32 +70,6 @@ func getSingleByteKeys() [][]byte { return keys[:i] } -// Tests the construction and parsing of TsAndChainId keys -func TestTsAndChainIdKeyAndParse(t *testing.T) { - tests := []struct { - prefix byte - timestamp time.Time - chainID string - }{ - {prefix: 0x01, timestamp: time.Now(), chainID: "1"}, - {prefix: 0x02, timestamp: time.Date( - 2003, 11, 17, 20, 34, 58, 651387237, time.UTC), chainID: "some other ID"}, - {prefix: 0x03, timestamp: time.Now().Add(5000 * time.Hour), chainID: "some other other chain ID"}, - } - - for _, test := range tests { - key := providertypes.TsAndChainIdKey(test.prefix, test.timestamp, test.chainID) - require.NotEmpty(t, key) - // Expected bytes = prefix + time length + time bytes + length of chainID - expectedLen := 1 + 8 + len(sdk.FormatTimeBytes(time.Time{})) + len(test.chainID) - require.Equal(t, expectedLen, len(key)) - parsedTime, parsedID, err := providertypes.ParseTsAndChainIdKey(test.prefix, key) - require.Equal(t, test.timestamp.UTC(), parsedTime.UTC()) - require.Equal(t, test.chainID, parsedID) - require.NoError(t, err) - } -} - // Tests the construction and parsing of ChainIdAndTs keys func TestChainIdAndTsKeyAndParse(t *testing.T) { tests := []struct { diff --git a/x/ccv/provider/types/provider.pb.go b/x/ccv/provider/types/provider.pb.go index b1b3511f07..b89bf21a76 100644 --- a/x/ccv/provider/types/provider.pb.go +++ b/x/ccv/provider/types/provider.pb.go @@ -10,6 +10,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" _ "google.golang.org/protobuf/types/known/durationpb" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" @@ -194,8 +195,7 @@ type GlobalSlashEntry struct { // The provider's consensus address of the validator being slashed. // This field is used to obtain validator power in HandleThrottleQueues. // - // This field is not used in the store key, but is persisted in value bytes, - // see QueueGlobalSlashEntry. + // This field is not used in the store key, but is persisted in value bytes, see QueueGlobalSlashEntry. ProviderValConsAddr []byte `protobuf:"bytes,4,opt,name=provider_val_cons_addr,json=providerValConsAddr,proto3" json:"provider_val_cons_addr,omitempty"` } @@ -608,6 +608,331 @@ func (m *AddressList) GetAddresses() [][]byte { return nil } +type ChannelToChain struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *ChannelToChain) Reset() { *m = ChannelToChain{} } +func (m *ChannelToChain) String() string { return proto.CompactTextString(m) } +func (*ChannelToChain) ProtoMessage() {} +func (*ChannelToChain) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{9} +} +func (m *ChannelToChain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ChannelToChain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ChannelToChain.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ChannelToChain) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChannelToChain.Merge(m, src) +} +func (m *ChannelToChain) XXX_Size() int { + return m.Size() +} +func (m *ChannelToChain) XXX_DiscardUnknown() { + xxx_messageInfo_ChannelToChain.DiscardUnknown(m) +} + +var xxx_messageInfo_ChannelToChain proto.InternalMessageInfo + +func (m *ChannelToChain) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *ChannelToChain) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +// VscUnbondingOps contains the IDs of unbonding operations that are waiting for +// at least one VSCMaturedPacket with vscID from a consumer chain +type VscUnbondingOps struct { + VscId uint64 `protobuf:"varint,1,opt,name=vsc_id,json=vscId,proto3" json:"vsc_id,omitempty"` + UnbondingOpIds []uint64 `protobuf:"varint,2,rep,packed,name=unbonding_op_ids,json=unbondingOpIds,proto3" json:"unbonding_op_ids,omitempty"` +} + +func (m *VscUnbondingOps) Reset() { *m = VscUnbondingOps{} } +func (m *VscUnbondingOps) String() string { return proto.CompactTextString(m) } +func (*VscUnbondingOps) ProtoMessage() {} +func (*VscUnbondingOps) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{10} +} +func (m *VscUnbondingOps) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VscUnbondingOps) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VscUnbondingOps.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VscUnbondingOps) XXX_Merge(src proto.Message) { + xxx_messageInfo_VscUnbondingOps.Merge(m, src) +} +func (m *VscUnbondingOps) XXX_Size() int { + return m.Size() +} +func (m *VscUnbondingOps) XXX_DiscardUnknown() { + xxx_messageInfo_VscUnbondingOps.DiscardUnknown(m) +} + +var xxx_messageInfo_VscUnbondingOps proto.InternalMessageInfo + +func (m *VscUnbondingOps) GetVscId() uint64 { + if m != nil { + return m.VscId + } + return 0 +} + +func (m *VscUnbondingOps) GetUnbondingOpIds() []uint64 { + if m != nil { + return m.UnbondingOpIds + } + return nil +} + +// UnbondingOp contains the ids of consumer chains that need to unbond before +// the unbonding operation with the given ID can unbond +type UnbondingOp struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + // consumer chains that are still unbonding + UnbondingConsumerChains []string `protobuf:"bytes,2,rep,name=unbonding_consumer_chains,json=unbondingConsumerChains,proto3" json:"unbonding_consumer_chains,omitempty"` +} + +func (m *UnbondingOp) Reset() { *m = UnbondingOp{} } +func (m *UnbondingOp) String() string { return proto.CompactTextString(m) } +func (*UnbondingOp) ProtoMessage() {} +func (*UnbondingOp) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{11} +} +func (m *UnbondingOp) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UnbondingOp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UnbondingOp.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UnbondingOp) XXX_Merge(src proto.Message) { + xxx_messageInfo_UnbondingOp.Merge(m, src) +} +func (m *UnbondingOp) XXX_Size() int { + return m.Size() +} +func (m *UnbondingOp) XXX_DiscardUnknown() { + xxx_messageInfo_UnbondingOp.DiscardUnknown(m) +} + +var xxx_messageInfo_UnbondingOp proto.InternalMessageInfo + +func (m *UnbondingOp) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *UnbondingOp) GetUnbondingConsumerChains() []string { + if m != nil { + return m.UnbondingConsumerChains + } + return nil +} + +type InitTimeoutTimestamp struct { + ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + Timestamp uint64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (m *InitTimeoutTimestamp) Reset() { *m = InitTimeoutTimestamp{} } +func (m *InitTimeoutTimestamp) String() string { return proto.CompactTextString(m) } +func (*InitTimeoutTimestamp) ProtoMessage() {} +func (*InitTimeoutTimestamp) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{12} +} +func (m *InitTimeoutTimestamp) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *InitTimeoutTimestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_InitTimeoutTimestamp.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *InitTimeoutTimestamp) XXX_Merge(src proto.Message) { + xxx_messageInfo_InitTimeoutTimestamp.Merge(m, src) +} +func (m *InitTimeoutTimestamp) XXX_Size() int { + return m.Size() +} +func (m *InitTimeoutTimestamp) XXX_DiscardUnknown() { + xxx_messageInfo_InitTimeoutTimestamp.DiscardUnknown(m) +} + +var xxx_messageInfo_InitTimeoutTimestamp proto.InternalMessageInfo + +func (m *InitTimeoutTimestamp) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *InitTimeoutTimestamp) GetTimestamp() uint64 { + if m != nil { + return m.Timestamp + } + return 0 +} + +type VscSendTimestamp struct { + VscId uint64 `protobuf:"varint,1,opt,name=vsc_id,json=vscId,proto3" json:"vsc_id,omitempty"` + Timestamp time.Time `protobuf:"bytes,2,opt,name=timestamp,proto3,stdtime" json:"timestamp"` +} + +func (m *VscSendTimestamp) Reset() { *m = VscSendTimestamp{} } +func (m *VscSendTimestamp) String() string { return proto.CompactTextString(m) } +func (*VscSendTimestamp) ProtoMessage() {} +func (*VscSendTimestamp) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{13} +} +func (m *VscSendTimestamp) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VscSendTimestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VscSendTimestamp.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VscSendTimestamp) XXX_Merge(src proto.Message) { + xxx_messageInfo_VscSendTimestamp.Merge(m, src) +} +func (m *VscSendTimestamp) XXX_Size() int { + return m.Size() +} +func (m *VscSendTimestamp) XXX_DiscardUnknown() { + xxx_messageInfo_VscSendTimestamp.DiscardUnknown(m) +} + +var xxx_messageInfo_VscSendTimestamp proto.InternalMessageInfo + +func (m *VscSendTimestamp) GetVscId() uint64 { + if m != nil { + return m.VscId + } + return 0 +} + +func (m *VscSendTimestamp) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} + +type KeyAssignmentReplacement struct { + ProviderAddr []byte `protobuf:"bytes,1,opt,name=provider_addr,json=providerAddr,proto3" json:"provider_addr,omitempty"` + PrevCKey *crypto.PublicKey `protobuf:"bytes,2,opt,name=prev_c_key,json=prevCKey,proto3" json:"prev_c_key,omitempty"` + Power int64 `protobuf:"varint,3,opt,name=power,proto3" json:"power,omitempty"` +} + +func (m *KeyAssignmentReplacement) Reset() { *m = KeyAssignmentReplacement{} } +func (m *KeyAssignmentReplacement) String() string { return proto.CompactTextString(m) } +func (*KeyAssignmentReplacement) ProtoMessage() {} +func (*KeyAssignmentReplacement) Descriptor() ([]byte, []int) { + return fileDescriptor_f22ec409a72b7b72, []int{14} +} +func (m *KeyAssignmentReplacement) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *KeyAssignmentReplacement) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_KeyAssignmentReplacement.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *KeyAssignmentReplacement) XXX_Merge(src proto.Message) { + xxx_messageInfo_KeyAssignmentReplacement.Merge(m, src) +} +func (m *KeyAssignmentReplacement) XXX_Size() int { + return m.Size() +} +func (m *KeyAssignmentReplacement) XXX_DiscardUnknown() { + xxx_messageInfo_KeyAssignmentReplacement.DiscardUnknown(m) +} + +var xxx_messageInfo_KeyAssignmentReplacement proto.InternalMessageInfo + +func (m *KeyAssignmentReplacement) GetProviderAddr() []byte { + if m != nil { + return m.ProviderAddr + } + return nil +} + +func (m *KeyAssignmentReplacement) GetPrevCKey() *crypto.PublicKey { + if m != nil { + return m.PrevCKey + } + return nil +} + +func (m *KeyAssignmentReplacement) GetPower() int64 { + if m != nil { + return m.Power + } + return 0 +} + func init() { proto.RegisterType((*ConsumerAdditionProposal)(nil), "interchain_security.ccv.provider.v1.ConsumerAdditionProposal") proto.RegisterType((*ConsumerRemovalProposal)(nil), "interchain_security.ccv.provider.v1.ConsumerRemovalProposal") @@ -618,6 +943,12 @@ func init() { proto.RegisterType((*ConsumerAdditionProposals)(nil), "interchain_security.ccv.provider.v1.ConsumerAdditionProposals") proto.RegisterType((*ConsumerRemovalProposals)(nil), "interchain_security.ccv.provider.v1.ConsumerRemovalProposals") proto.RegisterType((*AddressList)(nil), "interchain_security.ccv.provider.v1.AddressList") + proto.RegisterType((*ChannelToChain)(nil), "interchain_security.ccv.provider.v1.ChannelToChain") + proto.RegisterType((*VscUnbondingOps)(nil), "interchain_security.ccv.provider.v1.VscUnbondingOps") + proto.RegisterType((*UnbondingOp)(nil), "interchain_security.ccv.provider.v1.UnbondingOp") + proto.RegisterType((*InitTimeoutTimestamp)(nil), "interchain_security.ccv.provider.v1.InitTimeoutTimestamp") + proto.RegisterType((*VscSendTimestamp)(nil), "interchain_security.ccv.provider.v1.VscSendTimestamp") + proto.RegisterType((*KeyAssignmentReplacement)(nil), "interchain_security.ccv.provider.v1.KeyAssignmentReplacement") } func init() { @@ -625,76 +956,91 @@ func init() { } var fileDescriptor_f22ec409a72b7b72 = []byte{ - // 1090 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdc, 0x36, - 0x10, 0x5e, 0xd5, 0x1b, 0xdb, 0xcb, 0x75, 0x62, 0x9b, 0xce, 0x8f, 0xec, 0x06, 0xbb, 0x9b, 0x6d, - 0x0f, 0x2e, 0x82, 0x48, 0xb0, 0x73, 0x29, 0x82, 0x16, 0x85, 0xbd, 0x6e, 0xe2, 0x02, 0x4d, 0xba, - 0x91, 0x17, 0x29, 0xd0, 0x1e, 0x04, 0x8a, 0xa2, 0x57, 0x84, 0x25, 0x51, 0x21, 0xb9, 0xaa, 0xfd, - 0x06, 0x3d, 0x06, 0xe8, 0x25, 0xc7, 0xbc, 0x41, 0x5f, 0x23, 0xc7, 0x1c, 0x7b, 0x4a, 0x0b, 0xfb, - 0xd8, 0x5b, 0x9f, 0xa0, 0x20, 0x29, 0x69, 0x7f, 0xe2, 0x00, 0x6b, 0x14, 0xbd, 0x89, 0x33, 0xdf, - 0x7c, 0x9c, 0xe1, 0x7c, 0x1c, 0x11, 0xec, 0xd2, 0x54, 0x12, 0x8e, 0x23, 0x44, 0x53, 0x5f, 0x10, - 0x3c, 0xe2, 0x54, 0x9e, 0xb9, 0x18, 0xe7, 0x6e, 0xc6, 0x59, 0x4e, 0x43, 0xc2, 0xdd, 0x7c, 0xa7, - 0xfa, 0x76, 0x32, 0xce, 0x24, 0x83, 0x9f, 0x5d, 0x12, 0xe3, 0x60, 0x9c, 0x3b, 0x15, 0x2e, 0xdf, - 0xd9, 0xba, 0x39, 0x64, 0x43, 0xa6, 0xf1, 0xae, 0xfa, 0x32, 0xa1, 0x5b, 0xed, 0x21, 0x63, 0xc3, - 0x98, 0xb8, 0x7a, 0x15, 0x8c, 0x8e, 0x5d, 0x49, 0x13, 0x22, 0x24, 0x4a, 0xb2, 0x02, 0xd0, 0x9a, - 0x05, 0x84, 0x23, 0x8e, 0x24, 0x65, 0x69, 0x49, 0x40, 0x03, 0xec, 0x62, 0xc6, 0x89, 0x8b, 0x63, - 0x4a, 0x52, 0xa9, 0xd2, 0x33, 0x5f, 0x05, 0xc0, 0x55, 0x80, 0x98, 0x0e, 0x23, 0x69, 0xcc, 0xc2, - 0x95, 0x24, 0x0d, 0x09, 0x4f, 0xa8, 0x01, 0x8f, 0x57, 0x26, 0xa0, 0xfb, 0xdb, 0x22, 0xb0, 0x7b, - 0x2c, 0x15, 0xa3, 0x84, 0xf0, 0xbd, 0x30, 0xa4, 0x6a, 0xb3, 0x3e, 0x67, 0x19, 0x13, 0x28, 0x86, - 0x37, 0xc1, 0x35, 0x49, 0x65, 0x4c, 0x6c, 0xab, 0x63, 0x6d, 0x37, 0x3c, 0xb3, 0x80, 0x1d, 0xd0, - 0x0c, 0x89, 0xc0, 0x9c, 0x66, 0x0a, 0x6c, 0x7f, 0xa2, 0x7d, 0x93, 0x26, 0xb8, 0x09, 0x96, 0xcd, - 0xf9, 0xd0, 0xd0, 0x5e, 0xd0, 0xee, 0x25, 0xbd, 0xfe, 0x2e, 0x84, 0x4f, 0xc0, 0x0d, 0x9a, 0x52, - 0x49, 0x51, 0xec, 0x47, 0x44, 0xe5, 0x69, 0xd7, 0x3b, 0xd6, 0x76, 0x73, 0x77, 0xcb, 0xa1, 0x01, - 0x76, 0x54, 0x69, 0x4e, 0x51, 0x50, 0xbe, 0xe3, 0x1c, 0x6a, 0xc4, 0x7e, 0xfd, 0xed, 0xfb, 0x76, - 0xcd, 0xbb, 0x5e, 0xc4, 0x19, 0x23, 0xbc, 0x07, 0x56, 0x86, 0x24, 0x25, 0x82, 0x0a, 0x3f, 0x42, - 0x22, 0xb2, 0xaf, 0x75, 0xac, 0xed, 0x15, 0xaf, 0x59, 0xd8, 0x0e, 0x91, 0x88, 0x60, 0x1b, 0x34, - 0x03, 0x9a, 0x22, 0x7e, 0x66, 0x10, 0x8b, 0x1a, 0x01, 0x8c, 0x49, 0x03, 0x7a, 0x00, 0x88, 0x0c, - 0xfd, 0x92, 0xfa, 0xaa, 0x0f, 0xf6, 0x52, 0x91, 0x88, 0xe9, 0x81, 0x53, 0xf6, 0xc0, 0x19, 0x94, - 0x4d, 0xda, 0x5f, 0x56, 0x89, 0xbc, 0xfa, 0xb3, 0x6d, 0x79, 0x0d, 0x1d, 0xa7, 0x3c, 0xf0, 0x19, - 0x58, 0x1b, 0xa5, 0x01, 0x4b, 0x43, 0x9a, 0x0e, 0xfd, 0x8c, 0x70, 0xca, 0x42, 0x7b, 0x59, 0x53, - 0x6d, 0x7e, 0x40, 0x75, 0x50, 0xb4, 0xd3, 0x30, 0xbd, 0x56, 0x4c, 0xab, 0x55, 0x70, 0x5f, 0xc7, - 0xc2, 0xe7, 0x00, 0x62, 0x9c, 0xeb, 0x94, 0xd8, 0x48, 0x96, 0x8c, 0x8d, 0xf9, 0x19, 0xd7, 0x30, - 0xce, 0x07, 0x26, 0xba, 0xa0, 0xfc, 0x19, 0xdc, 0x91, 0x1c, 0xa5, 0xe2, 0x98, 0xf0, 0x59, 0x5e, - 0x30, 0x3f, 0xef, 0xad, 0x92, 0x63, 0x9a, 0xfc, 0x10, 0x74, 0x70, 0x21, 0x20, 0x9f, 0x93, 0x90, - 0x0a, 0xc9, 0x69, 0x30, 0x52, 0xb1, 0xfe, 0x31, 0x47, 0x58, 0x6b, 0xa4, 0xa9, 0x45, 0xd0, 0x2a, - 0x71, 0xde, 0x14, 0xec, 0x71, 0x81, 0x82, 0x3f, 0x80, 0xcf, 0x83, 0x98, 0xe1, 0x13, 0xa1, 0x92, - 0xf3, 0xa7, 0x98, 0xf4, 0xd6, 0x09, 0x15, 0x42, 0xb1, 0xad, 0x74, 0xac, 0xed, 0x05, 0xef, 0x9e, - 0xc1, 0xf6, 0x09, 0x3f, 0x98, 0x40, 0x0e, 0x26, 0x80, 0xf0, 0x01, 0x80, 0x11, 0x15, 0x92, 0x71, - 0x8a, 0x51, 0xec, 0x93, 0x54, 0x72, 0x4a, 0x84, 0x7d, 0x5d, 0x87, 0xaf, 0x8f, 0x3d, 0xdf, 0x1a, - 0xc7, 0xa3, 0xe5, 0x5f, 0xdf, 0xb4, 0x6b, 0xaf, 0xdf, 0xb4, 0x6b, 0xdd, 0xdf, 0x2d, 0x70, 0xa7, - 0x57, 0x25, 0x9b, 0xb0, 0x1c, 0xc5, 0xff, 0xe7, 0xa5, 0xd8, 0x03, 0x0d, 0x21, 0x59, 0x66, 0x64, - 0x58, 0xbf, 0x82, 0x0c, 0x97, 0x55, 0x98, 0x72, 0x74, 0xff, 0xb6, 0xc0, 0xda, 0x93, 0x98, 0x05, - 0x28, 0x3e, 0x8a, 0x91, 0x88, 0x54, 0x49, 0x67, 0x8a, 0x97, 0x93, 0x42, 0x4b, 0x3a, 0xdd, 0xb9, - 0x79, 0x55, 0x98, 0x56, 0xf7, 0x37, 0x60, 0xbd, 0xea, 0x6e, 0x95, 0xbe, 0xae, 0x6e, 0x7f, 0xe3, - 0xfc, 0x7d, 0x7b, 0xb5, 0x3c, 0xa5, 0x9e, 0x2e, 0xe5, 0xc0, 0x5b, 0xc5, 0x53, 0x86, 0x10, 0xb6, - 0x40, 0x93, 0x06, 0xd8, 0x17, 0xe4, 0xa5, 0x9f, 0x8e, 0x12, 0x5d, 0x79, 0xdd, 0x6b, 0xd0, 0x00, - 0x1f, 0x91, 0x97, 0xcf, 0x46, 0x09, 0x7c, 0x08, 0x6e, 0x97, 0x83, 0xd3, 0xcf, 0x51, 0xec, 0xab, - 0x78, 0x1f, 0x85, 0x21, 0xd7, 0x07, 0xb1, 0xe2, 0x6d, 0x94, 0xde, 0x17, 0x28, 0x56, 0x9b, 0xed, - 0x85, 0x21, 0xef, 0xfe, 0x53, 0x07, 0x8b, 0x7d, 0xc4, 0x51, 0x22, 0xe0, 0x00, 0xac, 0x4a, 0x92, - 0x64, 0x31, 0x92, 0xc4, 0x37,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0x00, 0x00, + // 1339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4b, 0x6f, 0xdc, 0x36, + 0x10, 0xb6, 0xec, 0xf5, 0x63, 0xb9, 0x8e, 0x1f, 0x74, 0x1e, 0x72, 0xea, 0xae, 0x37, 0x9b, 0x1e, + 0x5c, 0x04, 0xd1, 0xc2, 0xce, 0xa5, 0x30, 0x5a, 0x14, 0xf6, 0xa6, 0x89, 0xdd, 0x34, 0x89, 0x23, + 0xbb, 0x2e, 0xda, 0x1e, 0x04, 0x8a, 0xa2, 0x77, 0x09, 0x4b, 0xa2, 0x42, 0x72, 0x95, 0xec, 0x3f, + 0xe8, 0x31, 0x45, 0x2f, 0x39, 0xe6, 0x1f, 0xf4, 0x6f, 0xe4, 0x98, 0x63, 0x4f, 0x69, 0xe1, 0x1c, + 0x7b, 0xeb, 0x2f, 0x28, 0x48, 0xea, 0xb1, 0xda, 0x38, 0x80, 0x83, 0xa2, 0x37, 0x71, 0xe6, 0x9b, + 0x8f, 0x33, 0x9c, 0x07, 0x29, 0xb0, 0x45, 0x63, 0x49, 0x38, 0xee, 0x23, 0x1a, 0x7b, 0x82, 0xe0, + 0x01, 0xa7, 0x72, 0xd8, 0xc1, 0x38, 0xed, 0x24, 0x9c, 0xa5, 0x34, 0x20, 0xbc, 0x93, 0x6e, 0x16, + 0xdf, 0x4e, 0xc2, 0x99, 0x64, 0xf0, 0xe6, 0x39, 0x36, 0x0e, 0xc6, 0xa9, 0x53, 0xe0, 0xd2, 0xcd, + 0xeb, 0x97, 0x7b, 0xac, 0xc7, 0x34, 0xbe, 0xa3, 0xbe, 0x8c, 0xe9, 0xf5, 0xf5, 0x1e, 0x63, 0xbd, + 0x90, 0x74, 0xf4, 0xca, 0x1f, 0x9c, 0x74, 0x24, 0x8d, 0x88, 0x90, 0x28, 0x4a, 0x32, 0x40, 0x73, + 0x1c, 0x10, 0x0c, 0x38, 0x92, 0x94, 0xc5, 0x39, 0x01, 0xf5, 0x71, 0x07, 0x33, 0x4e, 0x3a, 0x38, + 0xa4, 0x24, 0x96, 0xca, 0x3d, 0xf3, 0x95, 0x01, 0x3a, 0x0a, 0x10, 0xd2, 0x5e, 0x5f, 0x1a, 0xb1, + 0xe8, 0x48, 0x12, 0x07, 0x84, 0x47, 0xd4, 0x80, 0xcb, 0x55, 0x66, 0xb0, 0x36, 0xa2, 0xc7, 0x7c, + 0x98, 0x48, 0xd6, 0x39, 0x25, 0x43, 0x61, 0xb4, 0xed, 0xdf, 0x66, 0x80, 0xdd, 0x65, 0xb1, 0x18, + 0x44, 0x84, 0xef, 0x04, 0x01, 0x55, 0xae, 0x1c, 0x70, 0x96, 0x30, 0x81, 0x42, 0x78, 0x19, 0x4c, + 0x4b, 0x2a, 0x43, 0x62, 0x5b, 0x2d, 0x6b, 0xa3, 0xee, 0x9a, 0x05, 0x6c, 0x81, 0x46, 0x40, 0x04, + 0xe6, 0x34, 0x51, 0x60, 0x7b, 0x52, 0xeb, 0x46, 0x45, 0x70, 0x15, 0xcc, 0x99, 0xd3, 0xa3, 0x81, + 0x3d, 0xa5, 0xd5, 0xb3, 0x7a, 0xbd, 0x1f, 0xc0, 0xfb, 0x60, 0x81, 0xc6, 0x54, 0x52, 0x14, 0x7a, + 0x7d, 0xa2, 0xa2, 0xb0, 0x6b, 0x2d, 0x6b, 0xa3, 0xb1, 0x75, 0xdd, 0xa1, 0x3e, 0x76, 0x54, 0xe0, + 0x4e, 0x16, 0x6e, 0xba, 0xe9, 0xec, 0x69, 0xc4, 0x6e, 0xed, 0xf5, 0xdb, 0xf5, 0x09, 0xf7, 0x52, + 0x66, 0x67, 0x84, 0xf0, 0x06, 0x98, 0xef, 0x91, 0x98, 0x08, 0x2a, 0xbc, 0x3e, 0x12, 0x7d, 0x7b, + 0xba, 0x65, 0x6d, 0xcc, 0xbb, 0x8d, 0x4c, 0xb6, 0x87, 0x44, 0x1f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a, 0xd6, 0x8b, + 0x77, 0xcd, 0x89, 0x37, 0xef, 0x9a, 0x13, 0x7f, 0xbc, 0x6b, 0x4e, 0xfc, 0xb4, 0xdd, 0xa3, 0xb2, + 0x3f, 0xf0, 0x1d, 0xcc, 0xa2, 0x0e, 0x66, 0x22, 0x62, 0xa2, 0x53, 0x56, 0xfb, 0xed, 0xe2, 0x5f, + 0xe3, 0x79, 0xf5, 0x6f, 0x43, 0x0e, 0x13, 0x22, 0xfc, 0x19, 0x7d, 0x24, 0x77, 0xfe, 0x0d, 0x00, + 0x00, 0xff, 0xff, 0x23, 0xe7, 0x0b, 0x44, 0x9e, 0x0c, 0x00, 0x00, } func (m *ConsumerAdditionProposal) Marshal() (dAtA []byte, err error) { @@ -1177,47 +1523,285 @@ func (m *AddressList) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarintProvider(dAtA []byte, offset int, v uint64) int { - offset -= sovProvider(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *ChannelToChain) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - dAtA[offset] = uint8(v) - return base + return dAtA[:n], nil } -func (m *ConsumerAdditionProposal) Size() (n int) { - if m == nil { - return 0 - } + +func (m *ChannelToChain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ChannelToChain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovProvider(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovProvider(uint64(l)) - } - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovProvider(uint64(l)) + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintProvider(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x12 } - l = m.InitialHeight.Size() - n += 1 + l + sovProvider(uint64(l)) - l = len(m.GenesisHash) - if l > 0 { - n += 1 + l + sovProvider(uint64(l)) + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintProvider(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa } - l = len(m.BinaryHash) - if l > 0 { - n += 1 + l + sovProvider(uint64(l)) + return len(dAtA) - i, nil +} + +func (m *VscUnbondingOps) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.SpawnTime) - n += 1 + l + sovProvider(uint64(l)) + return dAtA[:n], nil +} + +func (m *VscUnbondingOps) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VscUnbondingOps) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UnbondingOpIds) > 0 { + dAtA14 := make([]byte, len(m.UnbondingOpIds)*10) + var j13 int + for _, num := range m.UnbondingOpIds { + for num >= 1<<7 { + dAtA14[j13] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j13++ + } + dAtA14[j13] = uint8(num) + j13++ + } + i -= j13 + copy(dAtA[i:], dAtA14[:j13]) + i = encodeVarintProvider(dAtA, i, uint64(j13)) + i-- + dAtA[i] = 0x12 + } + if m.VscId != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.VscId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *UnbondingOp) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UnbondingOp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UnbondingOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UnbondingConsumerChains) > 0 { + for iNdEx := len(m.UnbondingConsumerChains) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.UnbondingConsumerChains[iNdEx]) + copy(dAtA[i:], m.UnbondingConsumerChains[iNdEx]) + i = encodeVarintProvider(dAtA, i, uint64(len(m.UnbondingConsumerChains[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if m.Id != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *InitTimeoutTimestamp) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *InitTimeoutTimestamp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *InitTimeoutTimestamp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Timestamp != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.Timestamp)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintProvider(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *VscSendTimestamp) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *VscSendTimestamp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VscSendTimestamp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n15, err15 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):]) + if err15 != nil { + return 0, err15 + } + i -= n15 + i = encodeVarintProvider(dAtA, i, uint64(n15)) + i-- + dAtA[i] = 0x12 + if m.VscId != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.VscId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *KeyAssignmentReplacement) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *KeyAssignmentReplacement) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *KeyAssignmentReplacement) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Power != 0 { + i = encodeVarintProvider(dAtA, i, uint64(m.Power)) + i-- + dAtA[i] = 0x18 + } + if m.PrevCKey != nil { + { + size, err := m.PrevCKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProvider(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ProviderAddr) > 0 { + i -= len(m.ProviderAddr) + copy(dAtA[i:], m.ProviderAddr) + i = encodeVarintProvider(dAtA, i, uint64(len(m.ProviderAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintProvider(dAtA []byte, offset int, v uint64) int { + offset -= sovProvider(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ConsumerAdditionProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = m.InitialHeight.Size() + n += 1 + l + sovProvider(uint64(l)) + l = len(m.GenesisHash) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = len(m.BinaryHash) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.SpawnTime) + n += 1 + l + sovProvider(uint64(l)) l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.UnbondingPeriod) n += 1 + l + sovProvider(uint64(l)) l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.CcvTimeoutPeriod) @@ -1391,6 +1975,110 @@ func (m *AddressList) Size() (n int) { return n } +func (m *ChannelToChain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + return n +} + +func (m *VscUnbondingOps) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.VscId != 0 { + n += 1 + sovProvider(uint64(m.VscId)) + } + if len(m.UnbondingOpIds) > 0 { + l = 0 + for _, e := range m.UnbondingOpIds { + l += sovProvider(uint64(e)) + } + n += 1 + sovProvider(uint64(l)) + l + } + return n +} + +func (m *UnbondingOp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovProvider(uint64(m.Id)) + } + if len(m.UnbondingConsumerChains) > 0 { + for _, s := range m.UnbondingConsumerChains { + l = len(s) + n += 1 + l + sovProvider(uint64(l)) + } + } + return n +} + +func (m *InitTimeoutTimestamp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + if m.Timestamp != 0 { + n += 1 + sovProvider(uint64(m.Timestamp)) + } + return n +} + +func (m *VscSendTimestamp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.VscId != 0 { + n += 1 + sovProvider(uint64(m.VscId)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovProvider(uint64(l)) + return n +} + +func (m *KeyAssignmentReplacement) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ProviderAddr) + if l > 0 { + n += 1 + l + sovProvider(uint64(l)) + } + if m.PrevCKey != nil { + l = m.PrevCKey.Size() + n += 1 + l + sovProvider(uint64(l)) + } + if m.Power != 0 { + n += 1 + sovProvider(uint64(m.Power)) + } + return n +} + func sovProvider(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2940,6 +3628,708 @@ func (m *AddressList) Unmarshal(dAtA []byte) error { } return nil } +func (m *ChannelToChain) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ChannelToChain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ChannelToChain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *VscUnbondingOps) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VscUnbondingOps: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VscUnbondingOps: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VscId", wireType) + } + m.VscId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VscId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.UnbondingOpIds = append(m.UnbondingOpIds, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.UnbondingOpIds) == 0 { + m.UnbondingOpIds = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.UnbondingOpIds = append(m.UnbondingOpIds, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field UnbondingOpIds", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UnbondingOp) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UnbondingOp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UnbondingOp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UnbondingConsumerChains", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UnbondingConsumerChains = append(m.UnbondingConsumerChains, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *InitTimeoutTimestamp) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: InitTimeoutTimestamp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: InitTimeoutTimestamp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + m.Timestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Timestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *VscSendTimestamp) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VscSendTimestamp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VscSendTimestamp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VscId", wireType) + } + m.VscId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VscId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *KeyAssignmentReplacement) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: KeyAssignmentReplacement: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: KeyAssignmentReplacement: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProviderAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProviderAddr = append(m.ProviderAddr[:0], dAtA[iNdEx:postIndex]...) + if m.ProviderAddr == nil { + m.ProviderAddr = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrevCKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProvider + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProvider + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PrevCKey == nil { + m.PrevCKey = &crypto.PublicKey{} + } + if err := m.PrevCKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Power", wireType) + } + m.Power = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProvider + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Power |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProvider(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProvider + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipProvider(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/ccv/provider/types/unbonding_delegation_entries.go b/x/ccv/provider/types/unbonding_delegation_entries.go deleted file mode 100644 index 18cf573eea..0000000000 --- a/x/ccv/provider/types/unbonding_delegation_entries.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - ccv "github.com/cosmos/interchain-security/x/ccv/types" -) - -func MustUnmarshalUnbondingOp(cdc codec.BinaryCodec, value []byte) ccv.UnbondingOp { - delegation, err := UnmarshalUnbondingOp(cdc, value) - if err != nil { - panic(err) - } - - return delegation -} - -func UnmarshalUnbondingOp(cdc codec.BinaryCodec, value []byte) (unbondingOp ccv.UnbondingOp, err error) { - err = cdc.Unmarshal(value, &unbondingOp) - return unbondingOp, err -} diff --git a/x/ccv/types/ccv.pb.go b/x/ccv/types/ccv.pb.go index b9bce4c948..cfa70fb4bd 100644 --- a/x/ccv/types/ccv.pb.go +++ b/x/ccv/types/ccv.pb.go @@ -137,59 +137,6 @@ func (m *ValidatorSetChangePackets) GetList() []ValidatorSetChangePacketData { return nil } -type UnbondingOp struct { - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // consumer chains that are still unbonding - UnbondingConsumerChains []string `protobuf:"bytes,2,rep,name=unbonding_consumer_chains,json=unbondingConsumerChains,proto3" json:"unbonding_consumer_chains,omitempty"` -} - -func (m *UnbondingOp) Reset() { *m = UnbondingOp{} } -func (m *UnbondingOp) String() string { return proto.CompactTextString(m) } -func (*UnbondingOp) ProtoMessage() {} -func (*UnbondingOp) Descriptor() ([]byte, []int) { - return fileDescriptor_68bd5f3242e6f29c, []int{2} -} -func (m *UnbondingOp) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnbondingOp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnbondingOp.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnbondingOp) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnbondingOp.Merge(m, src) -} -func (m *UnbondingOp) XXX_Size() int { - return m.Size() -} -func (m *UnbondingOp) XXX_DiscardUnknown() { - xxx_messageInfo_UnbondingOp.DiscardUnknown(m) -} - -var xxx_messageInfo_UnbondingOp proto.InternalMessageInfo - -func (m *UnbondingOp) GetId() uint64 { - if m != nil { - return m.Id - } - return 0 -} - -func (m *UnbondingOp) GetUnbondingConsumerChains() []string { - if m != nil { - return m.UnbondingConsumerChains - } - return nil -} - // This packet is sent from the consumer chain to the provider chain // to notify that a VSC packet reached maturity on the consumer chain. type VSCMaturedPacketData struct { @@ -201,7 +148,7 @@ func (m *VSCMaturedPacketData) Reset() { *m = VSCMaturedPacketData{} } func (m *VSCMaturedPacketData) String() string { return proto.CompactTextString(m) } func (*VSCMaturedPacketData) ProtoMessage() {} func (*VSCMaturedPacketData) Descriptor() ([]byte, []int) { - return fileDescriptor_68bd5f3242e6f29c, []int{3} + return fileDescriptor_68bd5f3242e6f29c, []int{2} } func (m *VSCMaturedPacketData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -252,7 +199,7 @@ func (m *SlashPacketData) Reset() { *m = SlashPacketData{} } func (m *SlashPacketData) String() string { return proto.CompactTextString(m) } func (*SlashPacketData) ProtoMessage() {} func (*SlashPacketData) Descriptor() ([]byte, []int) { - return fileDescriptor_68bd5f3242e6f29c, []int{4} + return fileDescriptor_68bd5f3242e6f29c, []int{3} } func (m *SlashPacketData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -302,51 +249,6 @@ func (m *SlashPacketData) GetInfraction() types1.InfractionType { return types1.InfractionEmpty } -// UnbondingOpsIndex defines a list of unbonding operation ids. -type UnbondingOpsIndex struct { - Ids []uint64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"` -} - -func (m *UnbondingOpsIndex) Reset() { *m = UnbondingOpsIndex{} } -func (m *UnbondingOpsIndex) String() string { return proto.CompactTextString(m) } -func (*UnbondingOpsIndex) ProtoMessage() {} -func (*UnbondingOpsIndex) Descriptor() ([]byte, []int) { - return fileDescriptor_68bd5f3242e6f29c, []int{5} -} -func (m *UnbondingOpsIndex) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnbondingOpsIndex) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnbondingOpsIndex.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnbondingOpsIndex) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnbondingOpsIndex.Merge(m, src) -} -func (m *UnbondingOpsIndex) XXX_Size() int { - return m.Size() -} -func (m *UnbondingOpsIndex) XXX_DiscardUnknown() { - xxx_messageInfo_UnbondingOpsIndex.DiscardUnknown(m) -} - -var xxx_messageInfo_UnbondingOpsIndex proto.InternalMessageInfo - -func (m *UnbondingOpsIndex) GetIds() []uint64 { - if m != nil { - return m.Ids - } - return nil -} - // MaturedUnbondingOps defines a list of ids corresponding to ids of matured unbonding operations. type MaturedUnbondingOps struct { Ids []uint64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"` @@ -356,7 +258,7 @@ func (m *MaturedUnbondingOps) Reset() { *m = MaturedUnbondingOps{} } func (m *MaturedUnbondingOps) String() string { return proto.CompactTextString(m) } func (*MaturedUnbondingOps) ProtoMessage() {} func (*MaturedUnbondingOps) Descriptor() ([]byte, []int) { - return fileDescriptor_68bd5f3242e6f29c, []int{6} + return fileDescriptor_68bd5f3242e6f29c, []int{4} } func (m *MaturedUnbondingOps) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -395,10 +297,8 @@ func (m *MaturedUnbondingOps) GetIds() []uint64 { func init() { proto.RegisterType((*ValidatorSetChangePacketData)(nil), "interchain_security.ccv.v1.ValidatorSetChangePacketData") proto.RegisterType((*ValidatorSetChangePackets)(nil), "interchain_security.ccv.v1.ValidatorSetChangePackets") - proto.RegisterType((*UnbondingOp)(nil), "interchain_security.ccv.v1.UnbondingOp") proto.RegisterType((*VSCMaturedPacketData)(nil), "interchain_security.ccv.v1.VSCMaturedPacketData") proto.RegisterType((*SlashPacketData)(nil), "interchain_security.ccv.v1.SlashPacketData") - proto.RegisterType((*UnbondingOpsIndex)(nil), "interchain_security.ccv.v1.UnbondingOpsIndex") proto.RegisterType((*MaturedUnbondingOps)(nil), "interchain_security.ccv.v1.MaturedUnbondingOps") } @@ -407,41 +307,38 @@ func init() { } var fileDescriptor_68bd5f3242e6f29c = []byte{ - // 541 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x8e, 0x93, 0x08, 0xa9, 0x1b, 0x29, 0xa4, 0xa6, 0x12, 0x6e, 0x00, 0xd7, 0x5a, 0x15, 0xc8, - 0x85, 0xb5, 0x12, 0x2e, 0xa8, 0x27, 0x48, 0x10, 0x52, 0x84, 0x10, 0xc8, 0xa1, 0x95, 0xe0, 0x62, - 0x6d, 0x76, 0x17, 0x67, 0x95, 0x64, 0x37, 0xf2, 0xae, 0xad, 0xe6, 0x2d, 0x78, 0xac, 0x1e, 0x7b, - 0xa3, 0xa7, 0x0a, 0x25, 0x6f, 0xc0, 0x13, 0x20, 0xaf, 0x9d, 0x1f, 0x68, 0x82, 0xc4, 0x29, 0x93, - 0xf9, 0xbe, 0xf9, 0xbc, 0xf3, 0xcd, 0x0c, 0x38, 0xe5, 0x42, 0xb3, 0x98, 0x8c, 0x30, 0x17, 0xa1, - 0x62, 0x24, 0x89, 0xb9, 0x9e, 0xfb, 0x84, 0xa4, 0x7e, 0xda, 0xce, 0x7e, 0xd0, 0x2c, 0x96, 0x5a, - 0xda, 0xcd, 0x1d, 0x2c, 0x94, 0xc1, 0x69, 0xbb, 0x79, 0x4a, 0xa4, 0x9a, 0x4a, 0xe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0x7d, 0xe9, 0x96, 0xae, 0x97, 0x6e, 0xe9, 0x66, - 0xe9, 0x96, 0xbe, 0xb6, 0x23, 0xae, 0x47, 0xc9, 0x10, 0x11, 0x39, 0xf5, 0x8b, 0x83, 0xdc, 0xec, - 0xcd, 0x8b, 0xf5, 0x65, 0x5f, 0x9a, 0xdb, 0x36, 0x57, 0x36, 0xbc, 0x67, 0xce, 0xec, 0xe5, 0xef, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xf2, 0xc0, 0x56, 0x1d, 0x03, 0x04, 0x00, 0x00, + // 483 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0xcd, 0x92, 0x08, 0x29, 0x5b, 0xa9, 0x04, 0xd3, 0x83, 0x09, 0xe0, 0x5a, 0x56, 0x05, 0xbe, + 0xb0, 0x96, 0xc3, 0x05, 0x71, 0x82, 0x14, 0x21, 0x55, 0x08, 0x81, 0x36, 0xb4, 0x07, 0x2e, 0xd1, + 0x7a, 0xbd, 0x38, 0xab, 0x24, 0xbb, 0x96, 0x77, 0x62, 0x91, 0x7f, 0xc1, 0xcf, 0xea, 0xb1, 0x37, + 0x7a, 0xaa, 0x50, 0xf2, 0x0f, 0xf8, 0x05, 0xc8, 0x1f, 0xf9, 0x00, 0x12, 0xa4, 0x9e, 0x3c, 0x9e, + 0x79, 0xf3, 0xa4, 0xf7, 0xf6, 0x0d, 0x3e, 0x91, 0x0a, 0x44, 0xc6, 0x47, 0x4c, 0xaa, 0xa1, 0x11, + 0x7c, 0x96, 0x49, 0x98, 0x07, 0x9c, 0xe7, 0x41, 0x1e, 0x16, 0x1f, 0x92, 0x66, 0x1a, 0xb4, 0xd5, + 0xdd, 0x81, 0x22, 0xc5, 0x38, 0x0f, 0xbb, 0x27, 0x5c, 0x9b, 0xa9, 0x36, 0x81, 0x01, 0x36, 0x96, + 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, 0xde, 0x6b, 0x7c, 0x74, 0x31, 0x38, 0xfd, 0xc0, 0x60, 0x96, 0x89, + 0x78, 0xcb, 0xc2, 0x5d, 0x8a, 0xd0, 0x2e, 0x45, 0xde, 0x0f, 0x84, 0xef, 0x0d, 0x0a, 0x01, 0x5b, + 0xdb, 0x14, 0xb7, 0xd7, 0x1e, 0x95, 0x6b, 0x07, 0xbd, 0xee, 0x7e, 0xe3, 0xfb, 0x76, 0x6d, 0x79, + 0xe7, 0x2f, 0xcb, 0x3d, 0xba, 0xa1, 0xb9, 0x85, 0xc7, 0xef, 0x30, 0x96, 0xea, 0x6b, 0xc6, 0x38, + 0x48, 0xad, 0xec, 0xa6, 0x8b, 0xfc, 0xc3, 0xde, 0x53, 0x52, 0xa5, 0x91, 0xac, 0xd2, 0x57, 0xa7, + 0x91, 0x9c, 0xad, 0x91, 0x9f, 0xe7, 0xa9, 0xa0, 0x5b, 0x9b, 0xde, 0x33, 0xfc, 0xa0, 0x36, 0xe6, + 0x5c, 0x45, 0x5a, 0xc5, 0x52, 0x25, 0x1f, 0x53, 0x63, 0x75, 0x70, 0x53, 0xc6, 0x55, 0x9e, 0x5a, + 0xb4, 0x28, 0xfb, 0xef, 0x2f, 0x17, 0x0e, 0xba, 0x5a, 0x38, 0xe8, 0xe7, 0xc2, 0x41, 0xdf, 0x97, + 0x4e, 0xe3, 0x6a, 0xe9, 0x34, 0xae, 0x97, 0x4e, 0xe3, 0x4b, 0x98, 0x48, 0x18, 0xcd, 0x22, 0xc2, + 0xf5, 0x34, 0xa8, 0xcf, 0x61, 0xf3, 0x6a, 0xcf, 0xd7, 0x77, 0xf5, 0xad, 0xbc, 0xac, 0x32, 0xe3, + 0xd1, 0xdd, 0x32, 0xe4, 0x2f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x72, 0x03, 0x3c, 0x5e, 0x81, + 0x03, 0x00, 0x00, } func (m *ValidatorSetChangePacketData) Marshal() (dAtA []byte, err error) { @@ -532,43 +429,6 @@ func (m *ValidatorSetChangePackets) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *UnbondingOp) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnbondingOp) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UnbondingOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.UnbondingConsumerChains) > 0 { - for iNdEx := len(m.UnbondingConsumerChains) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.UnbondingConsumerChains[iNdEx]) - copy(dAtA[i:], m.UnbondingConsumerChains[iNdEx]) - i = encodeVarintCcv(dAtA, i, uint64(len(m.UnbondingConsumerChains[iNdEx]))) - i-- - dAtA[i] = 0x12 - } - } - if m.Id != 0 { - i = encodeVarintCcv(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func (m *VSCMaturedPacketData) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -640,7 +500,7 @@ func (m *SlashPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *UnbondingOpsIndex) Marshal() (dAtA []byte, err error) { +func (m *MaturedUnbondingOps) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -650,12 +510,12 @@ func (m *UnbondingOpsIndex) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *UnbondingOpsIndex) MarshalTo(dAtA []byte) (int, error) { +func (m *MaturedUnbondingOps) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *UnbondingOpsIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MaturedUnbondingOps) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -681,47 +541,6 @@ func (m *UnbondingOpsIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MaturedUnbondingOps) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MaturedUnbondingOps) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MaturedUnbondingOps) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Ids) > 0 { - dAtA5 := make([]byte, len(m.Ids)*10) - var j4 int - for _, num := range m.Ids { - for num >= 1<<7 { - dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j4++ - } - dAtA5[j4] = uint8(num) - j4++ - } - i -= j4 - copy(dAtA[i:], dAtA5[:j4]) - i = encodeVarintCcv(dAtA, i, uint64(j4)) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintCcv(dAtA []byte, offset int, v uint64) int { offset -= sovCcv(v) base := offset @@ -772,24 +591,6 @@ func (m *ValidatorSetChangePackets) Size() (n int) { return n } -func (m *UnbondingOp) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Id != 0 { - n += 1 + sovCcv(uint64(m.Id)) - } - if len(m.UnbondingConsumerChains) > 0 { - for _, s := range m.UnbondingConsumerChains { - l = len(s) - n += 1 + l + sovCcv(uint64(l)) - } - } - return n -} - func (m *VSCMaturedPacketData) Size() (n int) { if m == nil { return 0 @@ -819,22 +620,6 @@ func (m *SlashPacketData) Size() (n int) { return n } -func (m *UnbondingOpsIndex) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Ids) > 0 { - l = 0 - for _, e := range m.Ids { - l += sovCcv(uint64(e)) - } - n += 1 + sovCcv(uint64(l)) + l - } - return n -} - func (m *MaturedUnbondingOps) Size() (n int) { if m == nil { return 0 @@ -1076,107 +861,6 @@ func (m *ValidatorSetChangePackets) Unmarshal(dAtA []byte) error { } return nil } -func (m *UnbondingOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnbondingOp: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnbondingOp: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UnbondingConsumerChains", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthCcv - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthCcv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.UnbondingConsumerChains = append(m.UnbondingConsumerChains, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCcv(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCcv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *VSCMaturedPacketData) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1367,132 +1051,6 @@ func (m *SlashPacketData) Unmarshal(dAtA []byte) error { } return nil } -func (m *UnbondingOpsIndex) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnbondingOpsIndex: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnbondingOpsIndex: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Ids = append(m.Ids, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthCcv - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthCcv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Ids) == 0 { - m.Ids = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCcv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Ids = append(m.Ids, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Ids", wireType) - } - default: - iNdEx = preIndex - skippy, err := skipCcv(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthCcv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *MaturedUnbondingOps) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0