浏览代码

Merge pull request #19534 from karalabe/downloader-delay-fix

eth/downloader: fix header delays during chain dedup
Péter Szilágyi 6 年之前
父节点
当前提交
78477e4118
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      eth/downloader/downloader.go

+ 7 - 0
eth/downloader/downloader.go

@@ -892,6 +892,7 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, pivot uint64)
 		}
 		}
 	}
 	}
 	// Start pulling the header chain skeleton until all is done
 	// Start pulling the header chain skeleton until all is done
+	ancestor := from
 	getHeaders(from)
 	getHeaders(from)
 
 
 	for {
 	for {
@@ -962,6 +963,12 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, pivot uint64)
 							head = full
 							head = full
 						}
 						}
 					}
 					}
+					// If the head is below the common ancestor, we're actually deduplicating
+					// already existing chain segments, so use the ancestor as the fake head.
+					// Otherwise we might end up delaying header deliveries pointlessly.
+					if head < ancestor {
+						head = ancestor
+					}
 					// If the head is way older than this batch, delay the last few headers
 					// If the head is way older than this batch, delay the last few headers
 					if head+uint64(reorgProtThreshold) < headers[n-1].Number.Uint64() {
 					if head+uint64(reorgProtThreshold) < headers[n-1].Number.Uint64() {
 						delay := reorgProtHeaderDelay
 						delay := reorgProtHeaderDelay