From 55d994690a6bb8366dc397a9f7afda14b6310781 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 15 Oct 2022 00:29:02 +0800 Subject: [PATCH] Xin 248 correct timeout message skip rule (#192) * test on current devnet issue * change to times 3 to fit correct dist --- eth/bft/bft_handler.go | 4 +++- eth/bft/bft_handler_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eth/bft/bft_handler.go b/eth/bft/bft_handler.go index 3bebb3f0b9..cb39dc31a1 100644 --- a/eth/bft/bft_handler.go +++ b/eth/bft/bft_handler.go @@ -113,7 +113,9 @@ func (b *Bfter) Timeout(peer string, timeout *types.Timeout) error { log.Debug("Receive Timeout", "timeout", timeout) 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) return nil } diff --git a/eth/bft/bft_handler_test.go b/eth/bft/bft_handler_test.go index a0f2b4dd65..5426fc5699 100644 --- a/eth/bft/bft_handler_test.go +++ b/eth/bft/bft_handler_test.go @@ -333,7 +333,7 @@ func TestTooFarTimeout(t *testing.T) { verifyCounter := uint32(0) handlerCounter := uint32(0) broadcastCounter := uint32(0) - targetTimeout := 0 + targetTimeout := 1 tester.bfter.consensus.verifyTimeout = func(consensus.ChainReader, *types.Timeout) (bool, error) { atomic.AddUint32(&verifyCounter, 1) @@ -349,9 +349,9 @@ func TestTooFarTimeout(t *testing.T) { 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) if err != nil {