Skip to content

Commit

Permalink
bugfix: Fixed the downloader issue and extra genesis header response
Browse files Browse the repository at this point in the history
Removed the unnessesary number checks in the queue, and in the handlers
for the get header by number request was sending an extra genesis header
which is not required.

Also simplified the logic of accepting the chain of headers in the queue
  • Loading branch information
gameofpointers committed Jun 30, 2023
1 parent af7c08c commit c6ead67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
18 changes: 4 additions & 14 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,12 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
// Ensure headers can be mapped onto the skeleton chain
targetTo := q.headerToPool[request.From+1]

var accepted bool
requiredHeaderFetch := request.From - targetTo
if targetTo != 0 {
if targetTo != 0 || common.NodeLocation.Context() == common.PRIME_CTX {
requiredHeaderFetch += 1
}
accepted := len(headers) == int(requiredHeaderFetch)
accepted = len(headers) == int(requiredHeaderFetch)

// reverse the array
for i, j := 0, len(headers)-1; i < j; i, j = i+1, j-1 {
Expand All @@ -736,19 +737,8 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh

if accepted {
parentHash := headers[0].Hash()
for i, header := range headers[1:] {
for _, header := range headers[1:] {
hash := header.Hash()
var want uint64
if targetTo != 0 {
want = targetTo + 1 + uint64(i)
} else {
want = targetTo + 2 + uint64(i)
}
if header.Number().Uint64() != want {
logger.Warn("Header broke chain ordering", "number", header.Number(), "hash", hash, "expected", want)
accepted = false
break
}
if parentHash != header.ParentHash() {
logger.Warn("Header broke chain ancestry", "number", header.Number(), "hash", hash)
accepted = false
Expand Down
4 changes: 0 additions & 4 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ func answerGetBlockHeadersQuery(backend Backend, query *GetBlockHeadersPacket, p
// If the to number is reached stop the search
// By default the To is 0 and if its value is specified we need to stop
if query.To >= query.Origin.Number && query.Reverse {
if query.Origin.Number == 0 {
genesis := backend.Core().GetHeaderByNumber(0)
headers = append(headers, genesis)
}
break
}

Expand Down

0 comments on commit c6ead67

Please sign in to comment.