Skip to content

Commit

Permalink
Xin 248 correct timeout message skip rule (ethereum#192)
Browse files Browse the repository at this point in the history
* test on current devnet issue

* change to times 3 to fit correct dist
  • Loading branch information
liam-lai authored Oct 14, 2022
1 parent 4595bcf commit 55d9946
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion eth/bft/bft_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions eth/bft/bft_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 55d9946

Please sign in to comment.