-
Notifications
You must be signed in to change notification settings - Fork 266
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
Add limit for incoming connections from peers without channels #2601
Conversation
We should think about how this interacts with onion messages. Anyone can connect directly to us to send us a message (to request an invoice for an offer for instance) and we want to keep this behavior. We already have a limit to the number of onion message we accept per second (https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/scala/fr/acinq/eclair/io/PeerConnection.scala#L182) but unless we are currently receiving a lot of messages, we want to continue accepting messages from strangers. Looking at your proposal, it seems that once we reach the maximum number of connections allowed we don't accept new connections (and thus don't accept onion messages), if it doesn't cause other problems I would prefer continuing accepting new connections but closing old idle ones to stay under the limit. |
Good point; onion messages are going to be a new source of connections from nodes without channels. I didn't see anything in the Onion Message PR about whether or not a connection should be kept open indefinitely after sending an onion message. This could lead to hitting the limit proposed by this PR and cause an unintentional DoS for both opening channels and receiving onion messages. Without any limit it could also lead to an ever increasing number of connections. As suggested, one approach is to track a timestamp for each connection without a channel and periodically close inactive connections. This would require adding a new data structures in |
This PR implements similar functionality to LDK PR #1988 wrt limiting incoming connections. |
- added new child actor to Switchboard to track peers with inbound connections - terminate peer with oldest inbound connection if tracked peers are over limit
- if the channel is killed while waiting to open, it will lead to sending PeerDisconnected if that is the last channel.
- this ensures new connections will succeed while waiting for the PeerDisconnected event - will need to handle an extra unnecessary PeerDisconnected event after disconnecting an old node
- clearer name and homage to similar LDK parameter
244a87a
to
2cfe424
Compare
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #2601 +/- ##
==========================================
- Coverage 85.69% 85.65% -0.05%
==========================================
Files 211 212 +1
Lines 16919 16962 +43
Branches 728 723 -5
==========================================
+ Hits 14499 14529 +30
- Misses 2420 2433 +13
|
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.
Concept ACK! We'll probably need to beef up the release notes with more details about DoS issues at various level, I believe this should help node operators configure their eclair node to make sure this new feature doesn't create more problems that it solves.
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Show resolved
Hide resolved
- why we don't count all child actors - why a DoS attack is against inbound liquidity is now possible
eclair-core/src/main/scala/fr/acinq/eclair/io/Switchboard.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/io/IncomingConnectionsTracker.scala
Outdated
Show resolved
Hide resolved
- also add test to confirm actor terminates when sent an unhandled message
- prevent switchboard from sending an unhandled classic message if peer not found to disconnect
- peer can receive `Disconnect` before `Init`
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, I only have nits and we should be good to go 👍
eclair-core/src/main/scala/fr/acinq/eclair/io/PeerConnection.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/EclairImplSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/io/SwitchboardSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/io/IncomingConnectionsTrackerSpec.scala
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.
LGTM 🚀
Limit the number of incoming connections from nodes we don't have channels with.
switchboard
checks if we have channels with that peersync-whitelist
, do not track itWe do not track peers we initiate outgoing channel connections to