From c8f9d6bb902e72f4f854e38a5e2c4217794d02b1 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 27 Mar 2025 20:22:23 +0100 Subject: [PATCH] eth/downloader: fix crash when there are no results that have been downloaded --- eth/downloader/queue.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index a69a52175e..a9ba3156c3 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -375,10 +375,12 @@ func (q *queue) Results(block bool) []*fetchResult { results := q.resultCache.GetCompleted(maxResultsProcess) - // set a throttle threshhold based on estimated worst-sized block that can be created for a given gas limit. - gasLimit := max(results[0].Header.GasLimit, 1) - throttleThreshold := min(uint64(blockCacheMemory)/(gasLimit/10), 2048) - throttleThreshold = q.resultCache.SetThrottleThreshold(throttleThreshold) + if len(results) > 0 { + // set a throttle threshhold based on estimated worst-sized block that can be created for a given gas limit. + gasLimit := max(results[0].Header.GasLimit, 10) + throttleThreshold := min(uint64(blockCacheMemory)/(gasLimit/10), 2048) + throttleThreshold = q.resultCache.SetThrottleThreshold(throttleThreshold) + } // With results removed from the cache, wake throttled fetchers for _, ch := range []chan bool{q.blockWakeCh, q.receiptWakeCh} {