Skip to content

Commit

Permalink
fix!: return a SlashAck even if the validator is not a consumer valid…
Browse files Browse the repository at this point in the history
…ator (#1763)

* init commit

* fix test
  • Loading branch information
insumity authored Apr 8, 2024
1 parent d0f7a42 commit 67091f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.Slas
if !k.IsConsumerValidator(ctx, chainID, providerConsAddr) {
k.Logger(ctx).Error("cannot jail validator %s that does not belong to consumer %s valset",
providerConsAddr.String(), chainID)
// drop packet
// drop packet but return a slash ack so that the consumer can send another slash packet
k.AppendSlashAck(ctx, chainID, consumerConsAddr.String())
return
}

Expand Down
15 changes: 11 additions & 4 deletions x/ccv/provider/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ func TestHandleSlashPacket(t *testing.T) {
name string
packetData ccv.SlashPacketData
// The mocks that we expect to be called for the specified packet data.
expectedCalls func(sdk.Context, testkeeper.MockedKeepers, ccv.SlashPacketData) []*gomock.Call
expectedSlashAcksLen int
expectedCalls func(sdk.Context, testkeeper.MockedKeepers, ccv.SlashPacketData) []*gomock.Call
expectedSlashAcksLen int
expectedSlashAckConsumerConsAddress types.ConsumerConsAddress
}{
{
"validator isn't a consumer validator",
Expand All @@ -318,7 +319,8 @@ func TestHandleSlashPacket(t *testing.T) {
) []*gomock.Call {
return []*gomock.Call{}
},
0,
1,
dummyConsAddr,
},
{
"unfound validator",
Expand All @@ -340,6 +342,7 @@ func TestHandleSlashPacket(t *testing.T) {
}
},
0,
consumerConsAddr,
},
{
"found, but tombstoned validator",
Expand All @@ -362,6 +365,7 @@ func TestHandleSlashPacket(t *testing.T) {
}
},
0,
consumerConsAddr,
},
{
"drop packet when infraction height not found",
Expand All @@ -385,6 +389,7 @@ func TestHandleSlashPacket(t *testing.T) {
}
},
0,
consumerConsAddr,
},
{
"full downtime packet handling, uses init chain height and non-jailed validator",
Expand All @@ -402,6 +407,7 @@ func TestHandleSlashPacket(t *testing.T) {
true) // expectJailing = true
},
1,
consumerConsAddr,
},
{
"full downtime packet handling, uses valid vscID and jailed validator",
Expand All @@ -419,6 +425,7 @@ func TestHandleSlashPacket(t *testing.T) {
false) // expectJailing = false, validator is already jailed.
},
1,
consumerConsAddr,
},
// Note: double-sign slash packet handling should not occur, see OnRecvSlashPacket.
}
Expand Down Expand Up @@ -447,7 +454,7 @@ func TestHandleSlashPacket(t *testing.T) {

if tc.expectedSlashAcksLen == 1 {
// must match the consumer address
require.Equal(t, consumerConsAddr.String(), providerKeeper.GetSlashAcks(ctx, chainId)[0])
require.Equal(t, tc.expectedSlashAckConsumerConsAddress.String(), providerKeeper.GetSlashAcks(ctx, chainId)[0])
require.NotEqual(t, providerConsAddr.String(), providerKeeper.GetSlashAcks(ctx, chainId)[0])
require.NotEqual(t, providerConsAddr.String(), consumerConsAddr.String())
}
Expand Down

0 comments on commit 67091f8

Please sign in to comment.