Skip to content

Commit

Permalink
fix handling of slash packet and integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Aug 22, 2023
1 parent 5e4b845 commit 8350956
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
29 changes: 23 additions & 6 deletions tests/integration/throttle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"bytes"
"time"

channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
Expand Down Expand Up @@ -84,9 +85,9 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
packet = s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, 2)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet)

s.Fail("need to update")

// 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.
// TODO: determine if there's a way to make this test better with a real retry.
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
s.Require().False(vals[2].IsJailed())

Expand Down Expand Up @@ -136,10 +137,26 @@ 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()
// 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)

vals = providerStakingKeeper.GetAllValidators(cacheCtx)
slashedVal = vals[2]
found := false
for _, val := range vals {
consAddr, err := val.GetConsAddr()
s.Require().NoError(err)
if bytes.Equal(consAddr, tmVal2.Address) {
slashedVal = val
found = true
break
}
}
if !found {
s.Fail("slashed validator not found")
}
s.Require().True(slashedVal.IsJailed())

// Assert validator 2 has no power, this should be apparent next block,
Expand Down
7 changes: 4 additions & 3 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,13 @@ func (k Keeper) OnRecvSlashPacket(ctx sdk.Context, packet channeltypes.Packet, d
return channeltypes.NewResultAcknowledgement(ccv.SlashPacketBouncedResult)
}

k.HandleSlashPacket(ctx, chainID, data)

// Subtract voting power that will be jailed/tombstoned from the slash meter
// 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(),
Expand Down

0 comments on commit 8350956

Please sign in to comment.