Xin 248 correct timeout message skip rule (#192)

* test on current devnet issue

* change to times 3 to fit correct dist
This commit is contained in:
Liam 2022-10-15 00:29:02 +08:00 committed by GitHub
parent 4595bcfac1
commit 55d994690a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -113,7 +113,9 @@ func (b *Bfter) Timeout(peer string, timeout *types.Timeout) error {
log.Debug("Receive Timeout", "timeout", timeout) log.Debug("Receive Timeout", "timeout", timeout)
gapNum := timeout.GapNumber gapNum := timeout.GapNumber
if dist := int64(gapNum) - int64(b.chainHeight()); dist < -int64(b.epoch)*2 || dist > int64(b.epoch)*2 { // times 2 is to avoid cross epoch case, ex: timeout block between 901 to 1799, gapnumber is 450
// dist times 3, ex: timeout message's gap number is based on block and find out it's epoch switch number, then mod 900 then minus 450
if dist := int64(gapNum) - int64(b.chainHeight()); dist < -int64(b.epoch)*3 || dist > int64(b.epoch)*3 {
log.Debug("Discarded propagated timeout, too far away", "peer", peer, "gapNumber", gapNum, "hash", timeout.Hash, "distance", dist) log.Debug("Discarded propagated timeout, too far away", "peer", peer, "gapNumber", gapNum, "hash", timeout.Hash, "distance", dist)
return nil return nil
} }

View file

@ -333,7 +333,7 @@ func TestTooFarTimeout(t *testing.T) {
verifyCounter := uint32(0) verifyCounter := uint32(0)
handlerCounter := uint32(0) handlerCounter := uint32(0)
broadcastCounter := uint32(0) broadcastCounter := uint32(0)
targetTimeout := 0 targetTimeout := 1
tester.bfter.consensus.verifyTimeout = func(consensus.ChainReader, *types.Timeout) (bool, error) { tester.bfter.consensus.verifyTimeout = func(consensus.ChainReader, *types.Timeout) (bool, error) {
atomic.AddUint32(&verifyCounter, 1) atomic.AddUint32(&verifyCounter, 1)
@ -349,9 +349,9 @@ func TestTooFarTimeout(t *testing.T) {
atomic.AddUint32(&broadcastCounter, 1) atomic.AddUint32(&broadcastCounter, 1)
} }
tester.bfter.chainHeight = func() uint64 { return 2400 } tester.bfter.chainHeight = func() uint64 { return 7175258 }
timeoutMsg := &types.Timeout{GapNumber: 450} timeoutMsg := &types.Timeout{GapNumber: 7173450}
err := tester.bfter.Timeout(peerID, timeoutMsg) err := tester.bfter.Timeout(peerID, timeoutMsg)
if err != nil { if err != nil {