Address @rigelrozanski comments
This commit is contained in:
parent
c0c5e293a8
commit
f9877508e5
|
@ -112,16 +112,17 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
|
||||||
// That way we avoid needing to read/write the whole array each time
|
// That way we avoid needing to read/write the whole array each time
|
||||||
previous := k.getValidatorMissedBlockBitArray(ctx, consAddr, index)
|
previous := k.getValidatorMissedBlockBitArray(ctx, consAddr, index)
|
||||||
missed := !signed
|
missed := !signed
|
||||||
if previous == missed {
|
switch {
|
||||||
// Array value at this index has not changed, no need to update counter
|
case !previous && missed:
|
||||||
} else if !previous && missed {
|
|
||||||
// Array value has changed from not missed to missed, increment counter
|
// Array value has changed from not missed to missed, increment counter
|
||||||
k.setValidatorMissedBlockBitArray(ctx, consAddr, index, true)
|
k.setValidatorMissedBlockBitArray(ctx, consAddr, index, true)
|
||||||
signInfo.MissedBlocksCounter++
|
signInfo.MissedBlocksCounter++
|
||||||
} else if previous && !missed {
|
case previous && !missed:
|
||||||
// Array value has changed from missed to not missed, decrement counter
|
// Array value has changed from missed to not missed, decrement counter
|
||||||
k.setValidatorMissedBlockBitArray(ctx, consAddr, index, false)
|
k.setValidatorMissedBlockBitArray(ctx, consAddr, index, false)
|
||||||
signInfo.MissedBlocksCounter--
|
signInfo.MissedBlocksCounter--
|
||||||
|
default:
|
||||||
|
// Array value at this index has not changed, no need to update counter
|
||||||
}
|
}
|
||||||
|
|
||||||
if missed {
|
if missed {
|
||||||
|
|
|
@ -375,6 +375,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||||
func TestValidatorDippingInAndOut(t *testing.T) {
|
func TestValidatorDippingInAndOut(t *testing.T) {
|
||||||
|
|
||||||
// initial setup
|
// initial setup
|
||||||
|
// keeperTestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500
|
||||||
ctx, _, sk, _, keeper := createTestInput(t, keeperTestParams())
|
ctx, _, sk, _, keeper := createTestInput(t, keeperTestParams())
|
||||||
params := sk.GetParams(ctx)
|
params := sk.GetParams(ctx)
|
||||||
params.MaxValidators = 1
|
params.MaxValidators = 1
|
||||||
|
@ -426,8 +427,9 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||||
validator, _ = sk.GetValidator(ctx, addr)
|
validator, _ = sk.GetValidator(ctx, addr)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
|
|
||||||
// validator misses 501 blocks
|
// validator misses 500 more blocks, 501 total
|
||||||
for ; height < int64(1201); height++ {
|
latest := height
|
||||||
|
for ; height < latest+500; height++ {
|
||||||
ctx = ctx.WithBlockHeight(height)
|
ctx = ctx.WithBlockHeight(height)
|
||||||
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, false)
|
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, false)
|
||||||
}
|
}
|
||||||
|
@ -437,6 +439,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||||
validator, _ = sk.GetValidator(ctx, addr)
|
validator, _ = sk.GetValidator(ctx, addr)
|
||||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||||
|
|
||||||
|
// check all the signing information
|
||||||
signInfo, found := keeper.getValidatorSigningInfo(ctx, consAddr)
|
signInfo, found := keeper.getValidatorSigningInfo(ctx, consAddr)
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, int64(0), signInfo.MissedBlocksCounter)
|
require.Equal(t, int64(0), signInfo.MissedBlocksCounter)
|
||||||
|
@ -454,14 +457,16 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||||
// validator rejoins and starts signing again
|
// validator rejoins and starts signing again
|
||||||
sk.Unjail(ctx, consAddr)
|
sk.Unjail(ctx, consAddr)
|
||||||
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, true)
|
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, true)
|
||||||
|
height++
|
||||||
|
|
||||||
// validator should not be kicked
|
// validator should not be kicked since we reset counter/array when it was jailed
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
validator, _ = sk.GetValidator(ctx, addr)
|
validator, _ = sk.GetValidator(ctx, addr)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
|
|
||||||
// validator misses 501 blocks
|
// validator misses 501 blocks
|
||||||
for height = int64(5001); height < int64(5503); height++ {
|
latest = height
|
||||||
|
for ; height < latest+501; height++ {
|
||||||
ctx = ctx.WithBlockHeight(height)
|
ctx = ctx.WithBlockHeight(height)
|
||||||
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, false)
|
keeper.handleValidatorSignature(ctx, val.Address(), newAmt, false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue