Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: only validate active chains #2266

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,31 @@
// Check expected behavior for handling SlashPackets for downtime infractions
slashPacketData.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME

// Expect packet to be handled if the validator didn't opt in
// Expect the packet to bounce if the slash meter is negative
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
// Only reaches the bouncing code if it fails in the check that chain is launched and the validator is not a consumer validator,
// so we set the chain as stopped.
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_STOPPED)
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)
suite.Require().NoError(err)
suite.Require().Equal(ccv.SlashPacketBouncedResult, ackResult, "expected bounced result")

// Expect packet not to bounce if the chain is launched
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_LAUNCHED)
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This definition of err is never used.
suite.Require().Equal(ccv.SlashPacketHandledResult, ackResult, "expected successful ack")

// Also test what happens if the chain is launched but we have a consumer validator. In this case the check that the
// chain is launched and the validator is not a consumer validator fails, and hence the packet bounces due to the
// negative slash meter.
err = providerKeeper.SetConsumerValidator(ctx, firstBundle.ConsumerId, providertypes.ConsensusValidator{
ProviderConsAddr: validAddress,
})
suite.Require().NoError(err)

// Expect the packet to bounce if the slash meter is negative
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)
suite.Require().NoError(err)
suite.Require().Equal(ccv.SlashPacketBouncedResult, ackResult, "expected successful ack")
suite.Require().Equal(ccv.SlashPacketBouncedResult, ackResult, "expected bounced result")

// Expect the packet to be handled if the slash meter is positive
providerKeeper.SetSlashMeter(ctx, math.NewInt(0))
Expand Down
5 changes: 5 additions & 0 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ func (k Keeper) hasToValidate(
provAddr types.ProviderConsAddress,
consumerId string,
) (bool, error) {
// only ask validators to validate active chains
if !k.IsConsumerActive(ctx, consumerId) {
return false, nil
}

// if the validator was sent as part of the packet in the last epoch, it has to validate
if k.IsConsumerValidator(ctx, consumerId, provAddr) {
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ func (k Keeper) OnRecvSlashPacket(
return ccv.V1Result, nil
}

// Check that the validator belongs to the consumer chain valset
if !k.IsConsumerValidator(ctx, consumerId, providerConsAddr) {
// Check that chain is launched and the validator belongs to the consumer chain valset
if k.GetConsumerPhase(ctx, consumerId) == providertypes.CONSUMER_PHASE_LAUNCHED && !k.IsConsumerValidator(ctx, consumerId, providerConsAddr) {
k.Logger(ctx).Error("cannot jail validator %s that does not belong to consumer %s valset",
providerConsAddr.String(), consumerId)
// drop packet but return a slash ack so that the consumer can send another slash packet
Expand Down
Loading