Skip to content

Commit

Permalink
fix: check liveness threshold from the second round of the window
Browse files Browse the repository at this point in the history
Check the liveness threshold only provided `VoterSetCounter >
SignedBlocksWindow` meaning `VoterSetCounter >= SignedBlocksWindow +
1`.
  • Loading branch information
0Tech committed Oct 7, 2021
1 parent 45d50ad commit 6856809
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/slashing/keeper/infractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr cryptotypes.Addre
maxMissed := k.SignedBlocksWindow(ctx) - minSignedPerWindow

// if we have joined enough times to voter set and the validator has missed too many blocks, punish them
if voterSetCounter >= minVoterSetCount && signInfo.MissedBlocksCounter > maxMissed {
if voterSetCounter > minVoterSetCount && signInfo.MissedBlocksCounter > maxMissed {
validator := k.sk.ValidatorByConsAddr(ctx, consAddr)
if validator != nil && !validator.IsJailed() {
// Downtime confirmed: slash and jail the validator
Expand Down
10 changes: 5 additions & 5 deletions x/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ func TestValidatorDippingInAndOut(t *testing.T) {
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), newPower, false)
}

// 398 more blocks happend
// 399 more blocks happend
latest = height
for ; height < latest+398; height++ {
for ; height < latest+399; height++ {
ctx = ctx.WithBlockHeight(height)
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), newPower, true)
}

// shouldn't be jailed/kicked yet because it had not joined to vote set 1000 times
// 100 times + (kicked) + 501 times + 398 times = 999 times
// shouldn't be jailed/kicked yet because it had not joined to vote set 1000 + 1 times
// 100 times + (kicked) + 501 times + 398 times = 1000 times
tstaking.CheckValidator(valAddr, stakingtypes.Bonded, false)

// another block happend
Expand All @@ -253,7 +253,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
signInfo, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, consAddr)
require.True(t, found)
require.Equal(t, int64(0), signInfo.MissedBlocksCounter)
require.Equal(t, int64(1000), signInfo.VoterSetCounter)
require.Equal(t, int64(1001), signInfo.VoterSetCounter)
// array should be cleared
for offset := int64(0); offset < app.SlashingKeeper.SignedBlocksWindow(ctx); offset++ {
missed := app.SlashingKeeper.GetValidatorMissedBlockBitArray(ctx, consAddr, offset)
Expand Down

0 comments on commit 6856809

Please sign in to comment.