diff --git a/CHANGELOG.md b/CHANGELOG.md index 792e83a7a9..867c9d54c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Add an entry to the unreleased provider section whenever merging a PR to main that is not targeted at a specific release. These entries will eventually be included in a provider release. +* (feat!) [#1230](https://github.com/cosmos/interchain-security/pull/1230) Throttle with retries provider changes. * (feature!) [#1244](https://github.com/cosmos/interchain-security/pull/1244) Update the default consumer unbonding period to 2 weeks. * (deps) [#1259](https://github.com/cosmos/interchain-security/pull/1259) Bump [cosmos-sdk](https://github.com/cosmos/cosmos-sdk) to [v0.47.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.5). * (deps!) [#1258](https://github.com/cosmos/interchain-security/pull/1258) Bump [ibc-go](https://github.com/cosmos/ibc-go) to [v7.3.0](https://github.com/cosmos/ibc-go/releases/tag/v7.3.0). diff --git a/proto/interchain_security/ccv/provider/v1/query.proto b/proto/interchain_security/ccv/provider/v1/query.proto index b0c1dc2b47..089df6bfec 100644 --- a/proto/interchain_security/ccv/provider/v1/query.proto +++ b/proto/interchain_security/ccv/provider/v1/query.proto @@ -65,14 +65,6 @@ service Query { "/interchain_security/ccv/provider/throttle_state"; } - // QueryThrottledConsumerPacketData returns a list of pending packet data - // instances (slash packet and vsc matured) for a single consumer chain - rpc QueryThrottledConsumerPacketData(QueryThrottledConsumerPacketDataRequest) - returns (QueryThrottledConsumerPacketDataResponse) { - option (google.api.http).get = - "/interchain_security/ccv/provider/pending_consumer_packets"; - } - // QueryRegisteredConsumerRewardDenoms returns a list of consumer reward // denoms that are registered rpc QueryRegisteredConsumerRewardDenoms( @@ -151,35 +143,6 @@ message QueryThrottleStateResponse { // full google.protobuf.Timestamp next_replenish_candidate = 3 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; - // data relevant to currently throttled slash packets - repeated ThrottledSlashPacket packets = 4; -} - -message QueryThrottledConsumerPacketDataRequest { string chain_id = 1; } - -message QueryThrottledConsumerPacketDataResponse { - string chain_id = 1; - uint64 size = 2; - repeated ThrottledPacketDataWrapper packetDataInstances = 3 - [ (gogoproto.nullable) = false ]; -} - -// A query wrapper type for the global entry and data relevant to a throttled -// slash packet. -message ThrottledSlashPacket { - interchain_security.ccv.provider.v1.GlobalSlashEntry global_entry = 1 - [ (gogoproto.nullable) = false ]; - interchain_security.ccv.v1.SlashPacketData data = 2 - [ (gogoproto.nullable) = false ]; -} - -// ThrottledPacketDataWrapper contains either SlashPacketData or -// VSCMaturedPacketData -message ThrottledPacketDataWrapper { - oneof data { - interchain_security.ccv.v1.SlashPacketData slash_packet = 1; - interchain_security.ccv.v1.VSCMaturedPacketData vsc_matured_packet = 2; - } } message QueryRegisteredConsumerRewardDenomsRequest {} diff --git a/tests/e2e/actions.go b/tests/e2e/actions.go index fccc27a957..7f31a3b451 100644 --- a/tests/e2e/actions.go +++ b/tests/e2e/actions.go @@ -1937,50 +1937,41 @@ func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbos tr.waitBlocks(chainID("provi"), 2, 30*time.Second) } -// slashThrottleDequeue polls slash queue sizes until nextQueueSize is achieved -type slashThrottleDequeue struct { - chain chainID - currentQueueSize int - nextQueueSize int +// slashMeterReplenishmentAction polls the slash meter on provider until value is achieved +type slashMeterReplenishmentAction struct { + targetValue int64 // panic if timeout is exceeded timeout time.Duration } -func (tr TestRun) waitForSlashThrottleDequeue( - action slashThrottleDequeue, +func (tr TestRun) waitForSlashMeterReplenishment( + action slashMeterReplenishmentAction, verbose bool, ) { timeout := time.Now().Add(action.timeout) - initialGlobalQueueSize := int(tr.getGlobalSlashQueueSize()) + initialSlashMeter := tr.getSlashMeter() - if initialGlobalQueueSize != action.currentQueueSize { - panic(fmt.Sprintf("wrong initial queue size: %d - expected global queue: %d\n", initialGlobalQueueSize, action.currentQueueSize)) + if initialSlashMeter >= 0 { + panic(fmt.Sprintf("No need to wait for slash meter replenishment, current value: %d", initialSlashMeter)) } + for { - globalQueueSize := int(tr.getGlobalSlashQueueSize()) - chainQueueSize := int(tr.getConsumerChainPacketQueueSize(action.chain)) + slashMeter := tr.getSlashMeter() if verbose { - fmt.Printf("waiting for packed queue size to reach: %d - current: %d\n", action.nextQueueSize, globalQueueSize) + fmt.Printf("waiting for slash meter to be replenished, current value: %d\n", slashMeter) } - // check if global queue size is equal to chain queue size - if globalQueueSize == chainQueueSize && globalQueueSize == action.nextQueueSize { //nolint:gocritic // this is the comparison that we want here. + // check if meter has reached target value + if slashMeter >= action.targetValue { break } if time.Now().After(timeout) { - panic(fmt.Sprintf("\n\n\nwaitForSlashThrottleDequeuemethod has timed out after: %s\n\n", action.timeout)) + panic(fmt.Sprintf("\n\nwaitForSlashMeterReplenishment has timed out after: %s\n\n", action.timeout)) } - time.Sleep(500 * time.Millisecond) + tr.WaitTime(5 * time.Second) } - // wair for 2 blocks to be created - // allowing the jailing to be incorporated into voting power - tr.waitBlocks(action.chain, 2, time.Minute) -} - -func uintPointer(i uint) *uint { - return &i } // GetPathNameForGorelayer returns the name of the path between two given chains used by Gorelayer. diff --git a/tests/e2e/main.go b/tests/e2e/main.go index e9336422ae..c8a840f206 100644 --- a/tests/e2e/main.go +++ b/tests/e2e/main.go @@ -242,8 +242,8 @@ func (tr *TestRun) runStep(step Step, verbose bool) { tr.registerRepresentative(action, verbose) case assignConsumerPubKeyAction: tr.assignConsumerPubKey(action, verbose) - case slashThrottleDequeue: - tr.waitForSlashThrottleDequeue(action, verbose) + case slashMeterReplenishmentAction: + tr.waitForSlashMeterReplenishment(action, verbose) case startRelayerAction: tr.startRelayer(action, verbose) case registerConsumerRewardDenomAction: diff --git a/tests/e2e/state.go b/tests/e2e/state.go index 8cc343ef00..57fc06e6c9 100644 --- a/tests/e2e/state.go +++ b/tests/e2e/state.go @@ -168,19 +168,6 @@ func (tr TestRun) getChainState(chain chainID, modelState ChainState) ChainState chainState.ProviderKeys = &providerKeys } - if modelState.GlobalSlashQueueSize != nil { - globalQueueSize := tr.getGlobalSlashQueueSize() - chainState.GlobalSlashQueueSize = &globalQueueSize - } - - if modelState.ConsumerChainQueueSizes != nil { - consumerChainQueueSizes := map[chainID]uint{} - for c := range *modelState.ConsumerChainQueueSizes { - consumerChainQueueSizes[c] = tr.getConsumerChainPacketQueueSize(c) - } - chainState.ConsumerChainQueueSizes = &consumerChainQueueSizes - } - if modelState.RegisteredConsumerRewardDenoms != nil { registeredConsumerRewardDenoms := tr.getRegisteredConsumerRewardDenoms(chain) chainState.RegisteredConsumerRewardDenoms = ®isteredConsumerRewardDenoms @@ -667,9 +654,10 @@ func (tr TestRun) getProviderAddressFromConsumer(consumerChain chainID, validato return addr } -func (tr TestRun) getGlobalSlashQueueSize() uint { +func (tr TestRun) getSlashMeter() int64 { //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. - cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chainID("provi")].binaryName, + cmd := exec.Command("docker", "exec", + tr.containerConfig.instanceName, tr.chainConfigs[chainID("provi")].binaryName, "query", "provider", "throttle-state", `--node`, tr.getQueryNode(chainID("provi")), @@ -680,26 +668,8 @@ func (tr TestRun) getGlobalSlashQueueSize() uint { log.Fatal(err, "\n", string(bz)) } - packets := gjson.Get(string(bz), "packets").Array() - return uint(len(packets)) -} - -func (tr TestRun) getConsumerChainPacketQueueSize(consumerChain chainID) uint { - //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. - cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chainID("provi")].binaryName, - - "query", "provider", "throttled-consumer-packet-data", - string(consumerChain), - `--node`, tr.getQueryNode(chainID("provi")), - `-o`, `json`, - ) - bz, err := cmd.CombinedOutput() - if err != nil { - log.Fatal(err, "\n", string(bz)) - } - - size := gjson.Get(string(bz), "size").Uint() - return uint(size) + slashMeter := gjson.Get(string(bz), "slash_meter") + return slashMeter.Int() } func (tr TestRun) getRegisteredConsumerRewardDenoms(chain chainID) []string { diff --git a/tests/e2e/steps_downtime.go b/tests/e2e/steps_downtime.go index e6d320bec1..f79b945ec0 100644 --- a/tests/e2e/steps_downtime.go +++ b/tests/e2e/steps_downtime.go @@ -56,7 +56,8 @@ func stepsDowntime(consumerName string) []Step { chainID(consumerName): ChainState{ ValPowers: &map[validatorID]uint{ validatorID("alice"): 509, - validatorID("bob"): 500, + // Bob's stake may or may not be slashed at this point depending on comet vs cometmock + // See https://github.com/cosmos/interchain-security/issues/1304 validatorID("carol"): 501, }, }, @@ -278,7 +279,7 @@ func stepsThrottledDowntime(consumerName string) []Step { validator: validatorID("bob"), }, state: State{ - // slash packet queued on consumer, but powers not affected on either chain yet + // slash packet queued for bob on consumer, but powers not affected on either chain yet chainID("provi"): ChainState{ ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, @@ -312,11 +313,6 @@ func stepsThrottledDowntime(consumerName string) []Step { validatorID("bob"): 0, // bob is jailed validatorID("carol"): 500, }, - // no provider throttling engaged yet - GlobalSlashQueueSize: uintPointer(0), - ConsumerChainQueueSizes: &map[chainID]uint{ - chainID(consumerName): uint(0), - }, }, chainID(consumerName): ChainState{ // VSC packet applying jailing is not yet relayed to consumer @@ -328,13 +324,13 @@ func stepsThrottledDowntime(consumerName string) []Step { }, }, }, + // Invoke carol downtime slash on consumer { action: downtimeSlashAction{ chain: chainID(consumerName), validator: validatorID("carol"), }, state: State{ - // powers not affected on either chain yet chainID("provi"): ChainState{ ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, @@ -343,10 +339,9 @@ func stepsThrottledDowntime(consumerName string) []Step { }, }, chainID(consumerName): ChainState{ - // VSC packet applying jailing is not yet relayed to consumer ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, - validatorID("bob"): 500, + validatorID("bob"): 500, // VSC packet jailing bob is not yet relayed to consumer validatorID("carol"): 500, }, }, @@ -364,42 +359,35 @@ func stepsThrottledDowntime(consumerName string) []Step { ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, validatorID("bob"): 0, - validatorID("carol"): 500, // not slashed due to throttling - }, - GlobalSlashQueueSize: uintPointer(1), // carol's slash request is throttled - ConsumerChainQueueSizes: &map[chainID]uint{ - chainID(consumerName): uint(1), + validatorID("carol"): 500, // slash packet for carol recv by provider, carol not slashed due to throttling }, }, chainID(consumerName): ChainState{ ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, - validatorID("bob"): 0, + validatorID("bob"): 0, // VSC packet applying bob jailing is also relayed and recv by consumer validatorID("carol"): 500, }, }, }, }, + // TODO(Shawn): Improve this test to have the consumer retry it's downtime slash, and to assert queue size on consumer. + // See https://github.com/cosmos/interchain-security/issues/1103 and https://github.com/cosmos/interchain-security/issues/1233 { - action: slashThrottleDequeue{ - chain: chainID(consumerName), - currentQueueSize: 1, - nextQueueSize: 0, + action: slashMeterReplenishmentAction{ + targetValue: 0, // We just want slash meter to be non-negative + // Slash meter replenish fraction is set to 10%, replenish period is 20 seconds, see config.go // Meter is initially at 10%, decremented to -23% from bob being jailed. It'll then take three replenishments - // for meter to become positive again. 3*20 = 60 seconds + buffer = 80 seconds - timeout: 80 * time.Second, + // for meter to become positive again. 3*20 = 60 seconds + buffer = 100 seconds + timeout: 100 * time.Second, }, state: State{ chainID("provi"): ChainState{ ValPowers: &map[validatorID]uint{ validatorID("alice"): 511, validatorID("bob"): 0, - validatorID("carol"): 0, // Carol is jailed upon packet being handled on provider - }, - GlobalSlashQueueSize: uintPointer(0), // slash packets dequeued - ConsumerChainQueueSizes: &map[chainID]uint{ - chainID(consumerName): 0, + validatorID("carol"): 500, // Carol still not slashed, packet must be retried }, }, chainID(consumerName): ChainState{ @@ -412,36 +400,5 @@ func stepsThrottledDowntime(consumerName string) []Step { }, }, }, - // A block is incremented each action, hence why VSC is committed on provider, - // and can now be relayed as packet to consumer - { - action: relayPacketsAction{ - chainA: chainID("provi"), - chainB: chainID(consumerName), - port: "provider", - channel: 0, - }, - state: State{ - chainID("provi"): ChainState{ - ValPowers: &map[validatorID]uint{ - validatorID("alice"): 511, - validatorID("bob"): 0, - validatorID("carol"): 0, - }, - GlobalSlashQueueSize: uintPointer(0), - ConsumerChainQueueSizes: &map[chainID]uint{ - chainID(consumerName): 0, - }, - }, - chainID(consumerName): ChainState{ - ValPowers: &map[validatorID]uint{ - validatorID("alice"): 511, - // throttled update gets to consumer - validatorID("bob"): 0, - validatorID("carol"): 0, - }, - }, - }, - }, } } diff --git a/tests/integration/common.go b/tests/integration/common.go index 7d5175d5d7..171253ddbc 100644 --- a/tests/integration/common.go +++ b/tests/integration/common.go @@ -1,6 +1,7 @@ package integration import ( + "bytes" "fmt" "time" @@ -414,50 +415,33 @@ func (suite *CCVTestSuite) commitConsumerPacket(ctx sdk.Context, packetData ccv. func (s *CCVTestSuite) constructSlashPacketFromConsumer(bundle icstestingutils.ConsumerBundle, tmVal tmtypes.Validator, infractionType stakingtypes.Infraction, ibcSeqNum uint64, ) channeltypes.Packet { + packet, _ := s.constructSlashPacketFromConsumerWithData(bundle, tmVal, infractionType, ibcSeqNum) + return packet +} + +func (s *CCVTestSuite) constructSlashPacketFromConsumerWithData(bundle icstestingutils.ConsumerBundle, + tmVal tmtypes.Validator, infractionType stakingtypes.Infraction, ibcSeqNum uint64, +) (channeltypes.Packet, ccv.SlashPacketData) { valsetUpdateId := bundle.GetKeeper().GetHeightValsetUpdateID( bundle.GetCtx(), uint64(bundle.GetCtx().BlockHeight())) - data := ccv.ConsumerPacketData{ - Type: ccv.SlashPacket, - Data: &ccv.ConsumerPacketData_SlashPacketData{ - SlashPacketData: &ccv.SlashPacketData{ - Validator: abci.Validator{ - Address: tmVal.Address, - Power: tmVal.VotingPower, - }, - ValsetUpdateId: valsetUpdateId, - Infraction: infractionType, - }, + spdData := ccv.SlashPacketData{ + Validator: abci.Validator{ + Address: tmVal.Address, + Power: tmVal.VotingPower, }, + ValsetUpdateId: valsetUpdateId, + Infraction: infractionType, } - return channeltypes.NewPacket(data.GetBytes(), - ibcSeqNum, - ccv.ConsumerPortID, // Src port - bundle.Path.EndpointA.ChannelID, // Src channel - ccv.ProviderPortID, // Dst port - bundle.Path.EndpointB.ChannelID, // Dst channel - clienttypes.Height{}, - uint64(bundle.GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()), - ) -} - -// constructVSCMaturedPacketFromConsumer constructs an IBC packet embedding -// VSC Matured packet data to be sent from consumer to provider -func (s *CCVTestSuite) constructVSCMaturedPacketFromConsumer(bundle icstestingutils.ConsumerBundle, - ibcSeqNum uint64, -) channeltypes.Packet { - valsetUpdateId := bundle.GetKeeper().GetHeightValsetUpdateID( - bundle.GetCtx(), uint64(bundle.GetCtx().BlockHeight())) - - data := ccv.ConsumerPacketData{ - Type: ccv.VscMaturedPacket, - Data: &ccv.ConsumerPacketData_VscMaturedPacketData{ - VscMaturedPacketData: &ccv.VSCMaturedPacketData{ValsetUpdateId: valsetUpdateId}, + cpdData := ccv.ConsumerPacketData{ + Type: ccv.SlashPacket, + Data: &ccv.ConsumerPacketData_SlashPacketData{ + SlashPacketData: &spdData, }, } - return channeltypes.NewPacket(data.GetBytes(), + return channeltypes.NewPacket(cpdData.GetBytes(), ibcSeqNum, ccv.ConsumerPortID, // Src port bundle.Path.EndpointA.ChannelID, // Src channel @@ -465,7 +449,7 @@ func (s *CCVTestSuite) constructVSCMaturedPacketFromConsumer(bundle icstestingut bundle.Path.EndpointB.ChannelID, // Dst channel clienttypes.Height{}, uint64(bundle.GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()), - ) + ), spdData } // incrementTime increments the overall time by jumpPeriod @@ -615,3 +599,18 @@ func (s *CCVTestSuite) setupValidatorPowers() { } s.Require().Equal(int64(4000), stakingKeeper.GetLastTotalPower(s.providerCtx()).Int64()) } + +// mustGetStakingValFromTmVal returns the staking validator from the current state of the staking keeper, +// corresponding to a given tendermint validator. Note this func will fail the test if the validator is not found. +func (s *CCVTestSuite) mustGetStakingValFromTmVal(tmVal tmtypes.Validator) (stakingVal stakingtypes.Validator) { + vals := s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx()) + for i, val := range vals { + consAddr, err := val.GetConsAddr() + s.Require().NoError(err) + if bytes.Equal(consAddr.Bytes(), tmVal.Address.Bytes()) { + stakingVal = vals[i] + } + } + s.Require().NotZero(stakingVal) + return stakingVal +} diff --git a/tests/integration/slashing.go b/tests/integration/slashing.go index 1ce7d11db8..7a7ea0e935 100644 --- a/tests/integration/slashing.go +++ b/tests/integration/slashing.go @@ -76,12 +76,11 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() { firstConsumerKeeper.SetOutstandingDowntime(s.consumerCtx(), consumerConsAddr.ToSdkConsAddr()) // Note: RecvPacket advances two blocks. Let's say the provider is currently at height N. - // The received slash packet will be queued during N, and handled by the ccv module during - // the endblocker of N. The staking module will then register a validator update from that - // packet during the endblocker of N+1 (note that staking endblocker runs before ccv endblocker, - // hence why the VSC is registered on N+1). Then the ccv module sends VSC packets to each consumer - // during the endblocker of N+1. The new validator set will be committed to in block N+2, - // and will be in effect for the provider during block N+3. + // The received slash packet will be handled during N. The staking module will then register + // a validator update from that packet during the endblocker of N. Then the ccv module sends + // VSC packets to each consumer during the endblocker of N (note ccv endblocker runs after staking). + // The new validator set will be committed to in block N+1, and will be in effect + // for the provider during block N+2. valsetUpdateIdN := providerKeeper.GetValidatorSetUpdateId(s.providerCtx()) @@ -91,8 +90,8 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() { // We've now advanced two blocks. - // VSC packets should have been sent from provider during block N+1 to each consumer - expectedSentValsetUpdateId := valsetUpdateIdN + 1 + // VSC packets should have been sent from provider during block N to each consumer + expectedSentValsetUpdateId := valsetUpdateIdN for _, bundle := range s.consumerBundles { _, found := providerKeeper.GetVscSendTimestamp(s.providerCtx(), bundle.Chain.ChainID, expectedSentValsetUpdateId) @@ -104,10 +103,7 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() { s.Require().Equal(valsetUpdateIdN+2, providerKeeper.GetValidatorSetUpdateId(s.providerCtx())) - // Call next block so provider is now on block N + 3 mentioned above - s.providerChain.NextBlock() - - // check that the validator was removed from the provider validator set by N + 3 + // check that the validator was removed from the provider validator set by N + 2 s.Require().Len(s.providerChain.Vals.Validators, validatorsPerChain-1) for _, bundle := range s.consumerBundles { @@ -151,9 +147,10 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() { pFlag := firstConsumerKeeper.OutstandingDowntime(s.consumerCtx(), consumerConsAddr.ToSdkConsAddr()) s.Require().False(pFlag) - // check that slashing packet gets acknowledged successfully - ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) - err = s.path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement()) + // Check that first consumer can recv ack from provider. + // Provider has returned SlashPacketHandledResult. + ack := channeltypes.NewResultAcknowledgement(ccv.SlashPacketHandledResult) + err = s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement()) s.Require().NoError(err) } @@ -234,8 +231,9 @@ func (s *CCVTestSuite) TestRelayAndApplyDoubleSignPacket() { // check that validator was NOT tombstoned on provider s.Require().False(valSignInfo.Tombstoned) - // check that slashing packet gets acknowledged successfully - ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + // check that slashing packet gets acknowledged successfully, + // provider returns V1Result acks for double sign packets + ack := channeltypes.NewResultAcknowledgement(ccv.V1Result) err = s.path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement()) s.Require().NoError(err) } @@ -426,16 +424,10 @@ func (suite *CCVTestSuite) TestOnRecvSlashPacketErrors() { errAck = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashingPkt) suite.Require().False(errAck.Success()) - // Expect nothing was queued - suite.Require().Equal(0, len(providerKeeper.GetAllGlobalSlashEntries(ctx))) - suite.Require().Equal(uint64(0), (providerKeeper.GetThrottledPacketDataSize(ctx, consumerChainID))) - // expect to queue entries for the slash request slashingPkt.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME ack = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashingPkt) suite.Require().True(ack.Success()) - suite.Require().Equal(1, len(providerKeeper.GetAllGlobalSlashEntries(ctx))) - suite.Require().Equal(uint64(1), (providerKeeper.GetThrottledPacketDataSize(ctx, consumerChainID))) } // TestValidatorDowntime tests if a slash packet is sent diff --git a/tests/integration/stop_consumer.go b/tests/integration/stop_consumer.go index b3d32ee6a4..452b28e3b1 100644 --- a/tests/integration/stop_consumer.go +++ b/tests/integration/stop_consumer.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/v3/x/ccv/types" ) @@ -80,33 +79,6 @@ func (s *CCVTestSuite) TestStopConsumerChain() { return nil }, }, - { - func(suite *CCVTestSuite) error { - // Queue slash and vsc packet data for consumer 0, these queue entries will be removed - firstBundle := s.getFirstBundle() - globalEntry := types.NewGlobalSlashEntry(s.providerCtx().BlockTime(), firstBundle.Chain.ChainID, 7, types.ProviderConsAddress{Address: []byte{}}) - providerKeeper.QueueGlobalSlashEntry(s.providerCtx(), globalEntry) - err := providerKeeper.QueueThrottledSlashPacketData(s.providerCtx(), firstBundle.Chain.ChainID, 1, - ccv.SlashPacketData{ValsetUpdateId: 1}) - suite.Require().NoError(err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(s.providerCtx(), - firstBundle.Chain.ChainID, 2, ccv.VSCMaturedPacketData{ValsetUpdateId: 2}) - suite.Require().NoError(err) - - // Queue slash and vsc packet data for consumer 1, these queue entries will be not be removed - secondBundle := s.getBundleByIdx(1) - globalEntry = types.NewGlobalSlashEntry(s.providerCtx().BlockTime(), secondBundle.Chain.ChainID, 7, types.ProviderConsAddress{Address: []byte{}}) - providerKeeper.QueueGlobalSlashEntry(s.providerCtx(), globalEntry) - err = providerKeeper.QueueThrottledSlashPacketData(s.providerCtx(), secondBundle.Chain.ChainID, 1, - ccv.SlashPacketData{ValsetUpdateId: 1}) - suite.Require().NoError(err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(s.providerCtx(), - secondBundle.Chain.ChainID, 2, ccv.VSCMaturedPacketData{ValsetUpdateId: 2}) - suite.Require().NoError(err) - - return nil - }, - }, } for _, so := range setupOperations { @@ -120,15 +92,6 @@ func (s *CCVTestSuite) TestStopConsumerChain() { // check all states are removed and the unbonding operation released s.checkConsumerChainIsRemoved(firstBundle.Chain.ChainID, true) - - // check entries related to second consumer chain are not removed - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 1) - - secondBundle := s.getBundleByIdx(1) - slashData, vscMaturedData, _, _ := providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), secondBundle.Chain.ChainID) - s.Require().Len(slashData, 1) - s.Require().Len(vscMaturedData, 1) } // TODO Simon: implement OnChanCloseConfirm in IBC-GO testing to close the consumer chain's channel end @@ -199,15 +162,4 @@ func (s *CCVTestSuite) checkConsumerChainIsRemoved(chainID string, checkChannel s.Require().Nil(providerKeeper.GetSlashAcks(s.providerCtx(), chainID)) s.Require().Zero(providerKeeper.GetInitChainHeight(s.providerCtx(), chainID)) s.Require().Empty(providerKeeper.GetPendingVSCPackets(s.providerCtx(), chainID)) - - // No remaining global entries for this consumer - allGlobalEntries := providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - for _, entry := range allGlobalEntries { - s.Require().NotEqual(chainID, entry.ConsumerChainID) - } - - // No remaining per-chain entries for this consumer - slashData, vscMaturedData, _, _ := providerKeeper.GetAllThrottledPacketData(s.providerCtx(), chainID) - s.Require().Empty(slashData) - s.Require().Empty(vscMaturedData) } diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index 0505d6257a..740576c4f7 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -13,7 +13,6 @@ import ( icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing" "github.com/cosmos/interchain-security/v3/x/ccv/provider" providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) const fullSlashMeterString = "1.0" @@ -85,7 +84,8 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() { packet = s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, 2) sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet) - // Require that slash packet has not been handled + // Require that slash packet has not been handled, a bounce result would have + // been returned, but the IBC helper throws out acks. vals = providerStakingKeeper.GetAllValidators(s.providerCtx()) s.Require().False(vals[2].IsJailed()) @@ -135,11 +135,14 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() { slashMeter = s.providerApp.GetProviderKeeper().GetSlashMeter(cacheCtx) s.Require().True(slashMeter.IsPositive()) - // Assert validator 2 is jailed once pending slash packets are handled in ccv endblocker. - s.providerChain.NextBlock() - vals = providerStakingKeeper.GetAllValidators(cacheCtx) - slashedVal = vals[2] - s.Require().True(slashedVal.IsJailed()) + // Assert validator 2 is jailed once slash packet is retried. + tmVal2 := s.providerChain.Vals.Validators[2] + packet = s.constructSlashPacketFromConsumer(s.getFirstBundle(), + *tmVal2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 3) // make sure to use a new seq num + sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet) + + stakingVal2 := s.mustGetStakingValFromTmVal(*tmVal2) + s.Require().True(stakingVal2.IsJailed()) // Assert validator 2 has no power, this should be apparent next block, // since the staking endblocker runs before the ccv endblocker. @@ -156,23 +159,8 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() { s.SetupAllCCVChannels() s.setupValidatorPowers() - providerKeeper := s.providerApp.GetProviderKeeper() providerStakingKeeper := s.providerApp.GetTestStakingKeeper() - // First confirm that VSC matured packets are handled immediately (not queued) - // when no slash packets are sent. - - // Send 2 VSC matured packets from every consumer to provider - for consumerChainID, bundle := range s.consumerBundles { - packet := s.constructVSCMaturedPacketFromConsumer(*bundle, 1) // use sequence 1 - sendOnConsumerRecvOnProvider(s, bundle.Path, packet) - packet = s.constructVSCMaturedPacketFromConsumer(*bundle, 2) // use sequence 2 - sendOnConsumerRecvOnProvider(s, bundle.Path, packet) - // Confirm packets were not queued on provider for this consumer - s.Require().Equal(uint64(0), - providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), consumerChainID)) - } - // Choose 3 consumer bundles. It doesn't matter which ones. idx := 0 senderBundles := []*icstestingutils.ConsumerBundle{} @@ -184,7 +172,7 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() { idx++ } - // Send some packets to provider from the 3 chosen consumers. + // Send some slash packets to provider from the 3 chosen consumers. // They will each slash a different validator according to idx. idx = 0 valsToSlash := []tmtypes.Validator{} @@ -200,54 +188,70 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() { *bundle, *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, - 3, // use sequence 3, 1 and 2 are used above. + 1, // all consumers use 1 seq num ) sendOnConsumerRecvOnProvider(s, bundle.Path, packet) - // Send two trailing VSC matured packets from consumer to provider - packet = s.constructVSCMaturedPacketFromConsumer(*bundle, 4) // use sequence 4 - sendOnConsumerRecvOnProvider(s, bundle.Path, packet) - packet = s.constructVSCMaturedPacketFromConsumer(*bundle, 5) // use sequence 5 - sendOnConsumerRecvOnProvider(s, bundle.Path, packet) - idx++ } - // Confirm that the slash packet and trailing VSC matured packet - // were handled immediately for the first consumer (this packet was recv first). + // Confirm that the slash packet for the first consumer was handled (this packet was recv first). s.confirmValidatorJailed(valsToSlash[0], true) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[0].Chain.ChainID)) - // Packets were queued for the second and third consumers. + // Packets were bounced for the second and third consumers. s.confirmValidatorNotJailed(valsToSlash[1], 1000) - s.Require().Equal(uint64(3), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[1].Chain.ChainID)) s.confirmValidatorNotJailed(valsToSlash[2], 1000) - s.Require().Equal(uint64(3), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[2].Chain.ChainID)) // Total power is now 3000 s.Require().Equal(int64(3000), providerStakingKeeper.GetLastTotalPower(s.providerCtx()).Int64()) // Now replenish the slash meter and confirm one of two queued slash - // packet entries are then handled. Order is irrelevant here since those - // two packets were sent and recv at the same block time when being queued. + // packet entries are then handled, when both are retried. s.replenishSlashMeterTillPositive() - // 1st NextBlock will handle the slash packet, 2nd will update staking module val powers + // Retry from consumer with idx 1 + bundle := senderBundles[1] + packet := s.constructSlashPacketFromConsumer( + *bundle, + valsToSlash[1], + stakingtypes.Infraction_INFRACTION_DOWNTIME, + 2, // seq number is incremented since last try + ) + sendOnConsumerRecvOnProvider(s, bundle.Path, packet) + + // retry from consumer with idx 2 + bundle = senderBundles[2] + packet = s.constructSlashPacketFromConsumer( + *bundle, + valsToSlash[2], + stakingtypes.Infraction_INFRACTION_DOWNTIME, + 2, // seq number is incremented since last try + ) + sendOnConsumerRecvOnProvider(s, bundle.Path, packet) + + // Call NextBlocks to update staking module val powers s.providerChain.NextBlock() s.providerChain.NextBlock() - // If one of the entires was handled, total power will be 2000 (1000 power was slashed) + // If one of the entires was handled, total power will be 2000 (1000 power was just slashed) s.Require().Equal(int64(2000), providerStakingKeeper.GetLastTotalPower(s.providerCtx()).Int64()) // Now replenish one more time, and handle final slash packet. s.replenishSlashMeterTillPositive() - // 1st NextBlock will handle the slash packet, 2nd will update last validator power + // Retry from consumer with idx 2 + bundle = senderBundles[2] + packet = s.constructSlashPacketFromConsumer( + *bundle, + valsToSlash[2], + stakingtypes.Infraction_INFRACTION_DOWNTIME, + 3, // seq number is incremented since last try + ) + sendOnConsumerRecvOnProvider(s, bundle.Path, packet) + + // Call NextBlocks to update staking module val powers s.providerChain.NextBlock() s.providerChain.NextBlock() @@ -260,15 +264,6 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() { for _, val := range valsToSlash { s.confirmValidatorJailed(val, true) } - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[0].Chain.ChainID)) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[1].Chain.ChainID)) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), senderBundles[2].Chain.ChainID)) - - // All global queue entries are gone too - s.Require().Empty(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx())) } // TestPacketSpam confirms that the provider can handle a large number of @@ -322,17 +317,14 @@ func (s *CCVTestSuite) TestPacketSpam() { providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } - // Execute block to handle packets in endblock + // Execute block s.providerChain.NextBlock() - // Confirm all packets are handled or dropped (queues empty) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), firstBundle.Chain.ChainID)) - slashData, vscMData, _, _ := providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), firstBundle.Chain.ChainID) - s.Require().Empty(slashData) - s.Require().Empty(vscMData) - s.Require().Empty(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx())) + // Confirm 3 expected vals are jailed + for i := 0; i < 3; i++ { + val := s.providerChain.Vals.Validators[i] + s.confirmValidatorJailed(*val, true) + } } func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { @@ -379,15 +371,6 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { // Execute block to handle packets in endblock s.providerChain.NextBlock() - // Confirm all packets are dropped (queues empty) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize( - s.providerCtx(), firstBundle.Chain.ChainID)) - slashData, vscMData, _, _ := providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), firstBundle.Chain.ChainID) - s.Require().Empty(slashData) - s.Require().Empty(vscMData) - s.Require().Empty(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx())) - // Confirm that slash meter is not affected s.Require().Equal(providerKeeper.GetSlashMeterAllowance(s.providerCtx()), providerKeeper.GetSlashMeter(s.providerCtx())) @@ -417,155 +400,6 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { } } -// TestQueueOrdering validates that the ordering of slash packet entries -// in the global queue (relevant to a single chain) matches the ordering of slash packet -// data in the chain specific queues, even in the presence of packet spam. -// -// Note: The global queue is ordered by: time, then IBC sequence number, see GlobalSlashEntryKey. -// The chain specific queue is ordered by: IBC sequence number, see ThrottledPacketDataKey. -func (s *CCVTestSuite) TestQueueOrdering() { - // Setup ccv channels to all consumers - s.SetupAllCCVChannels() - - // Setup validator powers to be 25%, 25%, 25%, 25% - s.setupValidatorPowers() - - // Explicitly set params, initialize slash meter - providerKeeper := s.providerApp.GetProviderKeeper() - params := providerKeeper.GetParams(s.providerCtx()) - params.SlashMeterReplenishFraction = "0.05" // 5% total power can be jailed - providerKeeper.SetParams(s.providerCtx(), params) - providerKeeper.InitializeSlashMeter(s.providerCtx()) - - // The packets to be recv in a single block, ordered as they will be recv. - packets := []channeltypes.Packet{} - - firstBundle := s.getFirstBundle() - - // Slash first 3 but not 4th validator - s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[0]) - s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[1]) - s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[2]) - - // Track and increment ibc seq num for each packet, since these need to be unique. - ibcSeqNum := uint64(4) - - for ibcSeqNum < 504 { - // Increment ibc seq num for each packet (starting at 5) - ibcSeqNum++ - - // Instantiate a vsc matured packet every 10th packet - if ibcSeqNum%10 == 0 { - packets = append(packets, s.constructVSCMaturedPacketFromConsumer(firstBundle, ibcSeqNum)) - continue - } - // Else instantiate a slash packet - - valToJail := s.providerChain.Vals.Validators[ibcSeqNum%3] - packets = append(packets, s.constructSlashPacketFromConsumer(firstBundle, *valToJail, stakingtypes.Infraction_INFRACTION_DOWNTIME, ibcSeqNum)) - } - - // Recv 500 packets from consumer to provider in same block - for i, packet := range packets { - - consumerPacketData, err := provider.UnmarshalConsumerPacket(packet) // Same func used by provider's OnRecvPacket - s.Require().NoError(err) - - // Type depends on index packets were appended from above - if (i+5)%10 == 0 { - vscMaturedPacketData := consumerPacketData.GetVscMaturedPacketData() - vscMaturedPacketData.ValsetUpdateId = uint64(i + 1000) - providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), packet, *vscMaturedPacketData) - } else { - // Set valset update id to be 2000 + index to assert ordering - slashPacketData := consumerPacketData.GetSlashPacketData() - slashPacketData.ValsetUpdateId = uint64(i + 2000) - // Set block height mapping so packet is not dropped - providerKeeper.SetValsetUpdateBlockHeight(s.providerCtx(), - slashPacketData.ValsetUpdateId, uint64(firstBundle.GetCtx().BlockHeight())) - providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *slashPacketData) - } - } - - // Confirm that global queue has 450 packet entries (500 * 0.9) - allGlobalEntries := providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(450, len(allGlobalEntries)) - - // Confirm that the chain specific queue has 450 slash packet data instances, and 50 vsc matured - slashPacketData, vscMaturedPacketData, _, _ := providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), firstBundle.Chain.ChainID) - s.Require().Equal(450, len(slashPacketData)) - s.Require().Equal(50, len(vscMaturedPacketData)) - - // IBC seq numbers of recv slash packets range from 5 to 504. - // Confirm expected global queue ordering. - expectedSeqNum := uint64(5) - for _, globalEntry := range allGlobalEntries { - // entries should be ordered by ibc seq num starting at 5 - s.Require().Equal(expectedSeqNum, globalEntry.IbcSeqNum) - expectedSeqNum++ - if expectedSeqNum%10 == 0 { - // Skip over vsc matured packets - expectedSeqNum++ - } - } - - // Confirm expected chain specific queue ordering. - expectedVscId := uint64(2000) - for _, slashPacket := range slashPacketData { - // entries should be ordered by valset update id starting at 2000 - s.Require().Equal(expectedVscId, slashPacket.ValsetUpdateId) - expectedVscId++ - if (expectedVscId+5)%10 == 0 { - // Skip over vsc matured packets - expectedVscId++ - } - } - for idx, vscMaturedPacket := range vscMaturedPacketData { - // entries should be ordered by valset update id starting at 1005 - // and show up every 10 packets - expectedVscId = uint64(1005) + 10*uint64(idx) - s.Require().Equal(expectedVscId, vscMaturedPacket.ValsetUpdateId) - } - - // Execute endblock to handle packets in throttled manner - s.providerChain.NextBlock() - - // Confirm that only the first packet was handled - allGlobalEntries = providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(449, len(allGlobalEntries)) - slashPacketData, vscMaturedPacketData, _, _ = providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), firstBundle.Chain.ChainID) - s.Require().Equal(449, len(slashPacketData)) - // No VSC matured packets should be handled yet - s.Require().Equal(50, len(vscMaturedPacketData)) - - // Replenish frac is 0.05, so jailing %25 of the validators should result in a negative slash meter. - s.Require().True(providerKeeper.GetSlashMeter(s.providerCtx()).IsNegative()) - - // Confirm total power is now 3000 once updated by staking end blocker - s.providerChain.NextBlock() - totalPower := s.providerApp.GetTestStakingKeeper().GetLastTotalPower(s.providerCtx()) - s.Require().Equal(sdk.NewInt(3000), totalPower) - - // Now change replenish frac to 0.67 and fully replenish the meter. - params.SlashMeterReplenishFraction = "0.67" - providerKeeper.SetParams(s.providerCtx(), params) - providerKeeper.InitializeSlashMeter(s.providerCtx()) - - // Execute endblock to handle packets (remaining packets are relevant to 2/3 of the validators) - // so the current replenish frac should be enough to handle all packets this block. - s.providerChain.NextBlock() - - // Confirm both queues are now empty, meaning every packet was handled. - allGlobalEntries = providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(0, len(allGlobalEntries)) - slashPacketData, vscMaturedPacketData, _, _ = providerKeeper.GetAllThrottledPacketData( - s.providerCtx(), firstBundle.Chain.ChainID) - s.Require().Equal(0, len(slashPacketData)) - s.Require().Equal(0, len(vscMaturedPacketData)) -} - // TestSlashingSmallValidators tests that multiple slash packets from validators with small // power can be handled by the provider chain in a non-throttled manner. func (s *CCVTestSuite) TestSlashingSmallValidators() { @@ -645,59 +479,6 @@ func (s *CCVTestSuite) TestSlashMeterAllowanceChanges() { s.Require().Equal(int64(1200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64()) } -// TestSlashSameValidator tests the edge case that that the total slashed validator power -// queued up for a single block exceeds the slash meter allowance, -// but some of the slash packets are for the same validator, and therefore some packets -// will be applied to a validator that is already jailed but still not unbonded (ie. still slashable). -func (s *CCVTestSuite) TestSlashSameValidator() { - s.SetupAllCCVChannels() - - // Setup 4 validators with 25% of the total power each. - s.setupValidatorPowers() - - providerKeeper := s.providerApp.GetProviderKeeper() - - // Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling) - params := providerKeeper.GetParams(s.providerCtx()) - params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter - providerKeeper.SetParams(s.providerCtx(), params) - providerKeeper.InitializeSlashMeter(s.providerCtx()) - - // Send a downtime and double-sign slash packet for 3/4 validators - // This will have a total slashing power of 150% total power. - tmval1 := s.providerChain.Vals.Validators[1] - tmval2 := s.providerChain.Vals.Validators[2] - tmval3 := s.providerChain.Vals.Validators[3] - s.setDefaultValSigningInfo(*tmval1) - s.setDefaultValSigningInfo(*tmval2) - s.setDefaultValSigningInfo(*tmval3) - - packets := []channeltypes.Packet{ - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1), - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 2), - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Infraction_INFRACTION_DOWNTIME, 3), - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 4), - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 5), - s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Infraction_INFRACTION_DOWNTIME, 6), - } - - // Recv and queue all slash packets. - for _, packet := range packets { - consumerPacketData, err := provider.UnmarshalConsumerPacket(packet) // Same func used by provider's OnRecvPacket - s.Require().NoError(err) - providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) - } - - // We should have 6 pending slash packet entries queued. - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 6) - - // Call next block to process all pending slash packets in end blocker. - s.providerChain.NextBlock() - - // All slash packets should have been handled immediately, even though they totaled to 150% of total power. - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 0) -} - // Similar to TestSlashSameValidator, but 100% of val power is jailed a single block, // and in the first packets recv for that block. // This edge case should not occur in practice, but is useful to validate that @@ -749,17 +530,7 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } - // We should have 24 pending slash packet entries queued. - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 24) - - // Call next block to process all pending slash packets in end blocker. - s.providerChain.NextBlock() - - // All slash packets should have been handled immediately, - // even though the first 4 packets jailed 100% of the total power. - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 0) - - // Sanity check that all validators are jailed. + // Check that all validators are jailed. for _, val := range s.providerChain.Vals.Validators { // Do not check power, since val power is not yet updated by staking endblocker. s.confirmValidatorJailed(*val, false) @@ -769,148 +540,6 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes // "applying the validator changes would result in empty set". } -func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() { - s.SetupAllCCVChannels() - providerKeeper := s.providerApp.GetProviderKeeper() - - // Queue up 50 vsc matured packets for each consumer - for _, bundle := range s.consumerBundles { - for i := 0; i < 50; i++ { - ibcSeqNum := uint64(i) - packet := s.constructVSCMaturedPacketFromConsumer(*bundle, ibcSeqNum) - packetData := ccvtypes.ConsumerPacketData{} - ccvtypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &packetData) - providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), - packet, *packetData.GetVscMaturedPacketData()) - } - } - - // Queue up 50 slash packets for each consumer - for _, bundle := range s.consumerBundles { - for i := 50; i < 100; i++ { - ibcSeqNum := uint64(i) - packet := s.constructSlashPacketFromConsumer(*bundle, - *s.providerChain.Vals.Validators[0], stakingtypes.Infraction_INFRACTION_DOWNTIME, ibcSeqNum) - consumerPacketData, err := provider.UnmarshalConsumerPacket(packet) // Same func used by provider's OnRecvPacket - s.Require().NoError(err) - providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) - } - } - - // Queue up another 50 vsc matured packets for each consumer - for _, bundle := range s.consumerBundles { - for i := 100; i < 150; i++ { - ibcSeqNum := uint64(i) - packet := s.constructVSCMaturedPacketFromConsumer(*bundle, ibcSeqNum) - packetData := ccvtypes.ConsumerPacketData{} - ccvtypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &packetData) - providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), - packet, *packetData.GetVscMaturedPacketData()) - } - } - - // Confirm queue size is 150 for each consumer-specific queue. - for _, bundle := range s.consumerBundles { - s.Require().Equal(uint64(150), - providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), bundle.Chain.ChainID)) - } - // Confirm global queue size is 50 * 5 (50 slash packets for each of 5 consumers) - globalEntries := providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(len(globalEntries), 50*5) - - // Set slash meter to negative value to not allow any slash packets to be handled. - providerKeeper.SetSlashMeter(s.providerCtx(), sdk.NewInt(-1)) - - // Set replenish time candidate so that no replenishment happens next block. - providerKeeper.SetSlashMeterReplenishTimeCandidate(s.providerCtx()) - - // Execute end blocker to dequeue only the leading vsc matured packets. - // Note we must call the end blocker three times, since only 100 vsc matured packets can be handled - // each block, and we have 5*50=250 total. - s.providerChain.NextBlock() - s.providerChain.NextBlock() - s.providerChain.NextBlock() - - // Confirm queue size is 100 for each consumer-specific queue (50 leading vsc matured are dequeued). - for _, bundle := range s.consumerBundles { - s.Require().Equal(uint64(100), - providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), bundle.Chain.ChainID)) - } - - // No slash packets handled, global slash queue is same size as last block. - globalEntries = providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(len(globalEntries), 50*5) - - // No slash packets handled even if we call end blocker a couple more times. - s.providerChain.NextBlock() - s.providerChain.NextBlock() - globalEntries = providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(len(globalEntries), 50*5) -} - -// TestVscMaturedHandledPerBlockLimit tests that only 100 vsc matured packets are handled per block, -// specifically from HandleThrottleQueues(). -// -// Note the vsc matured per block limit is also tested in, TestLeadingVSCMaturedAreDequeued, -// specifically in the context of HandleLeadingVSCMaturedPackets(). -func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() { - s.SetupAllCCVChannels() - providerKeeper := s.providerApp.GetProviderKeeper() - - // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no jail throttling) - params := providerKeeper.GetParams(s.providerCtx()) - params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter - providerKeeper.SetParams(s.providerCtx(), params) - providerKeeper.InitializeSlashMeter(s.providerCtx()) - - // Queue up 100 vsc matured packets for each consumer - for _, bundle := range s.consumerBundles { - for i := 0; i < 100; i++ { - ibcSeqNum := uint64(i) - packet := s.constructVSCMaturedPacketFromConsumer(*bundle, ibcSeqNum) - packetData := ccvtypes.ConsumerPacketData{} - ccvtypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &packetData) - providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), - packet, *packetData.GetVscMaturedPacketData()) - } - } - - // Queue up 50 slash packets for each consumer, with new IBC sequence numbers - for _, bundle := range s.consumerBundles { - for i := 100; i < 150; i++ { - ibcSeqNum := uint64(i) - packet := s.constructSlashPacketFromConsumer(*bundle, - *s.providerChain.Vals.Validators[0], stakingtypes.Infraction_INFRACTION_DOWNTIME, ibcSeqNum) - consumerPacketData, err := provider.UnmarshalConsumerPacket(packet) // Same func used by provider's OnRecvPacket - s.Require().NoError(err) - providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) - } - } - - // Confirm queue size is 150 for each consumer-specific queue. - for _, bundle := range s.consumerBundles { - s.Require().Equal(uint64(150), - providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), bundle.Chain.ChainID)) - } - // Confirm global queue size is 50 * 5 (50 slash packets for each of 5 consumers) - globalEntries := providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()) - s.Require().Equal(len(globalEntries), 50*5) - - // Note even though there is no jail throttling active, slash packets will not be handled until - // all of the leading vsc matured packets are handled first. This should take 5 blocks. - for i := 0; i < 5; i++ { - s.providerChain.NextBlock() - s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 250) // global entries remain same size - } - - // Set signing info for val to be jailed, preventing panic - s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[0]) - - // Now we execute one more block and all 250 of the slash packets should be handled. - s.providerChain.NextBlock() - s.Require().Empty(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx())) // empty global entries = all slash packets handled -} - func (s *CCVTestSuite) confirmValidatorJailed(tmVal tmtypes.Validator, checkPower bool) { sdkVal, found := s.providerApp.GetTestStakingKeeper().GetValidator( s.providerCtx(), sdk.ValAddress(tmVal.Address)) diff --git a/tests/integration/throttle_retry.go b/tests/integration/throttle_retry.go index ae15aac977..4b445d5d25 100644 --- a/tests/integration/throttle_retry.go +++ b/tests/integration/throttle_retry.go @@ -1,32 +1,25 @@ package integration import ( + "time" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - provider "github.com/cosmos/interchain-security/v3/x/ccv/provider" - providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) -// TestSlashRetries tests the throttling v2 retry logic. Without provider changes, -// the consumer will queue up a slash packet, the provider will return a v1 result, -// and the consumer will never need to retry. -// -// Once provider changes are made (slash packet queuing is removed), the consumer may retry packets -// via new result acks from the provider. -// -// TODO: This test will need updating once provider changes are made. +// TestSlashRetries tests the throttling v2 retry logic at an integration level. func (s *CCVTestSuite) TestSlashRetries() { s.SetupAllCCVChannels() + s.SendEmptyVSCPacket() // Establish ccv channel s.setupValidatorPowers() // // Provider setup // providerKeeper := s.providerApp.GetProviderKeeper() - providerModule := provider.NewAppModule(&providerKeeper, s.providerApp.GetSubspace(providertypes.ModuleName)) // Initialize slash meter providerKeeper.InitializeSlashMeter(s.providerCtx()) // Assert that we start out with no jailings @@ -35,13 +28,24 @@ func (s *CCVTestSuite) TestSlashRetries() { for _, val := range vals { s.Require().False(val.IsJailed()) } + + // We jail two different validators in this test, referred to as val1 and val2. + // This may or may not correspond to the indexes 1 and 2 in various validator slices, + // depending on how the slice is constructed. + + // The s.providerChain.Vals.Validators set will change depending on jailings, + // so we cache these two val objects now to be the canonical val1 and val2. + tmval1 := s.providerChain.Vals.Validators[1] + tmval2 := s.providerChain.Vals.Validators[2] + // Setup signing info for jailings - s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[1]) + s.setDefaultValSigningInfo(*tmval1) + s.setDefaultValSigningInfo(*tmval2) // // Consumer setup // - consumerKeeper := s.consumerApp.GetConsumerKeeper() + consumerKeeper := s.getFirstBundle().App.GetConsumerKeeper() // Assert no slash record exists _, found := consumerKeeper.GetSlashRecord(s.consumerCtx()) s.Require().False(found) @@ -50,101 +54,166 @@ func (s *CCVTestSuite) TestSlashRetries() { // Test section: See FSM explanation in throttle_retry.go // - // Construct a mock slash packet from consumer - tmval1 := s.providerChain.Vals.Validators[1] - packet1 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1) + // Construct a slash packet + packet1, data := s.constructSlashPacketFromConsumerWithData( + s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1) - // Mock the sending of the packet on consumer + // Append packet to be sent by consumer consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket, &ccvtypes.ConsumerPacketData_SlashPacketData{ - SlashPacketData: &ccvtypes.SlashPacketData{}, + SlashPacketData: &data, }, ) - consumerKeeper.UpdateSlashRecordOnSend(s.consumerCtx()) + + sendTime := s.consumerCtx().BlockTime() + + // Advance block on consumer to send pending packet + s.getFirstBundle().Chain.NextBlock() + + // Confirm packet was sent via state that's updated on send slashRecord, found := consumerKeeper.GetSlashRecord(s.consumerCtx()) s.Require().True(found) s.Require().True(slashRecord.WaitingOnReply) + s.Require().NotZero(slashRecord.SendTime) + s.Require().Equal(sendTime, slashRecord.SendTime) s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1) - // Recv packet on provider and assert ack. Provider should return v1 result. - ack := providerModule.OnRecvPacket(s.providerCtx(), packet1, nil) - expectedv1Ack := channeltypes.NewResultAcknowledgement([]byte(ccvtypes.V1Result)) - s.Require().Equal(expectedv1Ack.Acknowledgement(), ack.Acknowledgement()) + // Packet sending blocked until provider returns slash packet handled ack + s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) + + // Recv packet on provider. + relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1) // Couple blocks pass on provider for provider staking keeper to process jailing s.providerChain.NextBlock() s.providerChain.NextBlock() // Default slash meter replenish fraction is 0.05, so packet should be handled on provider. - vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx()) - s.Require().True(vals[1].IsJailed()) + stakingVal1 := s.mustGetStakingValFromTmVal(*tmval1) + s.Require().True(stakingVal1.IsJailed()) s.Require().Equal(int64(0), - s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), vals[1].GetOperator())) - s.Require().Equal(uint64(0), providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), - s.getFirstBundle().Chain.ChainID)) + s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), stakingVal1.GetOperator())) // Now slash meter should be negative on provider s.Require().True(s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx()).IsNegative()) // Apply ack back on consumer - ackForConsumer := expectedv1Ack - err := consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet1, ackForConsumer) + expectedAck := channeltypes.NewResultAcknowledgement([]byte(ccvtypes.SlashPacketHandledResult)) + err := s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet1, expectedAck.Acknowledgement()) s.Require().NoError(err) - // Slash record should have been deleted, head of pending packets should have been popped - // Since provider has handled the packet + // Slash record should have been deleted, head of pending packets should have been popped, + // since provider has handled the packet. _, found = consumerKeeper.GetSlashRecord(s.consumerCtx()) s.Require().False(found) s.Require().Empty(consumerKeeper.GetPendingPackets(s.consumerCtx())) + // Packet sending should now be unblocked + s.Require().True(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) + // pass two blocks on provider and consumer for good measure s.providerChain.NextBlock() s.providerChain.NextBlock() s.consumerChain.NextBlock() s.consumerChain.NextBlock() - // Construct and mock the sending of a second packet on consumer - tmval2 := s.providerChain.Vals.Validators[2] - packet2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1) - + // Have consumer queue a new slash packet for a different validator. + packet2, data := s.constructSlashPacketFromConsumerWithData( + s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1) consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket, &ccvtypes.ConsumerPacketData_SlashPacketData{ - SlashPacketData: &ccvtypes.SlashPacketData{}, + SlashPacketData: &data, }, ) - consumerKeeper.UpdateSlashRecordOnSend(s.consumerCtx()) + + // Advance block on consumer to send pending packet + sendTime = s.consumerCtx().BlockTime() + s.getFirstBundle().Chain.NextBlock() + + // Confirm packet was sent via state that's updated on send slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx()) s.Require().True(found) s.Require().True(slashRecord.WaitingOnReply) + s.Require().NotZero(slashRecord.SendTime) + s.Require().Equal(sendTime, slashRecord.SendTime) s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1) - // Recv 2nd slash packet on provider for different validator. - // Provider should return the same v1 result ack even tho the packet was queued. - ack = providerModule.OnRecvPacket(s.providerCtx(), packet2, nil) - expectedv1Ack = channeltypes.NewResultAcknowledgement([]byte(ccvtypes.V1Result)) - s.Require().Equal(expectedv1Ack.Acknowledgement(), ack.Acknowledgement()) + // Packet sending blocked until provider returns slash packet handled ack + s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) + + // Recv 2nd packet on provider. + relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1) // Couple blocks pass on provider for staking keeper to process jailings s.providerChain.NextBlock() s.providerChain.NextBlock() - // Val shouldn't be jailed on provider. Slash packet was queued - s.Require().False(vals[2].IsJailed()) + // Val 2 shouldn't be jailed on provider. Slash packet should have been bounced. + stakingVal2 := s.mustGetStakingValFromTmVal(*tmval2) + s.Require().False(stakingVal2.IsJailed()) s.Require().Equal(int64(1000), - providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[2].GetOperator())) - s.Require().Equal(uint64(1), providerKeeper.GetThrottledPacketDataSize(s.providerCtx(), - s.getFirstBundle().Chain.ChainID)) + providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), stakingVal2.GetOperator())) // Apply ack on consumer - ackForConsumer = expectedv1Ack - err = consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet2, ackForConsumer) + expectedAck = channeltypes.NewResultAcknowledgement([]byte(ccvtypes.SlashPacketBouncedResult)) + err = s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet2, expectedAck.Acknowledgement()) s.Require().NoError(err) - // TODO: when provider changes are made, slashRecord.WaitingOnReply should have been updated to false on consumer. Slash Packet will still be in consumer's pending packets queue. + // Now consumer should have updated it's slash record on receipt of bounce ack + slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx()) + s.Require().True(found) + s.Require().False(slashRecord.WaitingOnReply) + // Packet still at head of queue + s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1) + + // Packet sending should still be blocked, WaitingOnReply is false, + // but retry delay hasn't passed yet. + s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) + + // IBC testing framework doesn't have a way to advance time, + // so we manually mutate send time in the slash record to be in the past. + slashRecord.SendTime = slashRecord.SendTime.Add(-time.Hour - time.Minute) + consumerKeeper.SetSlashRecord(s.consumerCtx(), slashRecord) + + s.Require().True(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) + + // Set slash meter on provider to positive value, + // now allowing handling of the slash packet + providerKeeper.InitializeSlashMeter(s.providerCtx()) + + // Advance block on consumer, now consumer should retry the sending of the slash packet. + sendTime = s.consumerCtx().BlockTime() + s.getFirstBundle().Chain.NextBlock() + + // Confirm packet was sent via state that's updated on send + slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx()) + s.Require().True(found) + s.Require().True(slashRecord.WaitingOnReply) + s.Require().NotZero(slashRecord.SendTime) + s.Require().Equal(sendTime, slashRecord.SendTime) + s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1) + + // Recv retried packet on provider. + relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1) + + // Couple blocks pass on provider for provider staking keeper to process jailing + s.providerChain.NextBlock() + s.providerChain.NextBlock() + + // Provider should have now jailed val 2 + stakingVal2 = s.mustGetStakingValFromTmVal(*tmval2) + s.Require().True(stakingVal2.IsJailed()) + s.Require().Equal(int64(0), + s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), stakingVal2.GetOperator())) + + // Apply ack on consumer + expectedAck = channeltypes.NewResultAcknowledgement([]byte(ccvtypes.SlashPacketHandledResult)) + err = s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet2, expectedAck.Acknowledgement()) + s.Require().NoError(err) - // Slash record should have been deleted, head of pending packets should have been popped - // Since provider has handled the packet + // Consumer state is properly cleared again _, found = consumerKeeper.GetSlashRecord(s.consumerCtx()) s.Require().False(found) s.Require().Empty(consumerKeeper.GetPendingPackets(s.consumerCtx())) + s.Require().True(consumerKeeper.PacketSendingPermitted(s.consumerCtx())) } diff --git a/testutil/integration/debug_test.go b/testutil/integration/debug_test.go index 6b9415440e..ab1c78af7f 100644 --- a/testutil/integration/debug_test.go +++ b/testutil/integration/debug_test.go @@ -181,10 +181,6 @@ func TestDoubleSignDoesNotAffectThrottling(t *testing.T) { runCCVTestByName(t, "TestDoubleSignDoesNotAffectThrottling") } -func TestQueueOrdering(t *testing.T) { - runCCVTestByName(t, "TestQueueOrdering") -} - func TestSlashingSmallValidators(t *testing.T) { runCCVTestByName(t, "TestSlashingSmallValidators") } @@ -193,22 +189,10 @@ func TestSlashMeterAllowanceChanges(t *testing.T) { runCCVTestByName(t, "TestSlashMeterAllowanceChanges") } -func TestSlashSameValidator(t *testing.T) { - runCCVTestByName(t, "TestSlashSameValidator") -} - func TestSlashAllValidators(t *testing.T) { runCCVTestByName(t, "TestSlashAllValidators") } -func TestLeadingVSCMaturedAreDequeued(t *testing.T) { - runCCVTestByName(t, "TestLeadingVSCMaturedAreDequeued") -} - -func TestVscMaturedHandledPerBlockLimit(t *testing.T) { - runCCVTestByName(t, "TestVscMaturedHandledPerBlockLimit") -} - // // Unbonding tests // diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index b58d6d2471..77b4df9c10 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -254,15 +254,6 @@ func TestProviderStateIsCleanedAfterConsumerChainIsStopped(t *testing.T, ctx sdk 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 { - require.NotEqual(t, expectedChainID, entry.ConsumerChainID) - } - - slashPacketData, vscMaturedPacketData, _, _ := providerKeeper.GetAllThrottledPacketData(ctx, expectedChainID) - require.Empty(t, slashPacketData) - require.Empty(t, vscMaturedPacketData) } func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal { diff --git a/x/ccv/provider/client/cli/query.go b/x/ccv/provider/client/cli/query.go index 1240e242f0..80746ff5d2 100644 --- a/x/ccv/provider/client/cli/query.go +++ b/x/ccv/provider/client/cli/query.go @@ -31,7 +31,6 @@ func NewQueryCmd() *cobra.Command { cmd.AddCommand(CmdConsumerValidatorKeyAssignment()) cmd.AddCommand(CmdProviderValidatorKey()) cmd.AddCommand(CmdThrottleState()) - cmd.AddCommand(CmdThrottledConsumerPacketData()) cmd.AddCommand(CmdRegisteredConsumerRewardDenoms()) return cmd @@ -286,42 +285,6 @@ $ %s query provider throttle-state return cmd } -func CmdThrottledConsumerPacketData() *cobra.Command { - cmd := &cobra.Command{ - Use: "throttled-consumer-packet-data [chainid]", - Short: "Query pending VSCMatured and slash packet data for a consumer chainId", - Long: strings.TrimSpace( - fmt.Sprintf(`Returns the current pending VSCMatured and slash packet data instances for a consumer chainId. - Queue is ordered by ibc sequence number. -Example: -$ %s query provider throttled-consumer-packet-data foochain -`, - version.AppName, - ), - ), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - req := &types.QueryThrottledConsumerPacketDataRequest{ChainId: args[0]} - res, err := queryClient.QueryThrottledConsumerPacketData(cmd.Context(), req) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - func CmdRegisteredConsumerRewardDenoms() *cobra.Command { cmd := &cobra.Command{ Use: "registered-consumer-reward-denoms", diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 2b522ea9ef..881a6b1a98 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -148,98 +147,14 @@ func (k Keeper) QueryThrottleState(goCtx context.Context, req *types.QueryThrott meter := k.GetSlashMeter(ctx) allowance := k.GetSlashMeterAllowance(ctx) candidate := k.GetSlashMeterReplenishTimeCandidate(ctx) // always UTC - packets := []*types.ThrottledSlashPacket{} - - // iterate global slash entries from all consumer chains - // and fetch corresponding SlashPacketData from the per-chain throttled packet data queue - allGlobalEntries := k.GetAllGlobalSlashEntries(ctx) - - for _, entry := range allGlobalEntries { - // Obtain slash packet data instance for the given global entry - slashData, found := k.getSlashPacketData(ctx, entry.ConsumerChainID, entry.IbcSeqNum) - if !found { - // silently skip over invalid data - continue - } - - packets = append(packets, &types.ThrottledSlashPacket{ - GlobalEntry: entry, - Data: slashData, - }) - } return &types.QueryThrottleStateResponse{ SlashMeter: meter.Int64(), SlashMeterAllowance: allowance.Int64(), NextReplenishCandidate: candidate, - Packets: packets, - }, nil -} - -func (k Keeper) QueryThrottledConsumerPacketData(goCtx context.Context, req *types.QueryThrottledConsumerPacketDataRequest) (*types.QueryThrottledConsumerPacketDataResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "empty request") - } - - if req.ChainId == "" { - return nil, status.Error(codes.InvalidArgument, "invalid chain-id") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - if _, found := k.GetChainToChannel(ctx, req.ChainId); !found { - return nil, status.Error(codes.InvalidArgument, "invalid chain-id") - } - - packetDataInstances := []types.ThrottledPacketDataWrapper{} - _, _, rawOrderedData, _ := k.GetAllThrottledPacketData(ctx, req.ChainId) - - for _, raw := range rawOrderedData { - switch data := raw.(type) { - case ccvtypes.SlashPacketData: - w := &types.ThrottledPacketDataWrapper_SlashPacket{SlashPacket: &data} - packetDataInstances = append(packetDataInstances, types.ThrottledPacketDataWrapper{ - Data: w, - }) - case ccvtypes.VSCMaturedPacketData: - w := &types.ThrottledPacketDataWrapper_VscMaturedPacket{VscMaturedPacket: &data} - packetDataInstances = append(packetDataInstances, types.ThrottledPacketDataWrapper{ - Data: w, - }) - default: - k.Logger(ctx).Error(fmt.Sprintf("unexpected packet data type: %T", data)) - } - } - - return &types.QueryThrottledConsumerPacketDataResponse{ - ChainId: req.ChainId, - Size_: k.GetThrottledPacketDataSize(ctx, req.ChainId), - PacketDataInstances: packetDataInstances, }, nil } -// getSlashPacketData fetches a slash packet data from the store using consumerChainId and ibcSeqNum (direct access) -// If the returned bytes do not unmarshal to SlashPacketData, the data is considered not found. -func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcSeqNum uint64) (ccvtypes.SlashPacketData, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) - if len(bz) == 0 { - return ccvtypes.SlashPacketData{}, false - } - - if bz[0] != slashPacketData { - return ccvtypes.SlashPacketData{}, false - } - - packet := ccvtypes.SlashPacketData{} - err := packet.Unmarshal(bz[1:]) - if err != nil { - // If the data cannot be unmarshaled, it is considered not found - return ccvtypes.SlashPacketData{}, false - } - - return packet, true -} - func (k Keeper) QueryRegisteredConsumerRewardDenoms(goCtx context.Context, req *types.QueryRegisteredConsumerRewardDenomsRequest) (*types.QueryRegisteredConsumerRewardDenomsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 7e4eb557f7..80ed8af54d 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -214,21 +214,6 @@ func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan boo k.DeleteUnbondingOpIndex(ctx, chainID, unbondingOpsIndex.VscId) } - // Remove any existing throttling related entries from the global queue, - // only for this consumer. - // Note: this call panics if the throttling state is invalid - k.DeleteGlobalSlashEntriesForConsumer(ctx, chainID) - - if k.GetThrottledPacketDataSize(ctx, chainID) > 0 { - k.Logger(ctx).Info("There are throttled slash and/or vsc matured packet data instances queued,"+ - " from a consumer that is being removed. This packet data will be thrown out!", "chainID", chainID) - } - - // Remove all throttled slash packets and vsc matured packets queued for this consumer. - // Note: queued VSC matured packets can be safely removed from the per-chain queue, - // since all unbonding operations for this consumer are release above. - k.DeleteThrottledPacketDataForConsumer(ctx, chainID) - k.Logger(ctx).Info("consumer chain removed from provider", "chainID", chainID) return nil diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index e6b8573e24..f49b6d3b11 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -18,7 +18,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" - cryptoutil "github.com/cosmos/interchain-security/v3/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper" providerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper" providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" @@ -525,28 +524,6 @@ func TestStopConsumerChain(t *testing.T) { }, expErr: true, }, - { - description: "valid stop of consumer chain, throttle related queues are cleaned", - setup: func(ctx sdk.Context, providerKeeper *providerkeeper.Keeper, mocks testkeeper.MockedKeepers) { - testkeeper.SetupForStoppingConsumerChain(t, ctx, providerKeeper, mocks) - - // assert mocks for expected calls to `StopConsumerChain` when closing the underlying channel - gomock.InOrder(testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...) - - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - ctx.BlockTime(), "chainID", 1, cryptoutil.NewCryptoIdentityFromIntSeed(90).ProviderConsAddress())) - - err := providerKeeper.QueueThrottledSlashPacketData(ctx, "chainID", 1, testkeeper.GetNewSlashPacketData()) - if err != nil { - t.Fatal(err) - } - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chainID", 2, testkeeper.GetNewVSCMaturedPacketData()) - if err != nil { - t.Fatal(err) - } - }, - expErr: false, - }, { description: "valid stop of consumer chain, all mock calls hit", setup: func(ctx sdk.Context, providerKeeper *providerkeeper.Keeper, mocks testkeeper.MockedKeepers) { diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index d63594dad1..63ea8dd9d5 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -17,7 +17,7 @@ import ( ccv "github.com/cosmos/interchain-security/v3/x/ccv/types" ) -// OnRecvVSCMaturedPacket handles a VSCMatured packet +// OnRecvVSCMaturedPacket handles a VSCMatured packet and returns a no-op result ack. func (k Keeper) OnRecvVSCMaturedPacket( ctx sdk.Context, packet channeltypes.Packet, @@ -34,12 +34,9 @@ func (k Keeper) OnRecvVSCMaturedPacket( panic(fmt.Errorf("VSCMaturedPacket received on unknown channel %s", packet.DestinationChannel)) } - if err := k.QueueThrottledVSCMaturedPacketData(ctx, chainID, packet.Sequence, data); err != nil { - return ccv.NewErrorAcknowledgementWithLog(ctx, fmt.Errorf( - "failed to queue VSCMatured packet data: %s", err.Error())) - } + k.HandleVSCMaturedPacket(ctx, chainID, data) - k.Logger(ctx).Info("VSCMaturedPacket received and enqueued", + k.Logger(ctx).Info("VSCMaturedPacket handled", "chainID", chainID, "vscID", data.ValsetUpdateId, ) @@ -48,35 +45,6 @@ func (k Keeper) OnRecvVSCMaturedPacket( return ack } -// HandleLeadingVSCMaturedPackets handles all VSCMatured packet data that has been queued this block, -// but does not need to be throttled. The handled data is then removed from the queue. -// -// Note: VSC matured packet data which is queued behind slash packet data CANNOT be -// handled until the leading slash packet data has been handled. This is to maintain -// the "VSC Maturity and Slashing Order" CCV property. If VSC matured packet data DOES NOT -// trail slash packet data for that consumer, it will be handled in this method, -// bypassing HandleThrottleQueues. -func (k Keeper) HandleLeadingVSCMaturedPackets(ctx sdk.Context) (vscMaturedHandledThisBlock int) { - vscMaturedHandledThisBlock = 0 - for _, chain := range k.GetAllConsumerChains(ctx) { - // Note: it's assumed the order of the vsc matured slice matches the order of the ibc seq nums slice, - // in that a vsc matured packet data at index i is associated with the ibc seq num at index i. - leadingVscMatured, ibcSeqNums := k.GetLeadingVSCMaturedData(ctx, chain.ChainId) - ibcSeqNumsHandled := []uint64{} - for idx, data := range leadingVscMatured { - if vscMaturedHandledThisBlock >= vscMaturedHandledPerBlockLimit { - // Break from inner for-loop, DeleteThrottledPacketData will still be called for this consumer - break - } - k.HandleVSCMaturedPacket(ctx, chain.ChainId, data) - vscMaturedHandledThisBlock++ - ibcSeqNumsHandled = append(ibcSeqNumsHandled, ibcSeqNums[idx]) - } - k.DeleteThrottledPacketData(ctx, chain.ChainId, ibcSeqNumsHandled...) - } - return vscMaturedHandledThisBlock -} - // HandleVSCMaturedPacket handles a VSCMatured packet. // // Note: This method should only panic for a system critical error like a @@ -270,18 +238,10 @@ func (k Keeper) QueueVSCPackets(ctx sdk.Context) { k.IncrementValidatorSetUpdateId(ctx) } -// EndBlockCIS contains the EndBlock logic needed for -// the Consumer Initiated Slashing sub-protocol -func (k Keeper) EndBlockCIS(ctx sdk.Context) { - // set the ValsetUpdateBlockHeight - blockHeight := uint64(ctx.BlockHeight()) + 1 - valUpdateID := k.GetValidatorSetUpdateId(ctx) - k.SetValsetUpdateBlockHeight(ctx, valUpdateID, blockHeight) - k.Logger(ctx).Debug("vscID was mapped to block height", "vscID", valUpdateID, "height", blockHeight) - - // Replenish slash meter if necessary, BEFORE executing slash packet throttling logic. - // This ensures the meter value is replenished, and not greater than the allowance (max value) - // for the block, before the throttling logic is executed. +// BeginBlockCIS contains the BeginBlock logic needed for the Consumer Initiated Slashing sub-protocol. +func (k Keeper) BeginBlockCIS(ctx sdk.Context) { + // Replenish slash meter if necessary. This ensures the meter value is replenished before handling any slash packets, + // and ensures the meter value is not greater than the allowance (max value) for the block. // // Note: CheckForSlashMeterReplenishment contains panics for the following scenarios, any of which should never occur // if the protocol is correct and external data is properly validated: @@ -291,23 +251,16 @@ func (k Keeper) EndBlockCIS(ctx sdk.Context) { // - Marshaling and/or store corruption errors. // - Setting invalid slash meter values (see SetSlashMeter). k.CheckForSlashMeterReplenishment(ctx) +} - // Handle leading vsc matured packets before throttling logic. - // - // Note: HandleLeadingVSCMaturedPackets contains panics for the following scenarios, any of which should never occur - // if the protocol is correct and external data is properly validated: - // - // - Marshaling and/or store corruption errors. - vscMaturedHandledThisBlock := k.HandleLeadingVSCMaturedPackets(ctx) - // Handle queue entries considering throttling logic. - // - // Note: HandleThrottleQueues contains panics for the following scenarios, any of which should never occur - // if the protocol is correct and external data is properly validated: - // - // - SlashMeter has not been set (which should be set in InitGenesis, see InitializeSlashMeter). - // - Marshaling and/or store corruption errors. - // - Setting invalid slash meter values (see SetSlashMeter). - k.HandleThrottleQueues(ctx, vscMaturedHandledThisBlock) +// EndBlockCIS contains the EndBlock logic needed for +// the Consumer Initiated Slashing sub-protocol +func (k Keeper) EndBlockCIS(ctx sdk.Context) { + // set the ValsetUpdateBlockHeight + blockHeight := uint64(ctx.BlockHeight()) + 1 + valUpdateID := k.GetValidatorSetUpdateId(ctx) + k.SetValsetUpdateBlockHeight(ctx, valUpdateID, blockHeight) + k.Logger(ctx).Debug("vscID was mapped to block height", "vscID", valUpdateID, "height", blockHeight) } // OnRecvSlashPacket delivers a received slash packet, validates it and @@ -358,20 +311,27 @@ func (k Keeper) OnRecvSlashPacket(ctx sdk.Context, packet channeltypes.Packet, d return channeltypes.NewResultAcknowledgement(ccv.V1Result) } - // Queue a slash entry to the global queue, which will be seen by the throttling logic - k.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - ctx.BlockTime(), // recv time - chainID, // consumer chain id that sent the packet - packet.Sequence, // IBC sequence number of the packet - providerConsAddr)) // Provider consensus address of val to be slashed - - // Queue slash packet data in the same (consumer chain specific) queue as vsc matured packet data, - // to enforce order of handling between the two packet data types. - if err := k.QueueThrottledSlashPacketData(ctx, chainID, packet.Sequence, data); err != nil { - return ccv.NewErrorAcknowledgementWithLog(ctx, fmt.Errorf("failed to queue slash packet data: %s", err.Error())) + meter := k.GetSlashMeter(ctx) + // Return bounce ack if meter is negative in value + if meter.IsNegative() { + k.Logger(ctx).Info("SlashPacket received, but meter is negative. Packet will be bounced", + "chainID", chainID, + "consumer cons addr", consumerConsAddr.String(), + "provider cons addr", providerConsAddr.String(), + "vscID", data.ValsetUpdateId, + "infractionType", data.Infraction, + ) + return channeltypes.NewResultAcknowledgement(ccv.SlashPacketBouncedResult) } - k.Logger(ctx).Info("slash packet received and enqueued", + // Subtract voting power that will be jailed/tombstoned from the slash meter, + // BEFORE handling slash packet. + meter = meter.Sub(k.GetEffectiveValPower(ctx, providerConsAddr)) + k.SetSlashMeter(ctx, meter) + + k.HandleSlashPacket(ctx, chainID, data) + + k.Logger(ctx).Info("slash packet received and handled", "chainID", chainID, "consumer cons addr", consumerConsAddr.String(), "provider cons addr", providerConsAddr.String(), @@ -379,7 +339,8 @@ func (k Keeper) OnRecvSlashPacket(ctx sdk.Context, packet channeltypes.Packet, d "infractionType", data.Infraction, ) - return channeltypes.NewResultAcknowledgement(ccv.V1Result) + // Return result ack that the packet was handled successfully + return channeltypes.NewResultAcknowledgement(ccv.SlashPacketHandledResult) } // ValidateSlashPacket validates a recv slash packet before it is diff --git a/x/ccv/provider/keeper/relay_test.go b/x/ccv/provider/keeper/relay_test.go index 590286261c..71e9528d64 100644 --- a/x/ccv/provider/keeper/relay_test.go +++ b/x/ccv/provider/keeper/relay_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "strings" "testing" - "time" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -11,6 +10,8 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "cosmossdk.io/math" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -93,10 +94,8 @@ func TestQueueVSCPackets(t *testing.T) { } // TestOnRecvVSCMaturedPacket tests the OnRecvVSCMaturedPacket method of the keeper. -// Particularly the behavior that VSC matured packet data should be handled immediately -// if the pending packet data queue is empty, and should be queued otherwise. // -// Note: Handling logic itself is not testing in here, just queueing behavior. +// Note: Handling logic itself is not tested here. func TestOnRecvVSCMaturedPacket(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() @@ -106,131 +105,69 @@ func TestOnRecvVSCMaturedPacket(t *testing.T) { providerKeeper.SetChannelToChain(ctx, "channel-1", "chain-1") providerKeeper.SetChannelToChain(ctx, "channel-2", "chain-2") - // Execute on recv for chain-1 + // Execute on recv for chain-1, confirm v1 result ack is returned ack := executeOnRecvVSCMaturedPacket(t, &providerKeeper, ctx, "channel-1", 1) require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) - // Assert that the packet data was queued for chain-1 - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - - // chain-2 queue empty - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - - // Now queue a slash packet data instance for chain-2, then confirm the on recv method - // queues the vsc matured behind the slash packet data - err := providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-2", 1, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) + // Now queue a slash packet data instance for chain-2, confirm v1 result ack is returned ack = executeOnRecvVSCMaturedPacket(t, &providerKeeper, ctx, "channel-2", 2) require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) - require.Equal(t, uint64(2), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - - // Chain-1 still has 1 packet data queued - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - - // Receive 5 more vsc matured packets for chain-2, then confirm chain-2 queue size is 7, chain-1 still size 1 - for i := 0; i < 5; i++ { - ack = executeOnRecvVSCMaturedPacket(t, &providerKeeper, ctx, "channel-2", uint64(i+3)) - require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) - } - require.Equal(t, uint64(7), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - - // Delete chain-2's data from its queue, then confirm the queue size is 0 - providerKeeper.DeleteThrottledPacketData(ctx, "chain-2", []uint64{1, 2, 3, 4, 5, 6, 7}...) - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) } -func TestHandleLeadingVSCMaturedPackets(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) +// TestOnRecvDowntimeSlashPacket tests the OnRecvSlashPacket method specifically for downtime slash packets. +func TestOnRecvDowntimeSlashPacket(t *testing.T) { + providerKeeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() providerKeeper.SetParams(ctx, providertypes.DefaultParams()) - vscData := getTenSampleVSCMaturedPacketData() - - // Set channel to chain, and chain to client mappings - // (faking multiple established consumer channels) + // Set channel to chain (faking multiple established channels) providerKeeper.SetChannelToChain(ctx, "channel-1", "chain-1") - providerKeeper.SetConsumerClientId(ctx, "chain-1", "client-1") providerKeeper.SetChannelToChain(ctx, "channel-2", "chain-2") - providerKeeper.SetConsumerClientId(ctx, "chain-2", "client-2") - // Queue some leading vsc matured packet data for chain-1 - err := providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-1", 1, vscData[0]) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-1", 2, vscData[1]) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-1", 3, vscData[2]) - require.NoError(t, err) + // Generate a new slash packet data instance with double sign infraction type + packetData := testkeeper.GetNewSlashPacketData() + packetData.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME - // Queue some trailing slash packet data (and a couple more vsc matured) - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-1", 4, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-1", 5, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-1", 6, vscData[3]) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-1", 7, vscData[4]) - require.NoError(t, err) + // Set a block height for the valset update id in the generated packet data + providerKeeper.SetValsetUpdateBlockHeight(ctx, packetData.ValsetUpdateId, uint64(15)) - // Queue some leading vsc matured packet data for chain-2 - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-2", 1, vscData[5]) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-2", 2, vscData[6]) - require.NoError(t, err) + // Set slash meter to negative value and assert a bounce ack is returned + providerKeeper.SetSlashMeter(ctx, math.NewInt(-5)) + ack := executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData) + require.Equal(t, channeltypes.NewResultAcknowledgement(ccv.SlashPacketBouncedResult), ack) - // And trailing slash packet data for chain-2 - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-2", 3, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-2", 4, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) + // Also bounced for chain-2 + ack = executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-2", 2, packetData) + require.Equal(t, channeltypes.NewResultAcknowledgement(ccv.SlashPacketBouncedResult), ack) + + // Now set slash meter to positive value and assert slash packet handled result is returned + providerKeeper.SetSlashMeter(ctx, math.NewInt(5)) + + // Mock call to GetEffectiveValPower, so that it returns 2. + providerAddr := providertypes.NewProviderConsAddress(packetData.Validator.Address) + calls := []*gomock.Call{ + mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr(ctx, providerAddr.ToSdkConsAddr()). + Return(stakingtypes.Validator{}, true).Times(1), + mocks.MockStakingKeeper.EXPECT().GetLastValidatorPower(ctx, gomock.Any()). + Return(int64(2)).Times(1), + } - // And one more trailing vsc matured packet for chain-2 - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-2", 5, vscData[7]) - require.NoError(t, err) + // Add mocks for slash packet handling + calls = append(calls, + testkeeper.GetMocksForHandleSlashPacket( + ctx, mocks, providerAddr, stakingtypes.Validator{Jailed: false}, true)..., + ) + gomock.InOrder(calls...) - // Set VSC Send timestamps for each recv vsc matured packet - providerKeeper.SetVscSendTimestamp(ctx, "chain-1", vscData[0].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-1", vscData[1].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-1", vscData[2].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-1", vscData[3].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-1", vscData[4].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-2", vscData[5].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-2", vscData[6].ValsetUpdateId, time.Now()) - providerKeeper.SetVscSendTimestamp(ctx, "chain-2", vscData[7].ValsetUpdateId, time.Now()) - - // Confirm each chain-specific queue has the expected number of packet data instances - require.Equal(t, uint64(7), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - require.Equal(t, uint64(5), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - - // Handle leading vsc matured packets and confirm queue sizes change for both chains - providerKeeper.HandleLeadingVSCMaturedPackets(ctx) - require.Equal(t, uint64(4), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - require.Equal(t, uint64(3), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - - // Confirm the leading vsc matured packet data was handled for both chains, - // but not the vsc matured packet data that trails slash data in the queue. - // This assertion is made by checking that VSC Send timestamps were deleted for - // handled vsc matured packet data. - _, found := providerKeeper.GetVscSendTimestamp(ctx, "chain-1", vscData[0].ValsetUpdateId) - require.False(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-1", vscData[1].ValsetUpdateId) - require.False(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-1", vscData[2].ValsetUpdateId) - require.False(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-1", vscData[3].ValsetUpdateId) - require.True(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-1", vscData[4].ValsetUpdateId) - require.True(t, found) + // Execute on recv and confirm slash packet handled result is returned + ack = executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData) + require.Equal(t, channeltypes.NewResultAcknowledgement(ccv.SlashPacketHandledResult), ack) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-2", vscData[5].ValsetUpdateId) - require.False(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-2", vscData[6].ValsetUpdateId) - require.False(t, found) - _, found = providerKeeper.GetVscSendTimestamp(ctx, "chain-2", vscData[7].ValsetUpdateId) - require.True(t, found) + // Require slash meter was decremented appropriately, 5-2=3 + require.Equal(t, int64(3), providerKeeper.GetSlashMeter(ctx).Int64()) } -// TestOnRecvSlashPacket tests the OnRecvSlashPacket method specifically for double-sign slash packets. +// TestOnRecvDoubleSignSlashPacket tests the OnRecvSlashPacket method specifically for double-sign slash packets. func TestOnRecvDoubleSignSlashPacket(t *testing.T) { providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() @@ -249,12 +186,8 @@ func TestOnRecvDoubleSignSlashPacket(t *testing.T) { // Receive the double-sign slash packet for chain-1 and confirm the expected acknowledgement ack := executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData) - require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) + require.Equal(t, channeltypes.NewResultAcknowledgement(ccv.V1Result), ack) - // Nothing should be queued - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) - require.Equal(t, 0, len(providerKeeper.GetAllGlobalSlashEntries(ctx))) require.True(t, providerKeeper.GetSlashLog(ctx, providertypes.NewProviderConsAddress(packetData.Validator.Address))) @@ -263,56 +196,6 @@ func TestOnRecvDoubleSignSlashPacket(t *testing.T) { require.False(t, providerKeeper.GetSlashLog(ctx, randomAddress)) } -// TestOnRecvSlashPacket tests the OnRecvSlashPacket method specifically for downtime slash packets, -// and how the method interacts with the parent and per-chain slash packet queues. -func TestOnRecvDowntimeSlashPacket(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - providerKeeper.SetParams(ctx, providertypes.DefaultParams()) - - // Set channel to chain (faking multiple established channels) - providerKeeper.SetChannelToChain(ctx, "channel-1", "chain-1") - providerKeeper.SetChannelToChain(ctx, "channel-2", "chain-2") - - // Generate a new slash packet data instance with downtime infraction type - packetData := testkeeper.GetNewSlashPacketData() - packetData.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME - - // Set a block height for the valset update id in the generated packet data - providerKeeper.SetValsetUpdateBlockHeight(ctx, packetData.ValsetUpdateId, uint64(15)) - - // Receive the downtime slash packet for chain-1 at time.Now() - ctx = ctx.WithBlockTime(time.Now()) - ack := executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData) - require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) - - // Confirm an entry was added to the global queue, and pending packet data was added to the per-chain queue - globalEntries := providerKeeper.GetAllGlobalSlashEntries(ctx) // parent queue - require.Equal(t, 1, len(globalEntries)) - require.Equal(t, "chain-1", globalEntries[0].ConsumerChainID) - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) // per chain queue - - // Generate a new downtime packet data instance with downtime infraction type - packetData = testkeeper.GetNewSlashPacketData() - packetData.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME - - // Set a block height for the valset update id in the generated packet data - providerKeeper.SetValsetUpdateBlockHeight(ctx, packetData.ValsetUpdateId, uint64(15)) - - // Receive a downtime slash packet for chain-2 at time.Now(Add(1 *time.Hour)) - ctx = ctx.WithBlockTime(time.Now().Add(1 * time.Hour)) - ack = executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-2", 2, packetData) - require.Equal(t, channeltypes.NewResultAcknowledgement([]byte{byte(1)}), ack) - - // Confirm sizes of parent queue and both per-chain queues - globalEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 2, len(globalEntries)) - require.Equal(t, "chain-1", globalEntries[0].ConsumerChainID) - require.Equal(t, "chain-2", globalEntries[1].ConsumerChainID) - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-1")) // per chain queue - require.Equal(t, uint64(1), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-2")) // per chain queue -} - func executeOnRecvVSCMaturedPacket(t *testing.T, providerKeeper *keeper.Keeper, ctx sdk.Context, channelID string, ibcSeqNum uint64, ) exported.Acknowledgement { diff --git a/x/ccv/provider/keeper/throttle.go b/x/ccv/provider/keeper/throttle.go index d8be629ee7..8232e37a25 100644 --- a/x/ccv/provider/keeper/throttle.go +++ b/x/ccv/provider/keeper/throttle.go @@ -11,64 +11,8 @@ import ( tmtypes "github.com/cometbft/cometbft/types" providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) -// This file contains functionality relevant to the throttling of slash and vsc matured packets, aka circuit breaker logic. - -const vscMaturedHandledPerBlockLimit = 100 - -// HandleThrottleQueues iterates over the global slash entry queue, and -// handles all or some portion of throttled (slash and/or VSC matured) packet data received from -// consumer chains. The slash meter is decremented appropriately in this method. -func (k Keeper) HandleThrottleQueues(ctx sdktypes.Context, vscMaturedHandledThisBlock int) { - meter := k.GetSlashMeter(ctx) - // Return if meter is negative in value - if meter.IsNegative() { - return - } - - // Return if vsc matured handle limit was already reached this block, during HandleLeadingVSCMaturedPackets. - // It makes no practical difference for throttling logic to execute next block. - // By doing this, we assure that all leading vsc matured packets were handled before any slash packets. - if vscMaturedHandledThisBlock >= vscMaturedHandledPerBlockLimit { - return - } - - // Obtain all global slash entries, where only some of them may be handled in this method, - // depending on the value of the slash meter. - allEntries := k.GetAllGlobalSlashEntries(ctx) - handledEntries := []providertypes.GlobalSlashEntry{} - - for _, globalEntry := range allEntries { - // Subtract voting power that will be jailed/tombstoned from the slash meter - providerAddr := providertypes.NewProviderConsAddress(globalEntry.ProviderValConsAddr) - meter = meter.Sub(k.GetEffectiveValPower(ctx, providerAddr)) - - // Handle one slash and any trailing vsc matured packet data instances by passing in - // chainID and appropriate callbacks, relevant packet data is deleted in this method. - - k.HandlePacketDataForChain(ctx, globalEntry.ConsumerChainID, k.HandleSlashPacket, k.HandleVSCMaturedPacket, vscMaturedHandledThisBlock) - handledEntries = append(handledEntries, globalEntry) - - // don't handle any more global entries if meter becomes negative in value - if meter.IsNegative() { - k.Logger(ctx).Info("negative slash meter value, no more slash packets will be handled", "meter", meter.Int64()) - break - } - } - - // Handled global entries are deleted after iteration is completed - k.DeleteGlobalSlashEntries(ctx, handledEntries...) - - // Persist current value for slash meter - k.SetSlashMeter(ctx, meter) - - if len(handledEntries) > 0 { - k.Logger(ctx).Info("handled global slash entries", "count", len(handledEntries), "meter", meter.Int64()) - } -} - // Obtains the effective validator power relevant to a validator consensus address. func (k Keeper) GetEffectiveValPower(ctx sdktypes.Context, valConsAddr providertypes.ProviderConsAddress, @@ -87,41 +31,6 @@ func (k Keeper) GetEffectiveValPower(ctx sdktypes.Context, } } -// HandlePacketDataForChain handles only the first queued slash packet relevant to the passed consumer chainID, -// and then handles any trailing vsc matured packets in that (consumer chain specific) throttled packet data queue. -// The handled data is then deleted from the queue. -// -// Note: Any packet data which is handled in this method is also deleted from the (consumer chain specific) queue. -func (k Keeper) HandlePacketDataForChain(ctx sdktypes.Context, consumerChainID string, - slashPacketHandler func(sdktypes.Context, string, ccvtypes.SlashPacketData), - vscMaturedPacketHandler func(sdktypes.Context, string, ccvtypes.VSCMaturedPacketData), - vscMaturedHandledThisBlock int, -) { - // Get slash packet data and trailing vsc matured packet data, handle it all. - slashFound, slashData, vscMaturedData, seqNums := k.GetSlashAndTrailingData(ctx, consumerChainID) - seqNumsHandled := []uint64{} - if slashFound { - slashPacketHandler(ctx, consumerChainID, slashData) - // Due to HandleLeadingVSCMaturedPackets() running before HandleThrottleQueues(), and the fact that - // HandleThrottleQueues() will return until all leading vsc matured have been handled, a slash packet - // should always be the first packet in the queue. So we can safely append the first seqNum here. - seqNumsHandled = append(seqNumsHandled, seqNums[0]) - } - for idx, vscMData := range vscMaturedData { - if vscMaturedHandledThisBlock >= vscMaturedHandledPerBlockLimit { - // Break from for-loop, DeleteThrottledPacketData will still be called for this consumer - break - } - vscMaturedPacketHandler(ctx, consumerChainID, vscMData) - vscMaturedHandledThisBlock++ - // Append seq num for this vsc matured packet - seqNumsHandled = append(seqNumsHandled, seqNums[idx+1]) // Note idx+1, since slash packet is at index 0 - } - - // Delete handled data after it has all been handled. - k.DeleteThrottledPacketData(ctx, consumerChainID, seqNumsHandled...) -} - // InitializeSlashMeter initializes the slash meter to it's max value (also its allowance), // and sets the replenish time candidate to one replenish period from current block time. func (k Keeper) InitializeSlashMeter(ctx sdktypes.Context) { @@ -206,353 +115,6 @@ func (k Keeper) GetSlashMeterAllowance(ctx sdktypes.Context) math.Int { return roundedInt } -// -// CRUD section -// - -// QueueGlobalSlashEntry queues an entry to the "global" slash packet queue, used for throttling val power changes -// related to jailing/tombstoning over time. This "global" queue is used to coordinate the order of slash packet handling -// between chains, whereas the chain-specific queue is used to coordinate the order of slash and vsc matured packets -// relevant to each chain. -func (k Keeper) QueueGlobalSlashEntry(ctx sdktypes.Context, entry providertypes.GlobalSlashEntry) { - store := ctx.KVStore(k.storeKey) - key := providertypes.GlobalSlashEntryKey(entry) - bz := entry.ProviderValConsAddr - store.Set(key, bz) -} - -// DeleteGlobalSlashEntriesForConsumer deletes all pending slash packet entries in the global queue, -// only relevant to a single consumer. -func (k Keeper) DeleteGlobalSlashEntriesForConsumer(ctx sdktypes.Context, consumerChainID string) { - allEntries := k.GetAllGlobalSlashEntries(ctx) - entriesToDel := []providertypes.GlobalSlashEntry{} - - for _, entry := range allEntries { - if entry.ConsumerChainID == consumerChainID { - entriesToDel = append(entriesToDel, entry) - } - } - k.DeleteGlobalSlashEntries(ctx, entriesToDel...) -} - -// 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) - iterator := sdktypes.KVStorePrefixIterator(store, []byte{providertypes.GlobalSlashEntryBytePrefix}) - defer iterator.Close() - - entries := []providertypes.GlobalSlashEntry{} - - for ; iterator.Valid(); iterator.Next() { - // MustParseGlobalSlashEntryKey should not panic, since we should be iterating over keys that're - // assumed to be correctly serialized in QueueGlobalSlashEntry. - recvTime, chainID, ibcSeqNum := providertypes.MustParseGlobalSlashEntryKey(iterator.Key()) - valAddr := providertypes.NewProviderConsAddress(iterator.Value()) - entry := providertypes.NewGlobalSlashEntry(recvTime, chainID, ibcSeqNum, valAddr) - entries = append(entries, entry) - } - return entries -} - -// DeleteGlobalSlashEntries deletes the given global entries from the global slash queue -func (k Keeper) DeleteGlobalSlashEntries(ctx sdktypes.Context, entries ...providertypes.GlobalSlashEntry) { - store := ctx.KVStore(k.storeKey) - for _, entry := range entries { - store.Delete(providertypes.GlobalSlashEntryKey(entry)) - } -} - -// Pending packet data type enum, used to encode the type of packet data stored at each entry in the mutual queue. -const ( - slashPacketData byte = iota - vscMaturedPacketData -) - -// GetThrottledPacketDataSize returns the size of the throttled packet data queue for the given consumer chain -func (k Keeper) GetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID string) uint64 { - store := ctx.KVStore(k.storeKey) - key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) - var size uint64 - bz := store.Get(key) - if bz == nil { - size = 0 - } else { - size = sdktypes.BigEndianToUint64(bz) - } - return size -} - -// SetThrottledPacketDataSize sets the size of the throttled packet data queue for the given consumer chain -func (k Keeper) SetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID string, size uint64) { - // Sanity check to ensure that the chain-specific throttled packet data queue does not grow too - // large for a single consumer chain. This check ensures that binaries would panic deterministically - // if the queue does grow too large. MaxThrottledPackets should be set accordingly (quite large). - if size >= uint64(k.GetMaxThrottledPackets(ctx)) { - panic(fmt.Sprintf("throttled packet data queue for chain %s is too large: %d", consumerChainID, size)) - } - - store := ctx.KVStore(k.storeKey) - key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) - bz := sdktypes.Uint64ToBigEndian(size) - store.Set(key, bz) -} - -// IncrementThrottledPacketDataSize increments the size of the throttled packet data -// queue for the given consumer chain. -func (k Keeper) IncrementThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID string) { - size := k.GetThrottledPacketDataSize(ctx, consumerChainID) - k.SetThrottledPacketDataSize(ctx, consumerChainID, size+1) - k.Logger(ctx).Debug("incremented throttled packets size", - "chainID", consumerChainID, - "size", size+1, - ) -} - -// QueueThrottledSlashPacketData queues the slash packet data for a chain-specific throttled packet data queue. -// -// Note: This queue is shared between pending slash packet data and pending vsc matured packet data. -func (k Keeper) QueueThrottledSlashPacketData( - ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, data ccvtypes.SlashPacketData, -) error { - return k.QueueThrottledPacketData(ctx, consumerChainID, ibcSeqNum, data) -} - -// QueueThrottledVSCMaturedPacketData queues the vsc matured packet data for a chain-specific throttled packet data queue. -// -// Note: This queue is shared between pending slash packet data and pending vsc matured packet data. -func (k Keeper) QueueThrottledVSCMaturedPacketData( - ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, data ccvtypes.VSCMaturedPacketData, -) error { - return k.QueueThrottledPacketData(ctx, consumerChainID, ibcSeqNum, data) -} - -// QueueThrottledPacketData queues a slash packet data or vsc matured packet data instance -// for the given consumer chain's queue. -// -// Note: This method returns an error because it is called from -// OnRecvSlashPacket and OnRecvVSCMaturedPacket, meaning we can return an ibc err ack to the -// counter party chain on error, instead of panicking this chain. -func (k Keeper) QueueThrottledPacketData( - ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, -) error { - store := ctx.KVStore(k.storeKey) - - var bz []byte - var err error - switch data := packetData.(type) { - case ccvtypes.SlashPacketData: - bz, err = data.Marshal() - if err != nil { - return fmt.Errorf("failed to marshal slash packet data: %v", err) - } - bz = append([]byte{slashPacketData}, bz...) - case ccvtypes.VSCMaturedPacketData: - bz, err = data.Marshal() - if err != nil { - return fmt.Errorf("failed to marshal vsc matured packet data: %v", err) - } - bz = append([]byte{vscMaturedPacketData}, bz...) - default: - // Indicates a developer error, this method should only be called - // by tests, QueueThrottledSlashPacketData, or QueueThrottledVSCMaturedPacketData. - panic(fmt.Sprintf("unexpected packet data type: %T", data)) - } - - store.Set(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum), bz) - k.IncrementThrottledPacketDataSize(ctx, consumerChainID) - return nil -} - -// GetLeadingVSCMaturedData returns the leading vsc matured packet data instances -// for a chain-specific throttled packet data queue. Ie the vsc matured packet data instances -// that do not have any slash packet data instances preceding them in the queue for consumerChainID. -func (k Keeper) GetLeadingVSCMaturedData(ctx sdktypes.Context, consumerChainID string) ( - vscMaturedData []ccvtypes.VSCMaturedPacketData, ibcSeqNums []uint64, -) { - store := ctx.KVStore(k.storeKey) - iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) - defer iterator.Close() - - // Iterate over the throttled packet data queue, - // and return vsc matured packet data instances until we encounter a slash packet data instance. - vscMaturedData = []ccvtypes.VSCMaturedPacketData{} - ibcSeqNums = []uint64{} - for ; iterator.Valid(); iterator.Next() { - - bz := iterator.Value() - if bz[0] == slashPacketData { - break - } else if bz[0] != vscMaturedPacketData { - // This case would indicate a developer error or store corruption, - // since QueueThrottledPacketData should only queue slash packet data or vsc matured packet data. - panic(fmt.Sprintf("unexpected packet data type: %d", bz[0])) - } - - var data ccvtypes.VSCMaturedPacketData - err := data.Unmarshal(bz[1:]) - if err != nil { - // An error here would indicate something is very wrong, - // vsc matured packet data is assumed to be correctly serialized in QueueThrottledPacketData. - panic(fmt.Sprintf("failed to unmarshal vsc matured packet data: %v", err)) - } - - vscMaturedData = append(vscMaturedData, data) - // The below func should not panic, since we should be iterating over keys that're - // assumed to be correctly serialized in QueueThrottledPacketData. - _, ibcSeqNum := providertypes.MustParseThrottledPacketDataKey(iterator.Key()) - ibcSeqNums = append(ibcSeqNums, ibcSeqNum) - } - return vscMaturedData, ibcSeqNums -} - -// 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 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 - // and trailing vsc matured packet data instances. This is used by caller to delete the - // data after it has been handled. - ibcSeqNums []uint64, -) { - store := ctx.KVStore(k.storeKey) - iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) - defer iterator.Close() - - slashFound = false - slashData = ccvtypes.SlashPacketData{} - vscMaturedData = []ccvtypes.VSCMaturedPacketData{} - ibcSeqNums = []uint64{} - - for ; iterator.Valid(); iterator.Next() { - - bz := iterator.Value() - if bz[0] == slashPacketData { - if slashFound { - // Break for-loop, we've already found first slash packet data instance. - break - } else { - if err := slashData.Unmarshal(bz[1:]); err != nil { - // An error here would indicate something is very wrong, - // slash packet data is assumed to be correctly serialized in QueueThrottledPacketData. - panic(fmt.Sprintf("failed to unmarshal slash packet data: %v", err)) - } - slashFound = true - } - } else if bz[0] == vscMaturedPacketData { - vscMData := ccvtypes.VSCMaturedPacketData{} - if err := vscMData.Unmarshal(bz[1:]); err != nil { - // An error here would indicate something is very wrong, - // vsc matured packet data is assumed to be correctly serialized in QueueThrottledPacketData. - panic(fmt.Sprintf("failed to unmarshal vsc matured packet data: %v", err)) - } - vscMaturedData = append(vscMaturedData, vscMData) - } else { - // This case would indicate a developer error or store corruption, - // since QueueThrottledPacketData should only queue slash packet data or vsc matured packet data. - panic("invalid packet data type") - } - // The below func should not panic, since we should be iterating over keys that're - // assumed to be correctly serialized in QueueThrottledPacketData. - _, ibcSeqNum := providertypes.MustParseThrottledPacketDataKey(iterator.Key()) - ibcSeqNums = append(ibcSeqNums, ibcSeqNum) - } - return slashFound, slashData, vscMaturedData, ibcSeqNums -} - -// GetAllThrottledPacketData returns all throttled packet data for a specific consumer chain. -// -// Note: This method is only used by tests and queries, hence why it returns redundant data as different types. -// Since this method executes on query, no panics are explicitly included. -func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID string) ( - slashData []ccvtypes.SlashPacketData, vscMaturedData []ccvtypes.VSCMaturedPacketData, - rawOrderedData []interface{}, ibcSeqNums []uint64, -) { - slashData = []ccvtypes.SlashPacketData{} - vscMaturedData = []ccvtypes.VSCMaturedPacketData{} - rawOrderedData = []interface{}{} - ibcSeqNums = []uint64{} - - store := ctx.KVStore(k.storeKey) - iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - bz := iterator.Value() - switch bz[0] { - case slashPacketData: - d := ccvtypes.SlashPacketData{} - if err := d.Unmarshal(bz[1:]); err != nil { - k.Logger(ctx).Error(fmt.Sprintf("failed to unmarshal slash packet data: %v", err)) - continue - } - slashData = append(slashData, d) - rawOrderedData = append(rawOrderedData, d) - case vscMaturedPacketData: - d := ccvtypes.VSCMaturedPacketData{} - if err := d.Unmarshal(bz[1:]); err != nil { - k.Logger(ctx).Error(fmt.Sprintf("failed to unmarshal vsc matured packet data: %v", err)) - continue - } - vscMaturedData = append(vscMaturedData, d) - rawOrderedData = append(rawOrderedData, d) - default: - k.Logger(ctx).Error(fmt.Sprintf("invalid packet data type: %v", bz[0])) - continue - } - _, ibcSeqNum, err := providertypes.ParseThrottledPacketDataKey(iterator.Key()) - if err != nil { - k.Logger(ctx).Error(fmt.Sprintf("failed to parse throttled packet data key: %v", err)) - continue - } - ibcSeqNums = append(ibcSeqNums, ibcSeqNum) - } - - return slashData, vscMaturedData, rawOrderedData, ibcSeqNums -} - -// DeleteAllPacketDataForConsumer deletes all queued packet data for the given consumer chain. -func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consumerChainID string) { - store := ctx.KVStore(k.storeKey) - iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := sdktypes.KVStorePrefixIterator(store, iteratorPrefix) - defer iterator.Close() - - keysToDel := [][]byte{} - for ; iterator.Valid(); iterator.Next() { - keysToDel = append(keysToDel, iterator.Key()) - } - // Delete data for this consumer - for _, key := range keysToDel { - store.Delete(key) - } - - // Delete size of data queue for this consumer - store.Delete(providertypes.ThrottledPacketDataSizeKey(consumerChainID)) -} - -// DeleteThrottledPacketData deletes the given throttled packet data instances -// (specified by their ibc seq number) from the chain-specific throttled packet data queue. -func (k Keeper) DeleteThrottledPacketData(ctx sdktypes.Context, consumerChainID string, ibcSeqNumbers ...uint64) { - store := ctx.KVStore(k.storeKey) - for _, ibcSeqNum := range ibcSeqNumbers { - store.Delete(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) - } - // Decrement the size of the pending packet data queue - sizeBeforeDeletion := k.GetThrottledPacketDataSize(ctx, consumerChainID) - k.SetThrottledPacketDataSize(ctx, consumerChainID, sizeBeforeDeletion-uint64(len(ibcSeqNumbers))) -} - // GetSlashMeter returns a meter (persisted as a signed int) which stores an amount of voting power, corresponding // to an allowance of validators that can be jailed/tombstoned over time. // diff --git a/x/ccv/provider/keeper/throttle_test.go b/x/ccv/provider/keeper/throttle_test.go index a5356b0dc0..24e8c0ddde 100644 --- a/x/ccv/provider/keeper/throttle_test.go +++ b/x/ccv/provider/keeper/throttle_test.go @@ -1,13 +1,11 @@ package keeper_test import ( - "math/rand" "testing" "time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" "cosmossdk.io/math" @@ -15,168 +13,10 @@ import ( tmtypes "github.com/cometbft/cometbft/types" - cryptoutil "github.com/cosmos/interchain-security/v3/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper" - "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper" providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) -// TestHandlePacketDataForChain tests the HandlePacketDataForChain function. Note: Only one consumer is tested here, -// but multiple consumers are tested in TestPendingPacketData. -func TestHandlePacketDataForChain(t *testing.T) { - testCases := []struct { - name string - chainID string - // Pending packet data that will be queued in the order specified by the slice - dataToQueue []interface{} - // Indexes of packet data from dataToQueue that are expected to be handled and deleted from store - expectedHandledIndexes []int - }{ - { - "no packets", - "my-cool-chain", - []interface{}{}, - []int{}, - }, - { - "one slash packet should be handled", - "chain-37", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - }, - []int{0}, - }, - { - "one slash packet followed by one vsc matured packet should all be handled", - "chain-222", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - }, - []int{0, 1}, - }, - { - "one slash packet followed by multiple vsc matured packets should all be handled", - "chain-2223", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - }, - []int{0, 1, 2, 3, 4, 5}, - }, - { - "multiple slash packets followed by multiple vsc matured packets should only handle first slash packet", - "chain-9", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - }, - []int{0}, - }, - { - "vsc matured packets sandwiched between slash packets should handle everything but the last slash packet", - "chain-000", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewSlashPacketData(), // 10th index not included in expectedHandledIndexes - }, - []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, - }, - { - "alternating slash and vsc matured packets should handle only the first slash, and trailing vsc matured packets", - "chain-00000", - []interface{}{ - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - testkeeper.GetNewSlashPacketData(), - testkeeper.GetNewVSCMaturedPacketData(), - }, - []int{0, 1, 2}, - }, - } - - for _, tc := range testCases { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - providerKeeper.SetParams(ctx, providertypes.DefaultParams()) - - // Queue throttled packet data, where chainID is arbitrary, and ibc seq number is index of the data instance - for i, data := range tc.dataToQueue { - err := providerKeeper.QueueThrottledPacketData(ctx, tc.chainID, uint64(i), data) - require.NoError(t, err) - } - - // Define our handler callbacks to simply store the data instances that are handled - handledData := []interface{}{} - slashHandleCounter := func(ctx sdktypes.Context, chainID string, data ccvtypes.SlashPacketData) { - handledData = append(handledData, data) - } - vscMaturedHandleCounter := func(ctx sdktypes.Context, chainID string, data ccvtypes.VSCMaturedPacketData) { - handledData = append(handledData, data) - } - - providerKeeper.HandlePacketDataForChain(ctx, tc.chainID, slashHandleCounter, vscMaturedHandleCounter, 0) - - // Assert number of handled data instances matches expected number - require.Equal(t, len(tc.expectedHandledIndexes), len(handledData)) - - // Assert handled data instances match expected value - for i, expectedIndex := range tc.expectedHandledIndexes { - require.Equal(t, tc.dataToQueue[expectedIndex], handledData[i]) - } - - // Sanity check, Assert that only the first handled packet is a slash packet, and the rest are vsc matured packets - for idx, instance := range handledData { - switch instance.(type) { - case ccvtypes.SlashPacketData: - require.Equal(t, 0, idx) - case ccvtypes.VSCMaturedPacketData: - default: - require.Fail(t, "unexpected data instance type") - } - } - - // Assert that the unhandled queued data instances are as expected (i.e no unexpected deletions) - expectedDataThatsLeft := []interface{}{} - for idx, data := range tc.dataToQueue { - if !slices.Contains(tc.expectedHandledIndexes, idx) { - expectedDataThatsLeft = append(expectedDataThatsLeft, data) - } - } - - _, _, dataThatsLeft, _ := providerKeeper.GetAllThrottledPacketData(ctx, tc.chainID) - require.Equal(t, expectedDataThatsLeft, dataThatsLeft) - - // Assert that each instance of handled data is deleted from the persisted queue (i.e deletions where expected) - for _, dataInstance := range handledData { - require.NotContains(t, dataThatsLeft, dataInstance) - } - } -} - // TestSlashMeterReplenishment tests the CheckForSlashMeterReplenishment, ReplenishSlashMeter, // and InitializeSlashMeter methods. func TestSlashMeterReplenishment(t *testing.T) { @@ -627,628 +467,6 @@ func TestGetSlashMeterAllowance(t *testing.T) { } } -// TestGlobalSlashEntries tests the queue and iteration functions for global slash entries, -// with assertion of FIFO ordering -func TestGlobalSlashEntries(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - // Consistent time for "now" - now := time.Now().UTC() - - globalEntries := providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 0, len(globalEntries)) - - // Queue 3 entries for chainIDs 0, 1, 2, note their respective ibc seq nums are - // ordered differently than the chainIDs would be iterated. - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Local(), "chain-0", 15, cryptoutil.NewCryptoIdentityFromIntSeed(10).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Local(), "chain-1", 10, cryptoutil.NewCryptoIdentityFromIntSeed(11).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Local(), "chain-2", 5, cryptoutil.NewCryptoIdentityFromIntSeed(12).ProviderConsAddress())) - - globalEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 3, len(globalEntries)) - - // Queue 3 entries for chainIDs 0, 1, 2 an hour later, with incremented ibc seq nums - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Add(time.Hour).Local(), "chain-0", 16, // should appear last for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(20).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Add(time.Hour).Local(), "chain-1", 11, // should appear middle for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(21).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry( - now.Add(time.Hour).Local(), "chain-2", 6, // should appear first for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(22).ProviderConsAddress())) - - // Retrieve entries from store - globalEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 6, len(globalEntries)) - - // Assert that entries are obtained in FIFO order according to block time, then ibc seq num - require.Equal(t, "chain-2", globalEntries[0].ConsumerChainID) - require.Equal(t, "chain-1", globalEntries[1].ConsumerChainID) - require.Equal(t, "chain-0", globalEntries[2].ConsumerChainID) - require.Equal(t, "chain-2", globalEntries[3].ConsumerChainID) - require.Equal(t, "chain-1", globalEntries[4].ConsumerChainID) - require.Equal(t, "chain-0", globalEntries[5].ConsumerChainID) - - // Queue 3 entries for chainIDs 5, 6, 7 another hour later - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(now.Add(2*time.Hour).Local(), "chain-5", 50, // should appear middle for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(96).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(now.Add(2*time.Hour).Local(), "chain-6", 60, // should appear last for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(97).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(now.Add(2*time.Hour).Local(), "chain-7", 40, // should appear first for this recv time - cryptoutil.NewCryptoIdentityFromIntSeed(98).ProviderConsAddress())) - // Retrieve entries from store - globalEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 9, len(globalEntries)) - - // Assert that entries are obtained in FIFO order according to block time, then ibc seq num - require.Equal(t, "chain-2", globalEntries[0].ConsumerChainID) - require.Equal(t, "chain-1", globalEntries[1].ConsumerChainID) - require.Equal(t, "chain-0", globalEntries[2].ConsumerChainID) - require.Equal(t, "chain-2", globalEntries[3].ConsumerChainID) - require.Equal(t, "chain-1", globalEntries[4].ConsumerChainID) - require.Equal(t, "chain-0", globalEntries[5].ConsumerChainID) - require.Equal(t, "chain-7", globalEntries[6].ConsumerChainID) - require.Equal(t, "chain-5", globalEntries[7].ConsumerChainID) - require.Equal(t, "chain-6", globalEntries[8].ConsumerChainID) - - // Assert each field is as expected for all 9 entries - require.Equal(t, uint64(5), globalEntries[0].IbcSeqNum) - require.Equal(t, uint64(10), globalEntries[1].IbcSeqNum) - require.Equal(t, uint64(15), globalEntries[2].IbcSeqNum) - require.Equal(t, uint64(6), globalEntries[3].IbcSeqNum) - require.Equal(t, uint64(11), globalEntries[4].IbcSeqNum) - require.Equal(t, uint64(16), globalEntries[5].IbcSeqNum) - require.Equal(t, uint64(40), globalEntries[6].IbcSeqNum) - require.Equal(t, uint64(50), globalEntries[7].IbcSeqNum) - require.Equal(t, uint64(60), globalEntries[8].IbcSeqNum) - - require.Equal(t, now, globalEntries[0].RecvTime) - require.Equal(t, now, globalEntries[1].RecvTime) - require.Equal(t, now, globalEntries[2].RecvTime) - require.Equal(t, now.Add(time.Hour).UTC(), globalEntries[3].RecvTime) - require.Equal(t, now.Add(time.Hour).UTC(), globalEntries[4].RecvTime) - require.Equal(t, now.Add(time.Hour).UTC(), globalEntries[5].RecvTime) - require.Equal(t, now.Add(2*time.Hour).UTC(), globalEntries[6].RecvTime) - require.Equal(t, now.Add(2*time.Hour).UTC(), globalEntries[7].RecvTime) - require.Equal(t, now.Add(2*time.Hour).UTC(), globalEntries[8].RecvTime) -} - -// Tests DeleteGlobalSlashEntriesForConsumer. -func TestDeleteGlobalSlashEntriesForConsumer(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx( - t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - // Queue 2 global entries for a consumer chain ID - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(time.Now().Add(time.Hour), "chain-78", 1, - cryptoutil.NewCryptoIdentityFromIntSeed(78).ProviderConsAddress())) - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(time.Now().Add(time.Hour), "chain-78", 2, - cryptoutil.NewCryptoIdentityFromIntSeed(79).ProviderConsAddress())) - - // Queue 1 global entry for two other consumer chain IDs - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(time.Now().Add(2*time.Hour), "chain-79", 1, - cryptoutil.NewCryptoIdentityFromIntSeed(80).ProviderConsAddress())) - - providerKeeper.QueueGlobalSlashEntry(ctx, - providertypes.NewGlobalSlashEntry(time.Now().Add(3*time.Hour), "chain-80", 1, - cryptoutil.NewCryptoIdentityFromIntSeed(81).ProviderConsAddress())) - - // Delete entries for chain-78, confirm those are deleted, and the other two remain - providerKeeper.DeleteGlobalSlashEntriesForConsumer(ctx, "chain-78") - allEntries := providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 2, len(allEntries)) - require.Equal(t, "chain-79", allEntries[0].ConsumerChainID) - require.Equal(t, "chain-80", allEntries[1].ConsumerChainID) -} - -// TestGlobalSlashEntryDeletion tests the deletion function for -// global slash entries with assertion of FIFO ordering. -func TestGlobalSlashEntryDeletion(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - now := time.Now() - - entries := providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 0, len(entries)) - - providerConsAddrs := []providertypes.ProviderConsAddress{ - cryptoutil.NewCryptoIdentityFromIntSeed(1).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(2).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(3).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(4).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(5).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(6).ProviderConsAddress(), - cryptoutil.NewCryptoIdentityFromIntSeed(7).ProviderConsAddress(), - } - - // Instantiate entries in the expected order we wish to get them back as (ordered by recv time) - entries = []providertypes.GlobalSlashEntry{} - entries = append(entries, providertypes.NewGlobalSlashEntry(now, "chain-0", 1, providerConsAddrs[0])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(time.Hour).UTC(), "chain-1", 178, providerConsAddrs[1])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(2*time.Hour).Local(), "chain-2", 89, providerConsAddrs[2])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(3*time.Hour).In(time.FixedZone("UTC-8", -8*60*60)), "chain-3", 23423, providerConsAddrs[3])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(4*time.Hour).Local(), "chain-4", 323, providerConsAddrs[4])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(5*time.Hour).UTC(), "chain-5", 18, providerConsAddrs[5])) - entries = append(entries, providertypes.NewGlobalSlashEntry(now.Add(6*time.Hour).Local(), "chain-6", 2, providerConsAddrs[6])) - - // Instantiate shuffled copy of above slice - shuffledEntries := append([]providertypes.GlobalSlashEntry{}, entries...) - seed := time.Now().UnixNano() - rng := rand.New(rand.NewSource(seed)) - rng.Shuffle(len(shuffledEntries), func(i, j int) { - shuffledEntries[i], shuffledEntries[j] = shuffledEntries[j], shuffledEntries[i] - }) - - // Queue 7 slash packets with various block times in random order - for _, entry := range shuffledEntries { - providerKeeper.QueueGlobalSlashEntry(ctx, entry) - } - - gotEntries := providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 7, len(gotEntries)) - - // Assert obtained order is decided upon via packet recvTime, not insertion order - for i, gotEntry := range gotEntries { - expectedEntry := entries[i] - require.Equal(t, expectedEntry, gotEntry) - } - - // Confirm no mutations have occurred from test helper - gotEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 7, len(gotEntries)) - - // Delete packets 1, 3, 5 (0-indexed) - providerKeeper.DeleteGlobalSlashEntries(ctx, gotEntries[1], gotEntries[3], gotEntries[5]) - - // Assert deletion and ordering - gotEntries = providerKeeper.GetAllGlobalSlashEntries(ctx) - require.Equal(t, 4, len(gotEntries)) - require.Equal(t, "chain-0", gotEntries[0].ConsumerChainID) - // entry 1 was deleted - require.Equal(t, "chain-2", gotEntries[1].ConsumerChainID) - // entry 3 was deleted - require.Equal(t, "chain-4", gotEntries[2].ConsumerChainID) - // entry 5 was deleted - require.Equal(t, "chain-6", gotEntries[3].ConsumerChainID) -} - -// TestThrottledPacketData tests chain-specific throttled packet data queuing, -// iteration and deletion functionality. -func TestThrottledPacketData(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - providerKeeper.SetParams(ctx, providertypes.DefaultParams()) - - packetDataForMultipleConsumers := []struct { - chainID string - instances []throttledPacketDataInstance - - // Expected order of data instances after retrieval from store, before deletion (specified by instance index) - expectedOrder []int - // Data instances to delete (specified by instance index) - toDelete []int - // Expected order of data instances after deletion (specified by instance index) - expectedOrderAfterDeletion []int - }{ - // Note, duplicate ibc sequence numbers are not tested, as we assume ibc behaves correctly - { - chainID: "chain-0", - instances: []throttledPacketDataInstance{ - {IbcSeqNum: 0, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 1, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 2, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 3, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 4, Data: testkeeper.GetNewSlashPacketData()}, - }, - expectedOrder: []int{0, 1, 2, 3, 4}, - toDelete: []int{0, 2, 4}, - expectedOrderAfterDeletion: []int{1, 3}, - }, - { - chainID: "chain-7", - instances: []throttledPacketDataInstance{ - {IbcSeqNum: 96, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 78, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 12, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 0, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 1, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 78972, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 9999999999999999999, Data: testkeeper.GetNewSlashPacketData()}, - }, - expectedOrder: []int{3, 4, 2, 1, 0, 5, 6}, - toDelete: []int{0, 1, 2, 3, 4, 5}, - expectedOrderAfterDeletion: []int{6}, - }, - { - chainID: "chain-thats-not-0-or-7", - instances: []throttledPacketDataInstance{ - {IbcSeqNum: 9, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 8, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 7, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 6, Data: testkeeper.GetNewSlashPacketData()}, - {IbcSeqNum: 5, Data: testkeeper.GetNewVSCMaturedPacketData()}, - {IbcSeqNum: 1, Data: testkeeper.GetNewVSCMaturedPacketData()}, - }, - expectedOrder: []int{5, 4, 3, 2, 1, 0}, - toDelete: []int{1, 2, 3, 4, 5}, - expectedOrderAfterDeletion: []int{0}, - }, - } - - // Queue all packet data at once - for _, chainData := range packetDataForMultipleConsumers { - for _, dataInstance := range chainData.instances { - err := providerKeeper.QueueThrottledPacketData(ctx, chainData.chainID, dataInstance.IbcSeqNum, dataInstance.Data) - require.NoError(t, err) - } - } - - // Assert retrieval ordering for each chain - for _, chainData := range packetDataForMultipleConsumers { - expectedInstances := getOrderedInstances(chainData.instances, chainData.expectedOrder) - assertPendingPacketDataOrdering(t, &providerKeeper, ctx, chainData.chainID, expectedInstances) - } - - // Delete specified data all at once - for _, chainData := range packetDataForMultipleConsumers { - for _, i := range chainData.toDelete { - providerKeeper.DeleteThrottledPacketData(ctx, chainData.chainID, chainData.instances[i].IbcSeqNum) - } - } - - // Assert retrieval ordering after deletion for each chain - for _, chainData := range packetDataForMultipleConsumers { - expectedInstances := getOrderedInstances(chainData.instances, chainData.expectedOrderAfterDeletion) - assertPendingPacketDataOrdering(t, &providerKeeper, ctx, chainData.chainID, expectedInstances) - } -} - -func TestGetLeadingVSCMaturedData(t *testing.T) { - // Instantiate some sample data - slashData := getTenSampleSlashPacketData() - vscMaturedData := getTenSampleVSCMaturedPacketData() - - testCases := []struct { - name string - dataToQueue []throttledPacketDataInstance - expectedReturnData []ccvtypes.VSCMaturedPacketData - expectedReturnSeqs []uint64 - }{ - { - name: "no data", - dataToQueue: []throttledPacketDataInstance{}, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{}, - expectedReturnSeqs: []uint64{}, - }, - { - name: "one slash", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 889, Data: slashData[0]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{}, - expectedReturnSeqs: []uint64{}, - }, - { - name: "one vsc matured", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 54, Data: vscMaturedData[0]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{vscMaturedData[0]}, - expectedReturnSeqs: []uint64{54}, - }, - { - name: "one vsc matured trailing one slash", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 87, Data: slashData[0]}, - {IbcSeqNum: 88, Data: vscMaturedData[0]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{}, // Nothing returned - expectedReturnSeqs: []uint64{}, // Nothing returned - }, - { - name: "one vsc matured trailing multiple slash", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 87, Data: slashData[0]}, - {IbcSeqNum: 88, Data: slashData[1]}, - {IbcSeqNum: 89, Data: slashData[2]}, - {IbcSeqNum: 90, Data: vscMaturedData[0]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{}, // Nothing returned - expectedReturnSeqs: []uint64{}, // Nothing returned - }, - { - name: "one vsc matured leading multiple slash", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 87, Data: vscMaturedData[0]}, - {IbcSeqNum: 88, Data: slashData[0]}, - {IbcSeqNum: 89, Data: slashData[1]}, - {IbcSeqNum: 90, Data: slashData[2]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{vscMaturedData[0]}, - expectedReturnSeqs: []uint64{87}, - }, - { - name: "multiple vsc matured leading multiple slash", - dataToQueue: []throttledPacketDataInstance{ - {IbcSeqNum: 102, Data: vscMaturedData[0]}, - {IbcSeqNum: 103, Data: vscMaturedData[1]}, - {IbcSeqNum: 104, Data: vscMaturedData[2]}, - {IbcSeqNum: 105, Data: slashData[0]}, - {IbcSeqNum: 106, Data: slashData[1]}, - {IbcSeqNum: 107, Data: slashData[2]}, - }, - expectedReturnData: []ccvtypes.VSCMaturedPacketData{vscMaturedData[0], vscMaturedData[1], vscMaturedData[2]}, - expectedReturnSeqs: []uint64{102, 103, 104}, - }, - } - - 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. - err := providerKeeper.QueueThrottledSlashPacketData(ctx, "some-rando-chain", 77, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "some-rando-chain", 97, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - - // Queue the data to test against - for _, dataInstance := range tc.dataToQueue { - err := providerKeeper.QueueThrottledPacketData(ctx, "chain-99", dataInstance.IbcSeqNum, dataInstance.Data) - require.NoError(t, err) - } - - // Obtain data from iterator - returnedData, ibcSeqNums := providerKeeper.GetLeadingVSCMaturedData(ctx, "chain-99") - - // Assert the returned data is as expected - require.Equal(t, tc.expectedReturnData, returnedData) - require.Equal(t, tc.expectedReturnSeqs, ibcSeqNums) - } -} - -func TestGetSlashAndTrailingData(t *testing.T) { - // Instantiate some data to test against - someSlashData := getTenSampleSlashPacketData() - someVSCMaturedData := getTenSampleVSCMaturedPacketData() - - 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. - err := providerKeeper.QueueThrottledSlashPacketData(ctx, "some-rando-chain", 77, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "some-rando-chain", 97, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - - // Queue the data to test - for _, dataInstance := range tc.dataToQueue { - err := providerKeeper.QueueThrottledPacketData(ctx, "chain-49", dataInstance.IbcSeqNum, dataInstance.Data) - require.NoError(t, err) - } - - // 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) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - providerKeeper.SetParams(ctx, providertypes.DefaultParams()) - - // Queue slash and a VSC matured packet data for chain-48 - err := providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-48", 0, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-48", 1, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - - // Queue 3 slash, and 4 vsc matured packet data instances for chain-49 - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-49", 0, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-49", 1, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledSlashPacketData(ctx, "chain-49", 2, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-49", 3, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-49", 4, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-49", 5, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledVSCMaturedPacketData(ctx, "chain-49", 6, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - - // Delete all packet data for chain-49, confirm they are deleted - providerKeeper.DeleteThrottledPacketDataForConsumer(ctx, "chain-49") - slashData, vscMaturedData, _, _ := providerKeeper.GetAllThrottledPacketData(ctx, "chain-49") - require.Empty(t, slashData) - require.Empty(t, vscMaturedData) - - // Confirm size of queue is now 0 - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-49")) - - // Confirm packet data for chain-48 is not deleted - slashData, vscMaturedData, _, _ = providerKeeper.GetAllThrottledPacketData(ctx, "chain-48") - require.Len(t, slashData, 1) - require.Len(t, vscMaturedData, 1) -} - -// TestPanicIfTooMuchThrottledPacketData tests that the provider panics -// when the number of throttled (queued) packets exceeds the max allowed by params. -func TestPanicIfTooMuchThrottledPacketData(t *testing.T) { - testCases := []struct { - max int64 - }{ - {max: 3}, // Max must be greater than 2 since we queue 2 packets for another chain in the test - {max: 5}, - {max: 10}, - {max: 15}, - {max: 25}, - {max: 100}, - } - - for _, tc := range testCases { - - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - // Set max throttled packets param - defaultParams := providertypes.DefaultParams() - defaultParams.MaxThrottledPackets = tc.max - providerKeeper.SetParams(ctx, defaultParams) - - seed := time.Now().UnixNano() - rng := rand.New(rand.NewSource(seed)) - - // Queuing up a couple data instances for another chain shouldn't matter - err := providerKeeper.QueueThrottledPacketData(ctx, "chain-17", 0, testkeeper.GetNewSlashPacketData()) - require.NoError(t, err) - err = providerKeeper.QueueThrottledPacketData(ctx, "chain-17", 1, testkeeper.GetNewVSCMaturedPacketData()) - require.NoError(t, err) - - // Queue packet data instances until we reach the max (some slash packets, some VSC matured packets) - reachedMax := false - for i := 0; i < int(tc.max); i++ { - randBool := rng.Intn(2) == 0 - var data interface{} - if randBool { - data = testkeeper.GetNewSlashPacketData() - } else { - data = testkeeper.GetNewVSCMaturedPacketData() - } - // Panic only if we've reached the max - if i == int(tc.max-1) { - require.Panics(t, func() { - _ = providerKeeper.QueueThrottledPacketData(ctx, "chain-88", uint64(i), data) - }) - reachedMax = true - } else { - err := providerKeeper.QueueThrottledPacketData(ctx, "chain-88", uint64(i), data) - require.NoError(t, err) - } - } - require.True(t, reachedMax) - } -} - -// TestThrottledPacketDataSize tests the getter, setter and incrementer for throttled packet data size. -func TestThrottledPacketDataSize(t *testing.T) { - providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - defer ctrl.Finish() - - // Set params so we can use the default max throttled packet data size - params := providertypes.DefaultParams() - providerKeeper.SetParams(ctx, params) - - // Confirm initial size is 0 - require.Equal(t, uint64(0), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-0")) - - // Set throttled packet data size and confirm it was set - providerKeeper.SetThrottledPacketDataSize(ctx, "chain-0", 10) - require.Equal(t, uint64(10), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-0")) - - // Increment throttled packet data size and confirm it was incremented - providerKeeper.IncrementThrottledPacketDataSize(ctx, "chain-0") - require.Equal(t, uint64(11), providerKeeper.GetThrottledPacketDataSize(ctx, "chain-0")) -} - // TestSlashMeter tests the getter and setter for the slash gas meter func TestSlashMeter(t *testing.T) { testCases := []struct { @@ -1320,65 +538,3 @@ func TestSlashMeterReplenishTimeCandidate(t *testing.T) { require.Equal(t, tc.blockTime.Add(tc.replenishPeriod).UTC(), gotTime) } } - -// Struct used for TestPendingPacketData and helpers -type throttledPacketDataInstance struct { - IbcSeqNum uint64 - Data interface{} -} - -// getAllThrottledPacketDataInstances returns all throttled packet data instances in order -// from the chain-specific packet data queue. -func getAllThrottledPacketDataInstances(ctx sdktypes.Context, k *keeper.Keeper, consumerChainId string) (instances []throttledPacketDataInstance) { - _, _, allData, ibcSeqNums := k.GetAllThrottledPacketData(ctx, consumerChainId) - instances = []throttledPacketDataInstance{} - for idx, data := range allData { - instances = append(instances, throttledPacketDataInstance{ - IbcSeqNum: ibcSeqNums[idx], - Data: data, - }) - } - return instances -} - -// getOrderedInstances returns the given instances in order, specified by the given indexes -func getOrderedInstances(instances []throttledPacketDataInstance, orderbyIdx []int) (orderedInstances []throttledPacketDataInstance) { - toReturn := []throttledPacketDataInstance{} - for _, idx := range orderbyIdx { - toReturn = append(toReturn, instances[idx]) - } - return toReturn -} - -// Asserts that the throttled packet data retrieved for this consumer chain matches what's expected -func assertPendingPacketDataOrdering(t *testing.T, k *keeper.Keeper, ctx sdktypes.Context, - consumerChainId string, expectedInstances []throttledPacketDataInstance, -) { - t.Helper() - // Get all packet data for this chain - obtainedInstances := getAllThrottledPacketDataInstances(ctx, k, consumerChainId) - // No extra data should be present - require.Equal(t, len(expectedInstances), len(obtainedInstances)) - // Assert order and correct serialization/deserialization for each data instance - for i, obtainedInstance := range obtainedInstances { - require.Equal(t, expectedInstances[i], obtainedInstance) - } -} - -// getTenSampleSlashPacketData returns 10 randomized slash packet data instances for testing -func getTenSampleSlashPacketData() []ccvtypes.SlashPacketData { - sampleData := []ccvtypes.SlashPacketData{} - for i := 0; i < 10; i++ { - sampleData = append(sampleData, testkeeper.GetNewSlashPacketData()) - } - return sampleData -} - -// getTenSampleVSCMaturedPacketData returns 10 randomized VSC matured packet data instances for testing -func getTenSampleVSCMaturedPacketData() []ccvtypes.VSCMaturedPacketData { - sampleData := []ccvtypes.VSCMaturedPacketData{} - for i := 0; i < 10; i++ { - sampleData = append(sampleData, testkeeper.GetNewVSCMaturedPacketData()) - } - return sampleData -} diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index 82891c27c7..5aa743ec2d 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -137,6 +137,8 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { am.keeper.BeginBlockInit(ctx) // Stop and remove state for any consumer chains that are due to be stopped via pending consumer removal proposals am.keeper.BeginBlockCCR(ctx) + // Check for replenishing slash meter before any slash packets are processed for this block + am.keeper.BeginBlockCIS(ctx) } // EndBlock implements the AppModule interface diff --git a/x/ccv/provider/types/query.pb.go b/x/ccv/provider/types/query.pb.go index 9fc9178e09..0ff8aba62c 100644 --- a/x/ccv/provider/types/query.pb.go +++ b/x/ccv/provider/types/query.pb.go @@ -637,8 +637,6 @@ type QueryThrottleStateResponse struct { // next time the slash meter could potentially be replenished, iff it's not // full NextReplenishCandidate time.Time `protobuf:"bytes,3,opt,name=next_replenish_candidate,json=nextReplenishCandidate,proto3,stdtime" json:"next_replenish_candidate"` - // data relevant to currently throttled slash packets - Packets []*ThrottledSlashPacket `protobuf:"bytes,4,rep,name=packets,proto3" json:"packets,omitempty"` } func (m *QueryThrottleStateResponse) Reset() { *m = QueryThrottleStateResponse{} } @@ -695,262 +693,6 @@ func (m *QueryThrottleStateResponse) GetNextReplenishCandidate() time.Time { return time.Time{} } -func (m *QueryThrottleStateResponse) GetPackets() []*ThrottledSlashPacket { - if m != nil { - return m.Packets - } - return nil -} - -type QueryThrottledConsumerPacketDataRequest struct { - ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` -} - -func (m *QueryThrottledConsumerPacketDataRequest) Reset() { - *m = QueryThrottledConsumerPacketDataRequest{} -} -func (m *QueryThrottledConsumerPacketDataRequest) String() string { return proto.CompactTextString(m) } -func (*QueryThrottledConsumerPacketDataRequest) ProtoMessage() {} -func (*QueryThrottledConsumerPacketDataRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{15} -} -func (m *QueryThrottledConsumerPacketDataRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryThrottledConsumerPacketDataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryThrottledConsumerPacketDataRequest.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 *QueryThrottledConsumerPacketDataRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryThrottledConsumerPacketDataRequest.Merge(m, src) -} -func (m *QueryThrottledConsumerPacketDataRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryThrottledConsumerPacketDataRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryThrottledConsumerPacketDataRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryThrottledConsumerPacketDataRequest proto.InternalMessageInfo - -func (m *QueryThrottledConsumerPacketDataRequest) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -type QueryThrottledConsumerPacketDataResponse struct { - ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - Size_ uint64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` - PacketDataInstances []ThrottledPacketDataWrapper `protobuf:"bytes,3,rep,name=packetDataInstances,proto3" json:"packetDataInstances"` -} - -func (m *QueryThrottledConsumerPacketDataResponse) Reset() { - *m = QueryThrottledConsumerPacketDataResponse{} -} -func (m *QueryThrottledConsumerPacketDataResponse) String() string { return proto.CompactTextString(m) } -func (*QueryThrottledConsumerPacketDataResponse) ProtoMessage() {} -func (*QueryThrottledConsumerPacketDataResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{16} -} -func (m *QueryThrottledConsumerPacketDataResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryThrottledConsumerPacketDataResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryThrottledConsumerPacketDataResponse.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 *QueryThrottledConsumerPacketDataResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryThrottledConsumerPacketDataResponse.Merge(m, src) -} -func (m *QueryThrottledConsumerPacketDataResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryThrottledConsumerPacketDataResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryThrottledConsumerPacketDataResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryThrottledConsumerPacketDataResponse proto.InternalMessageInfo - -func (m *QueryThrottledConsumerPacketDataResponse) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -func (m *QueryThrottledConsumerPacketDataResponse) GetSize_() uint64 { - if m != nil { - return m.Size_ - } - return 0 -} - -func (m *QueryThrottledConsumerPacketDataResponse) GetPacketDataInstances() []ThrottledPacketDataWrapper { - if m != nil { - return m.PacketDataInstances - } - return nil -} - -// A query wrapper type for the global entry and data relevant to a throttled -// slash packet. -type ThrottledSlashPacket struct { - GlobalEntry GlobalSlashEntry `protobuf:"bytes,1,opt,name=global_entry,json=globalEntry,proto3" json:"global_entry"` - Data types.SlashPacketData `protobuf:"bytes,2,opt,name=data,proto3" json:"data"` -} - -func (m *ThrottledSlashPacket) Reset() { *m = ThrottledSlashPacket{} } -func (m *ThrottledSlashPacket) String() string { return proto.CompactTextString(m) } -func (*ThrottledSlashPacket) ProtoMessage() {} -func (*ThrottledSlashPacket) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{17} -} -func (m *ThrottledSlashPacket) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ThrottledSlashPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ThrottledSlashPacket.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 *ThrottledSlashPacket) XXX_Merge(src proto.Message) { - xxx_messageInfo_ThrottledSlashPacket.Merge(m, src) -} -func (m *ThrottledSlashPacket) XXX_Size() int { - return m.Size() -} -func (m *ThrottledSlashPacket) XXX_DiscardUnknown() { - xxx_messageInfo_ThrottledSlashPacket.DiscardUnknown(m) -} - -var xxx_messageInfo_ThrottledSlashPacket proto.InternalMessageInfo - -func (m *ThrottledSlashPacket) GetGlobalEntry() GlobalSlashEntry { - if m != nil { - return m.GlobalEntry - } - return GlobalSlashEntry{} -} - -func (m *ThrottledSlashPacket) GetData() types.SlashPacketData { - if m != nil { - return m.Data - } - return types.SlashPacketData{} -} - -// ThrottledPacketDataWrapper contains either SlashPacketData or -// VSCMaturedPacketData -type ThrottledPacketDataWrapper struct { - // Types that are valid to be assigned to Data: - // *ThrottledPacketDataWrapper_SlashPacket - // *ThrottledPacketDataWrapper_VscMaturedPacket - Data isThrottledPacketDataWrapper_Data `protobuf_oneof:"data"` -} - -func (m *ThrottledPacketDataWrapper) Reset() { *m = ThrottledPacketDataWrapper{} } -func (m *ThrottledPacketDataWrapper) String() string { return proto.CompactTextString(m) } -func (*ThrottledPacketDataWrapper) ProtoMessage() {} -func (*ThrottledPacketDataWrapper) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{18} -} -func (m *ThrottledPacketDataWrapper) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ThrottledPacketDataWrapper) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ThrottledPacketDataWrapper.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 *ThrottledPacketDataWrapper) XXX_Merge(src proto.Message) { - xxx_messageInfo_ThrottledPacketDataWrapper.Merge(m, src) -} -func (m *ThrottledPacketDataWrapper) XXX_Size() int { - return m.Size() -} -func (m *ThrottledPacketDataWrapper) XXX_DiscardUnknown() { - xxx_messageInfo_ThrottledPacketDataWrapper.DiscardUnknown(m) -} - -var xxx_messageInfo_ThrottledPacketDataWrapper proto.InternalMessageInfo - -type isThrottledPacketDataWrapper_Data interface { - isThrottledPacketDataWrapper_Data() - MarshalTo([]byte) (int, error) - Size() int -} - -type ThrottledPacketDataWrapper_SlashPacket struct { - SlashPacket *types.SlashPacketData `protobuf:"bytes,1,opt,name=slash_packet,json=slashPacket,proto3,oneof" json:"slash_packet,omitempty"` -} -type ThrottledPacketDataWrapper_VscMaturedPacket struct { - VscMaturedPacket *types.VSCMaturedPacketData `protobuf:"bytes,2,opt,name=vsc_matured_packet,json=vscMaturedPacket,proto3,oneof" json:"vsc_matured_packet,omitempty"` -} - -func (*ThrottledPacketDataWrapper_SlashPacket) isThrottledPacketDataWrapper_Data() {} -func (*ThrottledPacketDataWrapper_VscMaturedPacket) isThrottledPacketDataWrapper_Data() {} - -func (m *ThrottledPacketDataWrapper) GetData() isThrottledPacketDataWrapper_Data { - if m != nil { - return m.Data - } - return nil -} - -func (m *ThrottledPacketDataWrapper) GetSlashPacket() *types.SlashPacketData { - if x, ok := m.GetData().(*ThrottledPacketDataWrapper_SlashPacket); ok { - return x.SlashPacket - } - return nil -} - -func (m *ThrottledPacketDataWrapper) GetVscMaturedPacket() *types.VSCMaturedPacketData { - if x, ok := m.GetData().(*ThrottledPacketDataWrapper_VscMaturedPacket); ok { - return x.VscMaturedPacket - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*ThrottledPacketDataWrapper) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*ThrottledPacketDataWrapper_SlashPacket)(nil), - (*ThrottledPacketDataWrapper_VscMaturedPacket)(nil), - } -} - type QueryRegisteredConsumerRewardDenomsRequest struct { } @@ -962,7 +704,7 @@ func (m *QueryRegisteredConsumerRewardDenomsRequest) String() string { } func (*QueryRegisteredConsumerRewardDenomsRequest) ProtoMessage() {} func (*QueryRegisteredConsumerRewardDenomsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{19} + return fileDescriptor_422512d7b7586cd7, []int{15} } func (m *QueryRegisteredConsumerRewardDenomsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1003,7 +745,7 @@ func (m *QueryRegisteredConsumerRewardDenomsResponse) String() string { } func (*QueryRegisteredConsumerRewardDenomsResponse) ProtoMessage() {} func (*QueryRegisteredConsumerRewardDenomsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_422512d7b7586cd7, []int{20} + return fileDescriptor_422512d7b7586cd7, []int{16} } func (m *QueryRegisteredConsumerRewardDenomsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1055,10 +797,6 @@ func init() { proto.RegisterType((*QueryValidatorProviderAddrResponse)(nil), "interchain_security.ccv.provider.v1.QueryValidatorProviderAddrResponse") proto.RegisterType((*QueryThrottleStateRequest)(nil), "interchain_security.ccv.provider.v1.QueryThrottleStateRequest") proto.RegisterType((*QueryThrottleStateResponse)(nil), "interchain_security.ccv.provider.v1.QueryThrottleStateResponse") - proto.RegisterType((*QueryThrottledConsumerPacketDataRequest)(nil), "interchain_security.ccv.provider.v1.QueryThrottledConsumerPacketDataRequest") - proto.RegisterType((*QueryThrottledConsumerPacketDataResponse)(nil), "interchain_security.ccv.provider.v1.QueryThrottledConsumerPacketDataResponse") - proto.RegisterType((*ThrottledSlashPacket)(nil), "interchain_security.ccv.provider.v1.ThrottledSlashPacket") - proto.RegisterType((*ThrottledPacketDataWrapper)(nil), "interchain_security.ccv.provider.v1.ThrottledPacketDataWrapper") proto.RegisterType((*QueryRegisteredConsumerRewardDenomsRequest)(nil), "interchain_security.ccv.provider.v1.QueryRegisteredConsumerRewardDenomsRequest") proto.RegisterType((*QueryRegisteredConsumerRewardDenomsResponse)(nil), "interchain_security.ccv.provider.v1.QueryRegisteredConsumerRewardDenomsResponse") } @@ -1068,90 +806,74 @@ func init() { } var fileDescriptor_422512d7b7586cd7 = []byte{ - // 1323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xcf, 0x6f, 0x1b, 0xc5, - 0x1f, 0xf5, 0x3a, 0x69, 0x9a, 0x4c, 0xfa, 0xfd, 0xb6, 0x4c, 0x4b, 0x71, 0xb7, 0x95, 0x5d, 0xb6, - 0x02, 0xd2, 0x16, 0x76, 0x1b, 0x57, 0x48, 0x6d, 0x21, 0x75, 0xed, 0x24, 0xa4, 0x51, 0x1b, 0x35, - 0xac, 0xab, 0x56, 0x02, 0xd4, 0x65, 0xb2, 0x3b, 0xd8, 0x2b, 0xd6, 0x3b, 0xdb, 0x99, 0xb1, 0xd3, - 0x80, 0x38, 0x00, 0x12, 0xf4, 0x58, 0x09, 0x71, 0xe3, 0xd0, 0x13, 0xff, 0x05, 0xf7, 0xde, 0xa8, - 0xe8, 0xa5, 0xa7, 0x82, 0x12, 0x0e, 0x1c, 0x11, 0x77, 0x24, 0xb4, 0xb3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e, 0x51, 0xee, 0xb0, 0x14, 0xd1, 0x4f, 0xab, 0x08, 0xed, 0xef, 0xc3, 0x2b, 0xc3, 0xb5, - 0x07, 0xd8, 0x77, 0x5c, 0xbf, 0xd6, 0x99, 0x63, 0x99, 0x58, 0xe1, 0x8f, 0x59, 0x70, 0x26, 0xc5, - 0xeb, 0x1c, 0xde, 0x4a, 0x4f, 0x3d, 0x55, 0x8c, 0x50, 0xd7, 0xf7, 0x0f, 0x50, 0xda, 0x71, 0x43, - 0xd8, 0xb1, 0x0c, 0x17, 0x87, 0xdb, 0x41, 0xdb, 0x88, 0x1d, 0x47, 0xa8, 0xc0, 0xb4, 0xa2, 0x78, - 0x52, 0xb9, 0xfb, 0x64, 0x3b, 0xaf, 0x3c, 0xdd, 0xce, 0x2b, 0x7f, 0x6c, 0xe7, 0x95, 0x47, 0x3b, - 0xf9, 0xcc, 0xd3, 0x9d, 0x7c, 0xe6, 0xf9, 0x4e, 0x3e, 0xf3, 0xd1, 0x42, 0xcd, 0xe5, 0xf5, 0xe6, - 0x86, 0x6e, 0x93, 0x86, 0x61, 0x13, 0xd6, 0x20, 0xac, 0xab, 0xdf, 0x3b, 0xed, 0x7e, 0xad, 0x8b, - 0xc6, 0x83, 0x5d, 0xf3, 0xb7, 0x15, 0x60, 0xb6, 0x31, 0x25, 0xbe, 0x56, 0x2e, 0xfe, 0x17, 0x00, - 0x00, 0xff, 0xff, 0x84, 0xab, 0xda, 0x7b, 0x39, 0x13, 0x00, 0x00, + // 1059 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xcf, 0x6f, 0xdc, 0x44, + 0x14, 0x5e, 0x27, 0x34, 0x24, 0x13, 0x20, 0xd5, 0xb4, 0x94, 0xad, 0x13, 0xed, 0x16, 0x57, 0xc0, + 0xb6, 0x80, 0xdd, 0xdd, 0x5c, 0xda, 0xa2, 0x74, 0xb3, 0x1b, 0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 0xc8, 0xe0, 0xdd, 0xfc, 0x14, 0x73, 0x19, 0xa8, + 0xba, 0x7d, 0x72, 0x80, 0x72, 0x08, 0xb7, 0xc4, 0x10, 0x36, 0xe1, 0xc6, 0xe4, 0x21, 0xd0, 0x14, + 0xb1, 0xb7, 0xd3, 0x54, 0x60, 0x5a, 0xb1, 0x31, 0x37, 0x3f, 0x7b, 0x72, 0x50, 0x52, 0x9e, 0x1e, + 0x94, 0x94, 0x3f, 0x0f, 0x4a, 0xca, 0xa3, 0xc3, 0x52, 0xe1, 0xe9, 0x61, 0xa9, 0xf0, 0xfb, 0x61, + 0xa9, 0xf0, 0xf9, 0x5a, 0xcb, 0xe5, 0xed, 0xee, 0xae, 0x6e, 0x93, 0x8e, 0x61, 0x13, 0xd6, 0x21, + 0xac, 0xaf, 0xdf, 0xfb, 0x69, 0xbf, 0x70, 0xd5, 0x78, 0x30, 0x34, 0xf9, 0xfd, 0x00, 0xb3, 0xdd, + 0x39, 0xf1, 0x71, 0xb2, 0xfa, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x94, 0x26, 0xbd, 0x0a, 0x28, + 0x0f, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1185,9 +907,6 @@ type QueryClient interface { // QueryThrottleState returns the main on-chain state relevant to currently // throttled slash packets QueryThrottleState(ctx context.Context, in *QueryThrottleStateRequest, opts ...grpc.CallOption) (*QueryThrottleStateResponse, error) - // QueryThrottledConsumerPacketData returns a list of pending packet data - // instances (slash packet and vsc matured) for a single consumer chain - QueryThrottledConsumerPacketData(ctx context.Context, in *QueryThrottledConsumerPacketDataRequest, opts ...grpc.CallOption) (*QueryThrottledConsumerPacketDataResponse, error) // QueryRegisteredConsumerRewardDenoms returns a list of consumer reward // denoms that are registered QueryRegisteredConsumerRewardDenoms(ctx context.Context, in *QueryRegisteredConsumerRewardDenomsRequest, opts ...grpc.CallOption) (*QueryRegisteredConsumerRewardDenomsResponse, error) @@ -1264,15 +983,6 @@ func (c *queryClient) QueryThrottleState(ctx context.Context, in *QueryThrottleS return out, nil } -func (c *queryClient) QueryThrottledConsumerPacketData(ctx context.Context, in *QueryThrottledConsumerPacketDataRequest, opts ...grpc.CallOption) (*QueryThrottledConsumerPacketDataResponse, error) { - out := new(QueryThrottledConsumerPacketDataResponse) - err := c.cc.Invoke(ctx, "/interchain_security.ccv.provider.v1.Query/QueryThrottledConsumerPacketData", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *queryClient) QueryRegisteredConsumerRewardDenoms(ctx context.Context, in *QueryRegisteredConsumerRewardDenomsRequest, opts ...grpc.CallOption) (*QueryRegisteredConsumerRewardDenomsResponse, error) { out := new(QueryRegisteredConsumerRewardDenomsResponse) err := c.cc.Invoke(ctx, "/interchain_security.ccv.provider.v1.Query/QueryRegisteredConsumerRewardDenoms", in, out, opts...) @@ -1303,9 +1013,6 @@ type QueryServer interface { // QueryThrottleState returns the main on-chain state relevant to currently // throttled slash packets QueryThrottleState(context.Context, *QueryThrottleStateRequest) (*QueryThrottleStateResponse, error) - // QueryThrottledConsumerPacketData returns a list of pending packet data - // instances (slash packet and vsc matured) for a single consumer chain - QueryThrottledConsumerPacketData(context.Context, *QueryThrottledConsumerPacketDataRequest) (*QueryThrottledConsumerPacketDataResponse, error) // QueryRegisteredConsumerRewardDenoms returns a list of consumer reward // denoms that are registered QueryRegisteredConsumerRewardDenoms(context.Context, *QueryRegisteredConsumerRewardDenomsRequest) (*QueryRegisteredConsumerRewardDenomsResponse, error) @@ -1336,9 +1043,6 @@ func (*UnimplementedQueryServer) QueryValidatorProviderAddr(ctx context.Context, func (*UnimplementedQueryServer) QueryThrottleState(ctx context.Context, req *QueryThrottleStateRequest) (*QueryThrottleStateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method QueryThrottleState not implemented") } -func (*UnimplementedQueryServer) QueryThrottledConsumerPacketData(ctx context.Context, req *QueryThrottledConsumerPacketDataRequest) (*QueryThrottledConsumerPacketDataResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method QueryThrottledConsumerPacketData not implemented") -} func (*UnimplementedQueryServer) QueryRegisteredConsumerRewardDenoms(ctx context.Context, req *QueryRegisteredConsumerRewardDenomsRequest) (*QueryRegisteredConsumerRewardDenomsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method QueryRegisteredConsumerRewardDenoms not implemented") } @@ -1473,24 +1177,6 @@ func _Query_QueryThrottleState_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } -func _Query_QueryThrottledConsumerPacketData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryThrottledConsumerPacketDataRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).QueryThrottledConsumerPacketData(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/interchain_security.ccv.provider.v1.Query/QueryThrottledConsumerPacketData", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).QueryThrottledConsumerPacketData(ctx, req.(*QueryThrottledConsumerPacketDataRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Query_QueryRegisteredConsumerRewardDenoms_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryRegisteredConsumerRewardDenomsRequest) if err := dec(in); err != nil { @@ -1541,10 +1227,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "QueryThrottleState", Handler: _Query_QueryThrottleState_Handler, }, - { - MethodName: "QueryThrottledConsumerPacketData", - Handler: _Query_QueryThrottledConsumerPacketData_Handler, - }, { MethodName: "QueryRegisteredConsumerRewardDenoms", Handler: _Query_QueryRegisteredConsumerRewardDenoms_Handler, @@ -2007,20 +1689,6 @@ func (m *QueryThrottleStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l - if len(m.Packets) > 0 { - for iNdEx := len(m.Packets) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Packets[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.NextReplenishCandidate, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.NextReplenishCandidate):]) if err4 != nil { return 0, err4 @@ -2042,7 +1710,7 @@ func (m *QueryThrottleStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *QueryThrottledConsumerPacketDataRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryRegisteredConsumerRewardDenomsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -2052,27 +1720,20 @@ func (m *QueryThrottledConsumerPacketDataRequest) Marshal() (dAtA []byte, err er return dAtA[:n], nil } -func (m *QueryThrottledConsumerPacketDataRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryRegisteredConsumerRewardDenomsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryThrottledConsumerPacketDataRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryRegisteredConsumerRewardDenomsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintQuery(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } -func (m *QueryThrottledConsumerPacketDataResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryRegisteredConsumerRewardDenomsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -2082,245 +1743,56 @@ func (m *QueryThrottledConsumerPacketDataResponse) Marshal() (dAtA []byte, err e return dAtA[:n], nil } -func (m *QueryThrottledConsumerPacketDataResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryRegisteredConsumerRewardDenomsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryThrottledConsumerPacketDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryRegisteredConsumerRewardDenomsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.PacketDataInstances) > 0 { - for iNdEx := len(m.PacketDataInstances) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.PacketDataInstances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } + if len(m.Denoms) > 0 { + for iNdEx := len(m.Denoms) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Denoms[iNdEx]) + copy(dAtA[i:], m.Denoms[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denoms[iNdEx]))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0xa } } - if m.Size_ != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Size_)) - i-- - dAtA[i] = 0x10 - } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintQuery(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } -func (m *ThrottledSlashPacket) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ } - return dAtA[:n], nil + dAtA[offset] = uint8(v) + return base } - -func (m *ThrottledSlashPacket) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (m *QueryConsumerGenesisRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n } -func (m *ThrottledSlashPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Data.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size, err := m.GlobalEntry.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *ThrottledPacketDataWrapper) 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 *ThrottledPacketDataWrapper) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ThrottledPacketDataWrapper) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Data != nil { - { - size := m.Data.Size() - i -= size - if _, err := m.Data.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *ThrottledPacketDataWrapper_SlashPacket) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ThrottledPacketDataWrapper_SlashPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.SlashPacket != nil { - { - size, err := m.SlashPacket.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *ThrottledPacketDataWrapper_VscMaturedPacket) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ThrottledPacketDataWrapper_VscMaturedPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.VscMaturedPacket != nil { - { - size, err := m.VscMaturedPacket.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *QueryRegisteredConsumerRewardDenomsRequest) 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 *QueryRegisteredConsumerRewardDenomsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRegisteredConsumerRewardDenomsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryRegisteredConsumerRewardDenomsResponse) 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 *QueryRegisteredConsumerRewardDenomsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryRegisteredConsumerRewardDenomsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Denoms) > 0 { - for iNdEx := len(m.Denoms) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Denoms[iNdEx]) - copy(dAtA[i:], m.Denoms[iNdEx]) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Denoms[iNdEx]))) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *QueryConsumerGenesisRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryConsumerGenesisResponse) Size() (n int) { - if m == nil { - return 0 - } +func (m *QueryConsumerGenesisResponse) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l l = m.GenesisState.Size() @@ -2496,99 +1968,9 @@ func (m *QueryThrottleStateResponse) Size() (n int) { } l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.NextReplenishCandidate) n += 1 + l + sovQuery(uint64(l)) - if len(m.Packets) > 0 { - for _, e := range m.Packets { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - return n -} - -func (m *QueryThrottledConsumerPacketDataRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -func (m *QueryThrottledConsumerPacketDataResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } - if m.Size_ != 0 { - n += 1 + sovQuery(uint64(m.Size_)) - } - if len(m.PacketDataInstances) > 0 { - for _, e := range m.PacketDataInstances { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - return n -} - -func (m *ThrottledSlashPacket) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.GlobalEntry.Size() - n += 1 + l + sovQuery(uint64(l)) - l = m.Data.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - -func (m *ThrottledPacketDataWrapper) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Data != nil { - n += m.Data.Size() - } return n } -func (m *ThrottledPacketDataWrapper_SlashPacket) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.SlashPacket != nil { - l = m.SlashPacket.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} -func (m *ThrottledPacketDataWrapper_VscMaturedPacket) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.VscMaturedPacket != nil { - l = m.VscMaturedPacket.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} func (m *QueryRegisteredConsumerRewardDenomsRequest) Size() (n int) { if m == nil { return 0 @@ -3846,493 +3228,6 @@ func (m *QueryThrottleStateResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Packets", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Packets = append(m.Packets, &ThrottledSlashPacket{}) - if err := m.Packets[len(m.Packets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryThrottledConsumerPacketDataRequest) 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 ErrIntOverflowQuery - } - 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: QueryThrottledConsumerPacketDataRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryThrottledConsumerPacketDataRequest: 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 ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryThrottledConsumerPacketDataResponse) 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 ErrIntOverflowQuery - } - 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: QueryThrottledConsumerPacketDataResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryThrottledConsumerPacketDataResponse: 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 ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - 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 Size_", wireType) - } - m.Size_ = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Size_ |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketDataInstances", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PacketDataInstances = append(m.PacketDataInstances, ThrottledPacketDataWrapper{}) - if err := m.PacketDataInstances[len(m.PacketDataInstances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ThrottledSlashPacket) 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 ErrIntOverflowQuery - } - 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: ThrottledSlashPacket: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ThrottledSlashPacket: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GlobalEntry", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.GlobalEntry.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Data.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ThrottledPacketDataWrapper) 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 ErrIntOverflowQuery - } - 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: ThrottledPacketDataWrapper: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ThrottledPacketDataWrapper: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SlashPacket", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.SlashPacketData{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Data = &ThrottledPacketDataWrapper_SlashPacket{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field VscMaturedPacket", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.VSCMaturedPacketData{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Data = &ThrottledPacketDataWrapper_VscMaturedPacket{v} - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/ccv/provider/types/query.pb.gw.go b/x/ccv/provider/types/query.pb.gw.go index 6a249ca2a2..1a4b418158 100644 --- a/x/ccv/provider/types/query.pb.gw.go +++ b/x/ccv/provider/types/query.pb.gw.go @@ -231,42 +231,6 @@ func local_request_Query_QueryThrottleState_0(ctx context.Context, marshaler run } -var ( - filter_Query_QueryThrottledConsumerPacketData_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_QueryThrottledConsumerPacketData_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryThrottledConsumerPacketDataRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryThrottledConsumerPacketData_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.QueryThrottledConsumerPacketData(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_QueryThrottledConsumerPacketData_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryThrottledConsumerPacketDataRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryThrottledConsumerPacketData_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.QueryThrottledConsumerPacketData(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_QueryRegisteredConsumerRewardDenoms_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryRegisteredConsumerRewardDenomsRequest var metadata runtime.ServerMetadata @@ -452,29 +416,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_QueryThrottledConsumerPacketData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_QueryThrottledConsumerPacketData_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_QueryThrottledConsumerPacketData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_QueryRegisteredConsumerRewardDenoms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -679,26 +620,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_QueryThrottledConsumerPacketData_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_QueryThrottledConsumerPacketData_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_QueryThrottledConsumerPacketData_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_QueryRegisteredConsumerRewardDenoms_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -737,8 +658,6 @@ var ( pattern_Query_QueryThrottleState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "throttle_state"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_QueryThrottledConsumerPacketData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "pending_consumer_packets"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_QueryRegisteredConsumerRewardDenoms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "registered_consumer_reward_denoms"}, "", runtime.AssumeColonVerbOpt(false))) ) @@ -757,7 +676,5 @@ var ( forward_Query_QueryThrottleState_0 = runtime.ForwardResponseMessage - forward_Query_QueryThrottledConsumerPacketData_0 = runtime.ForwardResponseMessage - forward_Query_QueryRegisteredConsumerRewardDenoms_0 = runtime.ForwardResponseMessage )