Skip to content

Commit

Permalink
headerdownload: fix OOM due to inifinitely growing children in link (#…
Browse files Browse the repository at this point in the history
…12405)

e2 cherry-pick of #12404
  • Loading branch information
taratorio authored Oct 22, 2024
1 parent b74578f commit 388ae1d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (hd *HeaderDownload) removeUpwards(link *Link) {
if link == nil {
return
}
if link.header != nil {
if parentLink, ok := hd.links[link.header.ParentHash]; ok {
parentLink.RemoveChild(link)
}
}
var toRemove = []*Link{link}
for len(toRemove) > 0 {
removal := toRemove[len(toRemove)-1]
Expand Down Expand Up @@ -514,8 +519,6 @@ func (hd *HeaderDownload) InsertHeader(hf FeedHeaderFunc, terminalTotalDifficult
}
if bad {
// If the link or its parent is marked bad, throw it out
hd.moveLinkToQueue(link, NoQueue)
delete(hd.links, link.hash)
hd.removeUpwards(link)
dataflow.HeaderDownloadStates.AddChange(link.blockHeight, dataflow.HeaderBad)
hd.stats.RejectedBadHeaders++
Expand All @@ -532,12 +535,7 @@ func (hd *HeaderDownload) InsertHeader(hf FeedHeaderFunc, terminalTotalDifficult
return false, false, 0, lastTime, nil // prevent removal of the link from the hd.linkQueue
} else {
hd.logger.Debug("[downloader] Verification failed for header", "hash", link.hash, "height", link.blockHeight, "err", err)
hd.moveLinkToQueue(link, NoQueue)
delete(hd.links, link.hash)
hd.removeUpwards(link)
if parentLink, ok := hd.links[link.header.ParentHash]; ok {
parentLink.RemoveChild(link)
}
dataflow.HeaderDownloadStates.AddChange(link.blockHeight, dataflow.HeaderEvicted)
hd.stats.InvalidHeaders++
return true, false, 0, lastTime, nil
Expand Down

0 comments on commit 388ae1d

Please sign in to comment.