-
Notifications
You must be signed in to change notification settings - Fork 93
Enforce max reconnection attempts #5253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
9e31084 to
395a527
Compare
coot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
dmq-node/changelog.d/20251128_104246_karl.fb.knutsson_max_recon_main.md
Outdated
Show resolved
Hide resolved
ouroboros-network/changelog.d/20251128_094205_karl.fb.knutsson_max_recon_main.md
Outdated
Show resolved
Hide resolved
cardano-diffusion/changelog.d/20251128_104055_karl.fb.knutsson_max_recon_main.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a maximum reconnection attempt limit for peer connections in the Ouroboros Network peer selection governor. Peers that fail to connect repeatedly are now forgotten after exceeding a configurable retry limit, with exceptions for localroot peers, bootstrap relays, and manually configured public root peers which can retry indefinitely.
Key changes:
- Adds
policyMaxConnectionRetriesfield (default: 5) toPeerSelectionPolicy - Implements retry limit enforcement in the cold peer promotion failure handler
- Adds a
forgottenboolean flag to promotion failure trace events to indicate when a peer is removed - Updates all trace pattern matches and JSON serialization to handle the new parameter
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/Types.hs |
Adds policyMaxConnectionRetries field and forgotten parameter to trace constructors |
ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs |
Implements retry limit logic to forget peers after max failures, exempting localroots and bootstrap peers |
ouroboros-network/lib/Ouroboros/Network/Diffusion/Policies.hs |
Sets default policyMaxConnectionRetries value to 5 |
ouroboros-network/orphan-instances/Ouroboros/Network/OrphanInstances.hs |
Updates JSON serialization to include forgotten field |
dmq-node/src/DMQ/Diffusion/PeerSelection.hs |
Adds policyMaxConnectionRetries to DMQ policy |
cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection/MockEnvironment.hs |
Updates test trace patterns for new forgotten parameter |
cardano-diffusion/tests/lib/Test/Cardano/Network/PeerSelection.hs |
Updates test trace pattern matches |
cardano-diffusion/tests/lib/Test/Cardano/Network/Diffusion/Testnet.hs |
Updates test trace pattern matches |
ouroboros-network/changelog.d/20251128_094205_karl.fb.knutsson_max_recon_main.md |
Adds changelog entry |
dmq-node/changelog.d/20251128_104246_karl.fb.knutsson_max_recon_main.md |
Adds changelog entry |
cardano-diffusion/changelog.d/20251128_104055_karl.fb.knutsson_max_recon_main.md |
Adds changelog entry |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/Types.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/EstablishedPeers.hs
Outdated
Show resolved
Hide resolved
| unForgetAble = LocalRootPeers.member peeraddr localRootPeers || | ||
| (memberExtraPeers peeraddr (PublicRootPeers.getExtraPeers publicRootPeers)) | ||
| (publicRootPeers', knownPeers'', forgotten) = | ||
| if unForgetAble || failCount < policyMaxConnectionRetries |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name unForgetAble has inconsistent capitalization. Consider using unforgettable or unForgettable for better consistency with Haskell naming conventions (camelCase for local variables).
| unForgetAble = LocalRootPeers.member peeraddr localRootPeers || | |
| (memberExtraPeers peeraddr (PublicRootPeers.getExtraPeers publicRootPeers)) | |
| (publicRootPeers', knownPeers'', forgotten) = | |
| if unForgetAble || failCount < policyMaxConnectionRetries | |
| unForgettable = LocalRootPeers.member peeraddr localRootPeers || | |
| (memberExtraPeers peeraddr (PublicRootPeers.getExtraPeers publicRootPeers)) | |
| (publicRootPeers', knownPeers'', forgotten) = | |
| if unForgettable || failCount < policyMaxConnectionRetries |
| unForgetAble = LocalRootPeers.member peeraddr localRootPeers || | ||
| (memberExtraPeers peeraddr (PublicRootPeers.getExtraPeers publicRootPeers)) | ||
| (publicRootPeers', knownPeers'', forgotten) = | ||
| if unForgetAble || failCount < policyMaxConnectionRetries | ||
| then ( publicRootPeers | ||
| , KnownPeers.setConnectTimes (Map.singleton peeraddr (delay `addTime` now)) | ||
| knownPeers' | ||
| , False | ||
| ) | ||
| else ( PublicRootPeers.difference differenceExtraPeers publicRootPeers | ||
| (Set.singleton peeraddr) | ||
| , KnownPeers.delete (Set.singleton peeraddr) knownPeers' | ||
| , True | ||
| ) |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new behavior of forgetting peers after policyMaxConnectionRetries failed connection attempts lacks test coverage. Consider adding a test that verifies:
- Peers that are not localroots or bootstrap peers are forgotten after the maximum number of connection failures
- Localroot peers and bootstrap peers are never forgotten regardless of connection failure count
- The
forgottenflag is correctly set toTruein the trace when a peer is forgotten
Enforce a maximum limit on the number of times we will attempt to promote a peer to warm. Localroot peers, bootstrap relays and manually configured public root peers are exempt from this limit.
4344590 to
72a8bdb
Compare
Description
Enforce a maximum limit on the number of times we will attempt to promote a peer to warm. Localroot peers, bootstrap relays and manually configured public root peers are exempt from this limit.
Implements #5252
Checklist
Quality
Maintenance
ouroboros-networkproject.