eth/downloader: cache parent hash instead of recomputing (#21678)

This commit is contained in:
Marius van der Wijden 2020-10-09 09:09:10 +02:00 committed by Igor Mandrigin
parent 99120e0c07
commit e40950ebd2

View File

@ -734,6 +734,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
} }
} }
if accepted { if accepted {
parentHash := headers[0].Hash()
for i, header := range headers[1:] { for i, header := range headers[1:] {
hash := header.Hash() hash := header.Hash()
if want := request.From + 1 + uint64(i); header.Number.Uint64() != want { if want := request.From + 1 + uint64(i); header.Number.Uint64() != want {
@ -741,11 +742,13 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
accepted = false accepted = false
break break
} }
if headers[i].Hash() != header.ParentHash { if parentHash != header.ParentHash {
log.Warn("Header broke chain ancestry", "peer", id, "number", header.Number, "hash", hash) log.Warn("Header broke chain ancestry", "peer", id, "number", header.Number, "hash", hash)
accepted = false accepted = false
break break
} }
// Set-up parent hash for next round
parentHash = hash
} }
} }
// If the batch of headers wasn't accepted, mark as unavailable // If the batch of headers wasn't accepted, mark as unavailable