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

Limit the number of outbound peer connections #2944

Merged
merged 16 commits into from
Oct 27, 2021
Merged

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Oct 25, 2021

Motivation

We want to limit Zebra's outbound peer connections to avoid whole-of-network denial of service attacks.

Solution

Implementation:

  • Limit the number of outbound connections in the crawler
  • Bias Zebra towards outbound connections
  • Make zebra-network channel bounds depend on config.peerset_initial_target_size

Bug fixes:

  • Avoid cooperative async task starvation in the peer crawler and listener

Unit tests:

  • Add zebra_network::initialize tests with limited numbers of peers
  • Test the crawler with small connection limits and connection errors
  • Test the crawler with small connection limits and connection success then close
  • Test the crawler with small connection limits and connection success then stay open
  • Test the crawler with the default connection limit and connection success then stay open

Runtime checks:

Local tests:

  • I've run the node for a few days and it seems stable, the connection limits seem to work
  • I've run the unit tests repeatedly, and they seem reliable on my machine

Closes #1850.

Review

@jvff is a good person to review this PR.

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

@teor2345 teor2345 added P-High C-security Category: Security issues I-remote-node-overload Zebra can overload other nodes on the network A-network Area: Network protocol updates or fixes labels Oct 25, 2021
@teor2345 teor2345 requested a review from jvff October 25, 2021 00:19
@teor2345 teor2345 self-assigned this Oct 25, 2021
jvff
jvff previously approved these changes Oct 25, 2021
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Looks good, just added some minor questions/nit-picks.

zebra-network/src/config.rs Outdated Show resolved Hide resolved
zebra-network/src/constants.rs Outdated Show resolved Hide resolved
zebra-network/src/peer_set/initialize.rs Show resolved Hide resolved
Copy link
Contributor Author

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

@conradoplg here are some notes on testing.

You might need the task starvation fixes in 5d245cf to avoid test hangs.
(Commit name: Avoid cooperative async task starvation...)

And you might need the new Config methods in 0b5f82e.
(Bias Zebra towards outbound connections.)

zebra-network/src/peer_set/initialize/tests/vectors.rs Outdated Show resolved Hide resolved
@teor2345

This comment has been minimized.

@teor2345 teor2345 marked this pull request as ready for review October 27, 2021 01:24
@teor2345
Copy link
Contributor Author

I've checked the "network health" Grafana dashboard. It shows the peer count dropping to ~75 when I implemented the outbound connection limit.

Screen Shot 2021-10-27 at 11 39 58

Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

I think this looks good and suggestions from @jvff were applied.

@teor2345 teor2345 enabled auto-merge (squash) October 27, 2021 20:28
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Looks good. The tests are very similar to the ones in #2961 (or maybe it should be the other way round 😅 ), so some review comments from there might also be useful here.

But we can merge as is and take a look at improving all of them later 👍

@teor2345 teor2345 merged commit 3e03d48 into main Oct 27, 2021
@teor2345 teor2345 deleted the limit-outbound-peers branch October 27, 2021 21:28
mpguerra added a commit that referenced this pull request May 19, 2023
mergify bot pushed a commit that referenced this pull request May 23, 2023
* ZIPs were updated to remove ambiguity, this was tracked in #1267.

* #2105 was fixed by #3039 and #2379 was closed by #3069

* #2230 was a duplicate of #2231 which was closed by #2511

* #3235 was obsoleted by #2156 which was fixed by #3505

* #1850 was fixed by #2944, #1851 was fixed by #2961 and #2902 was fixed by #2969

* We migrated to Rust 2021 edition in Jan 2022 with #3332

* #1631 was closed as not needed

* #338 was fixed by #3040 and #1162 was fixed by #3067

* #2079 was fixed by #2445

* #4794 was fixed by #6122

* #1678 stopped being an issue

* #3151 was fixed by #3934

* #3204 was closed as not needed

* #1213 was fixed by #4586

* #1774 was closed as not needed

* #4633 was closed as not needed

* Clarify behaviour of difficulty spacing

Co-authored-by: teor <teor@riseup.net>

* Update comment to reflect implemented behaviour

Co-authored-by: teor <teor@riseup.net>

* Update comment to reflect implemented behaviour when retrying block downloads

Co-authored-by: teor <teor@riseup.net>

* Update `TODO` to remove closed issue and clarify when we might want to fix

Co-authored-by: teor <teor@riseup.net>

* Update `TODO` to remove closed issue and clarify what we might want to change in future

Co-authored-by: teor <teor@riseup.net>

* Clarify benefits of how we do block verification

Co-authored-by: teor <teor@riseup.net>

* Fix rustfmt errors

---------

Co-authored-by: teor <teor@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-network Area: Network protocol updates or fixes C-security Category: Security issues I-remote-node-overload Zebra can overload other nodes on the network
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Security: Limit the number of outbound peer connections when dialing new peers
3 participants