Roll back composite sub-handlers when one rejects peer_connected#4595
Open
tnull wants to merge 1 commit intolightningdevkit:mainfrom
Open
Roll back composite sub-handlers when one rejects peer_connected#4595tnull wants to merge 1 commit intolightningdevkit:mainfrom
peer_connected#4595tnull wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
`composite_custom_message_handler!` expanded `peer_connected` to call every sub-handler and remember the last error, but never undo the already-succeeded ones. The `CustomMessageHandler::peer_connected` contract is that `PeerManager` will *not* invoke `peer_disconnected` when `peer_connected` returns `Err` — so any per-peer state allocated by an earlier sub-handler that returned `Ok` was leaked permanently once a later sub-handler returned `Err`. A peer who can elicit `Err` from any sub-handler in the composite (feature-bit gate, banlist, etc.) could repeatedly reconnect to grow that leaked state without bound (slow resource DoS), and "currently connected" predicates in the leaking sub-handler would lie about peers that were actually rejected. Mirror the rollback pattern `PeerManager` already uses for the four built-in handlers (`peer_handler.rs:2149-2188`): record each sub-handler's `peer_connected` result, and if any returned `Err`, call `peer_disconnected` on the ones that succeeded before propagating the failure. Co-Authored-By: HAL 9000
|
👋 I see @jkczyz was un-assigned. |
Collaborator
|
I've completed a thorough review of the entire diff. The macro change and the test are both correct. Analysis of the core logic:
Test analysis:
No issues found. |
TheBlueMatt
reviewed
May 5, 2026
| fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Bar)> { | ||
| vec![] | ||
| } | ||
| fn peer_disconnected(&self, _: PublicKey) {} |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4595 +/- ##
==========================================
- Coverage 86.84% 86.15% -0.69%
==========================================
Files 161 160 -1
Lines 109260 109304 +44
Branches 109260 109304 +44
==========================================
- Hits 94882 94174 -708
- Misses 11797 12517 +720
- Partials 2581 2613 +32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jkczyz
reviewed
May 5, 2026
Contributor
jkczyz
left a comment
There was a problem hiding this comment.
LGTM aside from needing to add the debug_assert.
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.
composite_custom_message_handler!expandedpeer_connectedto call every sub-handler and remember the last error, but never undo the already-succeeded ones. TheCustomMessageHandler::peer_connectedcontract is thatPeerManagerwill not invokepeer_disconnectedwhenpeer_connectedreturnsErr— so any per-peer state allocated by an earlier sub-handler that returnedOkwas leaked permanently once a later sub-handler returnedErr.A peer who can elicit
Errfrom any sub-handler in the composite (feature-bit gate, banlist, etc.) could repeatedly reconnect to grow that leaked state without bound (slow resource DoS), and "currently connected" predicates in the leaking sub-handler would lie about peers that were actually rejected.Mirror the rollback pattern
PeerManageralready uses for the four built-in handlers (peer_handler.rs:2149-2188): record each sub-handler'speer_connectedresult, and if any returnedErr, callpeer_disconnectedon the ones that succeeded before propagating the failure.Co-Authored-By: HAL 9000