From e47186db90c91bf86902e751b26245d671a66d56 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Tue, 11 Nov 2025 12:04:50 +1100 Subject: [PATCH] fix: decrease block retry count when no peers found There is a limitation in `downloadInternal` that infinitely loops for peers when attempting to download a block if the node does not have peers. Currently, the block retry counter is only decremented if there exists peers and a download attempt is made, otherwise the loop will continue until peers are found, ad infinium. This fix decrements the retry counter on each loop that no peers are found. --- codex/blockexchange/engine/engine.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codex/blockexchange/engine/engine.nim b/codex/blockexchange/engine/engine.nim index 962de133..73db0d63 100644 --- a/codex/blockexchange/engine/engine.nim +++ b/codex/blockexchange/engine/engine.nim @@ -371,6 +371,12 @@ proc downloadInternal( break # If we still don't have the block, we'll go for another cycle. trace "No peers for block, will retry shortly" + # Without decremeting the retries count, this would infinitely loop + # trying to find peers. + self.pendingBlocks.decRetries(address) + # `searchForNewPeers` will do nothing if DiscoveryRateLimit has not + # elapsed, so we should wait to avoid a noop + await sleepAsync(DiscoveryRateLimit) continue # Once again, it might happen that the block was requested to a peer