[Fix] Enforce the connected-peer cap when provers are present - #4332
Open
thep2p wants to merge 2 commits into
Open
[Fix] Enforce the connected-peer cap when provers are present#4332thep2p wants to merge 2 commits into
thep2p wants to merge 2 commits into
Conversation
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.
Motivation
Heartbeat::handle_connected_peersis meant to trim the node back toMAXIMUM_NUMBER_OF_PEERS(21) whenever it's over. It doesn't: whenever any provers are connected, it under-disconnects and the node settles at up tomax_peers + connected_provers— 26 instead of 21, a ~24% overshoot of the configured cap — and never converges.Root cause is a single wrong operand when splitting the disconnect budget between provers and everyone else:
Every prover disconnected is also a peer disconnected, so the non-prover budget must net out the provers being removed, not the ones remaining. Subtracting the larger "remaining" count drains the budget — usually to 0 — so non-provers are never trimmed:
Fix:
Test Plan
Added a table-driven unit test over four regimes (normal, prover-heavy, no-surplus, all-provers), each asserting the exact (provers, others) split and the invariant
provers + others == max(surplus_peers, surplus_provers). Red on staging, green with the fix. Router suite andclippy --lib -D warnings pass.Documentation
Does not add or change functionality, solely fixing an invariant.
Backwards compatibility
None affected — no wire, storage, or protocol changes; purely an internal connection-management correction.