Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More relax inclusion of headers in the downloader #4050

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ func (hd *HeaderDownload) removeUpwards(toRemove []*Link) {

func (hd *HeaderDownload) MarkPreverified(link *Link) {
// Go through all parent links that are not preverified and mark them too
for link != nil && !link.persisted {
if !link.verified {
for link != nil && !link.verified {
if !link.persisted {
link.verified = true
hd.moveLinkToQueue(link, InsertQueueID)
link = hd.links[link.header.ParentHash]
}
link = hd.links[link.header.ParentHash]
}
}

Expand Down Expand Up @@ -275,13 +275,11 @@ func (hd *HeaderDownload) extendUp(segment ChainSegment, attachmentLink *Link) {
prevLink := attachmentLink
for i := len(segment) - 1; i >= 0; i-- {
link := hd.addHeaderAsLink(segment[i], false /* persisted */)
if prevLink.persisted {
// If we are attching to already persisted link, schedule for insertion (persistence)
if link.verified {
hd.moveLinkToQueue(link, InsertQueueID)
} else {
hd.moveLinkToQueue(link, VerifyQueueID)
}
// If we are attching to already persisted link, schedule for insertion (persistence)
if link.verified {
hd.moveLinkToQueue(link, InsertQueueID)
} else {
hd.moveLinkToQueue(link, VerifyQueueID)
}
prevLink.next = append(prevLink.next, link)
prevLink = link
Expand Down Expand Up @@ -365,12 +363,10 @@ func (hd *HeaderDownload) connect(segment ChainSegment, attachmentLink *Link, an
for i := len(segment) - 1; i >= 0; i-- {
link := hd.addHeaderAsLink(segment[i], false /* persisted */)
// If we attach to already persisted link, mark this one for insertion
if prevLink.persisted {
if link.verified {
hd.moveLinkToQueue(link, InsertQueueID)
} else {
hd.moveLinkToQueue(link, VerifyQueueID)
}
if link.verified {
hd.moveLinkToQueue(link, InsertQueueID)
} else {
hd.moveLinkToQueue(link, VerifyQueueID)
}
prevLink.next = append(prevLink.next, link)
prevLink = link
Expand Down Expand Up @@ -760,6 +756,18 @@ func (hd *HeaderDownload) InsertHeaders(hf FeedHeaderFunc, terminalTotalDifficul

checkInsert := true

if hd.trace {
var iStrs []string
for i := 0; i < hd.insertQueue.Len(); i++ {
iStrs = append(iStrs, fmt.Sprintf("%d=>%x", hd.insertQueue[i].blockHeight, hd.insertQueue[i].hash))
}
var vStrs []string
for i := 0; i < hd.verifyQueue.Len(); i++ {
vStrs = append(vStrs, fmt.Sprintf("%d=>%x", hd.verifyQueue[i].blockHeight, hd.verifyQueue[i].hash))
}
log.Info("InsertHeaders", "highestInDb", hd.highestInDb, "insertQueue", strings.Join(iStrs, ", "), "verifyQueue", strings.Join(vStrs, ", "))
}

for checkInsert {
checkInsert = false
// Check what we can insert without verification
Expand Down Expand Up @@ -798,6 +806,9 @@ func (hd *HeaderDownload) InsertHeaders(hf FeedHeaderFunc, terminalTotalDifficul
}

if link.blockHeight > hd.highestInDb {
if hd.trace {
log.Info("Highest in DB change", "number", link.blockHeight, "hash", link.hash)
}
hd.highestInDb = link.blockHeight
}
link.persisted = true
Expand Down
1 change: 1 addition & 0 deletions turbo/stages/headerdownload/header_data_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ type HeaderDownload struct {
requestChaining bool // Whether the downloader is allowed to issue more requests when previous responses created or moved an anchor
fetchingNew bool // Set when the stage that is actively fetching the headers is in progress
topSeenHeightPoW uint64
trace bool

consensusHeaderReader consensus.ChainHeaderReader
headerReader interfaces.HeaderReader
Expand Down