peer selection - backoff when no peers available#458
Merged
freemans13 merged 1 commit intobsv-blockchain:mainfrom Feb 5, 2026
Merged
peer selection - backoff when no peers available#458freemans13 merged 1 commit intobsv-blockchain:mainfrom
freemans13 merged 1 commit intobsv-blockchain:mainfrom
Conversation
…tight loop and raise CPU
Contributor
|
🤖 Claude Code Review Status: Complete Summary: The changes look good and directly address the busy loop issue when no eligible peers are available. The addition of Analysis:
The backoff implementation is already present in the codebase (lines 669-688) with exponential backoff and peer attempt clearing, making this a straightforward fix to invoke it at the right points. No issues found - the implementation correctly prevents CPU-intensive busy loops while maintaining sync functionality. |
|
galt-tr
approved these changes
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
selectAndActivateNewPeer()to prevent busy-loop when peer selection failsProblem
When
selectAndActivateNewPeer()(called fromhandleRunningState()) fails to find a suitable sync peer, it simply returns without any backoff. This path runs every 2 seconds via the FSM monitor, and when all peers fail selection (e.g., health checks fail, all on cooldown), it creates a tight loop of:selectAndActivateNewPeer()Each iteration involves expensive health check HTTP requests for every peer.
Solution
Add
SyncAttemptCooldownto selection criteria - MakesselectAndActivateNewPeer()consistent withselectNewSyncPeer(), which already uses a 1-minute cooldown. Without this, peers could be retried immediately through this code path.Call
enterBackoffMode()when no peer found - When peer selection fails (either no eligible peers or selector returns empty), enter exponential backoff. This uses the existing backoff mechanism (2s, 4s, 8s, etc.) to prevent hammering peers when none are available.Test plan
🤖 Generated with Claude Code