From 19a1c950467db58171532bbfcdc354f50a6e5f8e Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 9 Oct 2020 09:09:10 +0200 Subject: [PATCH] eth/downloader: cache parent hash instead of recomputing (#21678) --- eth/downloader/queue.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 51a57f0d4..d2ec8ba69 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -712,6 +712,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh } } if accepted { + parentHash := headers[0].Hash() for i, header := range headers[1:] { hash := header.Hash() if want := request.From + 1 + uint64(i); header.Number.Uint64() != want { @@ -719,11 +720,13 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh accepted = false break } - if headers[i].Hash() != header.ParentHash { + if parentHash != header.ParentHash { log.Warn("Header broke chain ancestry", "peer", id, "number", header.Number, "hash", hash) accepted = false break } + // Set-up parent hash for next round + parentHash = hash } } // If the batch of headers wasn't accepted, mark as unavailable