From 3df4197f2ee05a901c8d5b052067d1775579fd93 Mon Sep 17 00:00:00 2001 From: TBC Dev <48684072+tbcd@users.noreply.github.com> Date: Thu, 11 Nov 2021 15:53:32 +0800 Subject: [PATCH] Fix header skeleton (#2945) * Fix underflow only * Rename queryRange to maxHeight * Fix additional cases --- turbo/stages/headerdownload/header_algos.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/turbo/stages/headerdownload/header_algos.go b/turbo/stages/headerdownload/header_algos.go index 09ab708459..4b9bce66f4 100644 --- a/turbo/stages/headerdownload/header_algos.go +++ b/turbo/stages/headerdownload/header_algos.go @@ -571,21 +571,22 @@ func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest { defer hd.lock.RUnlock() log.Trace("Request skeleton", "anchors", len(hd.anchors), "top seen height", hd.topSeenHeight, "highestInDb", hd.highestInDb) stride := uint64(8 * 192) - queryRange := hd.topSeenHeight + nextHeight := hd.highestInDb + stride + maxHeight := hd.topSeenHeight + 1 // Inclusive upper bound + if maxHeight <= nextHeight { + return nil + } // Determine the query range as the height of lowest anchor for _, anchor := range hd.anchors { - if anchor.blockHeight > hd.highestInDb && anchor.blockHeight < queryRange { - queryRange = anchor.blockHeight + if anchor.blockHeight > nextHeight && anchor.blockHeight < maxHeight { + maxHeight = anchor.blockHeight // Exclusive upper bound } } - length := (queryRange - hd.highestInDb) / stride + length := (maxHeight - nextHeight) / stride if length > 192 { length = 192 } - if length == 0 { - return nil - } - return &HeaderRequest{Number: hd.highestInDb + stride, Length: length, Skip: stride, Reverse: false} + return &HeaderRequest{Number: nextHeight, Length: length, Skip: stride - 1, Reverse: false} } // InsertHeaders attempts to insert headers into the database, verifying them first -- GitLab