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

server: stagger connReqs to multi-address peers #5925

Merged

Conversation

ellemouton
Copy link
Collaborator

Currently if a peer has multiple working addresses (like 1 clearnet & 1 tor) we will, on startup and during reconnection, attempt to connect to all their advertised addresses at once. The peer will then accept the first connection and so we will cancel the second one but it already reaches the peer and so then they close the first connection in favour of the second one.

I have tested that this would also happen pre #5538 when establishPersistentConnections would kickoff all the connReqs at once but it would then recover since peerTerminationWatcher would only try to connect to a single address. With #5538, peerTerminationWatcher also uses all the advertised addresses during it's reconnection attempt and so the issue just keeps repeating itself.

In this PR: if we have multiple addresses stored for a peer, we stagger the creation of the connReqs for those addrs.

Fixes #5887

@ellemouton ellemouton changed the title server: stagger connReqs to multi-addresses peers server: stagger connReqs to multi-address peers Nov 3, 2021
@ellemouton ellemouton force-pushed the staggerConnToMultipleAddresses branch from b78dd4c to a73f599 Compare November 3, 2021 13:56
@Roasbeef Roasbeef requested a review from Crypt-iQ November 3, 2021 22:28
@Roasbeef Roasbeef added this to the v0.14.0 milestone Nov 3, 2021
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix! Only major comments are re improper typing of the constant controlling delay (appears to be using nanoseconds rn) and also the interplay between this and the existing stagger connection config/flag

Delete all the stored addresses from the persistentPeerAddr map when we
prune the persistent peer.
Let the connectToPersistentPeer func handle all connection attempts to
persistent peers so that that logic is in once place.
@ellemouton
Copy link
Collaborator Author

ellemouton commented Nov 4, 2021

Thanks for the review @Roasbeef 🚀

see my comment above re this stagger vs the existing stagger connection config/flag (tldr: existing stagger is for connection between multiple different peers and this stagger is for trying multiple addresses for the same peer so slightly different behaviour is wanted imo)

In this commit, we stagger the connection attempts to the multiple
addresses of a peer.
@ellemouton ellemouton force-pushed the staggerConnToMultipleAddresses branch from a73f599 to ac4fe5f Compare November 4, 2021 11:27
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🍂

Have one small thing will fix in a follow up commit.

@Roasbeef Roasbeef merged commit 1ab5cc3 into lightningnetwork:master Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto reconnect fails with some peers
2 participants