Skip to content

Commit ecd1991

Browse files
committed
eth/fetcher: allow backward uncle imports too
1 parent 90d45f0 commit ecd1991

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

eth/fetcher/fetcher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
const (
1717
arriveTimeout = 500 * time.Millisecond // Time allowance before an announced block is explicitly requested
1818
fetchTimeout = 5 * time.Second // Maximum alloted time to return an explicitly requested block
19+
maxUncleDist = 7 // Maximum allowed backward distance from the chain head
1920
maxQueueDist = 256 // Maximum allowed distance from the chain head to queue
2021
)
2122

@@ -202,7 +203,7 @@ func (f *Fetcher) loop() {
202203
break
203204
}
204205
// Otherwise if fresh and still unknown, try and import
205-
if number <= height || f.getBlock(op.block.Hash()) != nil {
206+
if number+maxUncleDist < height || f.getBlock(op.block.Hash()) != nil {
206207
continue
207208
}
208209
f.insert(op.origin, op.block)
@@ -317,7 +318,7 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
317318
hash := block.Hash()
318319

319320
// Discard any past or too distant blocks
320-
if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist <= 0 || dist > maxQueueDist {
321+
if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist {
321322
glog.V(logger.Detail).Infof("Peer %s: discarded block #%d [%x], distance %d", peer, block.NumberU64(), hash.Bytes()[:4], dist)
322323
return
323324
}

0 commit comments

Comments
 (0)