Skip to content
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

Ensure peer_disconnected is called after a handler refuses a connection #3580

Conversation

TheBlueMatt
Copy link
Collaborator

This is similar to #3110 but does the disconnection calls inline to avoid the races described in the discussion there.

Only the first commit should be backported.

If one message handler refuses a connection by returning an `Err`
from `peer_connected`, other handlers which already got the
`peer_connected` will not see the corresponding
`peer_disconnected`, leaving them in a potentially-inconsistent
state.

Here we ensure we call the `peer_disconnected` handler for all
handlers which received a `peer_connected` event (except the one
which refused the connection).
...to make it identical to all our other message handlers.
This adds a `ConnectionTracker` test util which is used across
`TestChannelMessageHandler`, `TestRoutingMessageHandler` and
`TestCustomMessageHandler`, asserting that `peer_connected` and
`peer_disconnected` methods are well-ordered. This expands test
coverage from just `TestChannelMessageHandler` to cover all test
handlers and adds some useful features which we'll use to test
the fix in the next commit.

This also adds an additional test which tests
`peer_{dis,}connected` consistency when a handler refuses a
connection by returning an `Err` from `peer_connected`.
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the last commit mentions a test being added in the next commit, but it was added in the same one

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM, one comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we enforce uniformity going forward by having the respective handler interfaces inherit from a general trait PeerMessageHandler interface and move peer_{connected, disconnected} and provided_{node,init}_features to it?

Note this would also allow us to iterate over all previously-succeeded handlers rather than having to call them individually (which might get stale at some point in the future).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we should definitely require uniformity going forward. We could definitely do a higer-level interface, do you want it in this PR or when we add the next handler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could definitely do a higer-level interface, do you want it in this PR or when we add the next handler?

I'd have a slight preference to do it right away, but feel free to do in a follow-up if you'd rather land this quickly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote the patch, but its 36 files changed, 982 insertions(+), 1018 deletions(-), so kinda would prefer to split it up just for sanity.

lightning/src/ln/peer_handler.rs Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator Author

Gonna go ahead and land this as both reviewers said LGTM and don't have remaining comments.

@TheBlueMatt TheBlueMatt merged commit ca40276 into lightningdevkit:main Feb 9, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

peer_disconnected event processing isn't robust if a peer_connected Errs
3 participants