From 388ae1de021cd81c0f840c6cce6d86aa02c46da1 Mon Sep 17 00:00:00 2001 From: milen <94537774+taratorio@users.noreply.github.com> Date: Tue, 22 Oct 2024 06:51:17 +0100 Subject: [PATCH] headerdownload: fix OOM due to inifinitely growing children in link (#12405) e2 cherry-pick of https://github.com/erigontech/erigon/pull/12404 --- turbo/stages/headerdownload/header_algos.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/turbo/stages/headerdownload/header_algos.go b/turbo/stages/headerdownload/header_algos.go index 4604ee360bc..7d177607efe 100644 --- a/turbo/stages/headerdownload/header_algos.go +++ b/turbo/stages/headerdownload/header_algos.go @@ -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] @@ -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++ @@ -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