-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
net: Add unit testing of node eviction logic #20477
net: Add unit testing of node eviction logic #20477
Conversation
a989adf
to
9b6f891
Compare
cb12388
to
2c62fb6
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Thanks for working on adding testing here. I'll try to review this soon. |
Concept ACK. Thanks for adding tests. I sometimes wonder if it would make sense to move "semi-internal" things that are only exposed externally for unit testing, like in this case "NodeEvictionCandidate" and "SelectNodeToEvict", to a separate set of headers. But not here anyhow. |
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.
utACK 2c62fb6
. Thank you, @practicalswift for making the code more testable. Also for exposure to idiomatic modern C++. I will checkout the branch and run soon.
2c62fb6
to
8da8e88
Compare
tsan failue can be ignored or fixed by a rebase |
@MarcoFalke Thanks! Rebased! |
8da8e88
to
071b4cd
Compare
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.
Very strong concept ACK. This area of the code is definitely undertested. The structure of the unit tests (passing in a setup lambda function to set the relevant parameters in the eviction candidates) is really nice.
071b4cd
to
67f3759
Compare
needs rebase |
4d4639d
to
ccc8162
Compare
I've now reverted to the original version (alternative 1 below), since your suggestion and sipa's suggestion are mutually exclusive :) I'll let others chime in regarding the choice between the three alternatives:
Trying to summarize the pros/cons:
Perhaps the members of the review club could chime in. Some questions for the review club: Do you agree with the pros/cons of each alternative? Which alternative do you find easier to review? Which alternative do you prefer? Is it possible to quantify the real-world impact of the extraneous copy in a theoretical worst-case scenario? |
Will review properly as soon as my laptop is done with the gitian builds for 3 RCs...until then, it's basically unusable. |
Updated to address @dhruv's feedback. Should hopefully be ready for final review. Please re-review :) |
a9cfb77
to
1c9b235
Compare
ACK |
cr ACK 6767d63 🤠 Show signature and timestampSignature:
Timestamp of file with hash |
cr ACK 1c9b235 👲 Show signature and timestampSignature:
Timestamp of file with hash |
I ACKed both versions. Let me know which one to merge. |
code review ACK 1c9b235 Either are fine to merge. |
wait for meeee 😀 |
ACK 1c9b235 modulo a few suggestions |
1c9b235
to
fee8823
Compare
@jonatack Thanks for reviewing! Feedback addressed: please re-review :) |
ACK fee8823 Thanks for adding this nicely done coverage! Looking forward to more. |
ACK fee8823 🐼 Show signature and timestampSignature:
Timestamp of file with hash |
…eviction protection test coverage 0cca08a Add unit test coverage for our onion peer eviction protection (Jon Atack) caa21f5 Protect onion+localhost peers in ProtectEvictionCandidatesByRatio() (Jon Atack) 8f1a53e Use EraseLastKElements() throughout SelectNodeToEvict() (Jon Atack) 8b1e156 Add m_inbound_onion to AttemptToEvictConnection() (Jon Atack) 72e30e8 Add unit tests for ProtectEvictionCandidatesByRatio() (Jon Atack) ca63b53 Use std::unordered_set instead of std::vector in IsEvicted() (Jon Atack) 41f84d5 Move peer eviction tests to a separate test file (Jon Atack) f126cbd Extract ProtectEvictionCandidatesByRatio from SelectNodeToEvict (Jon Atack) Pull request description: Now that #19991 and #20210 have been merged, we can determine inbound onion peers using `CNode::m_inbound_onion` and add it to the localhost peers protection in `AttemptToEvictConnection`, which was added in #19670 to address issue #19500. Update 28 February 2021: I've updated this to follow gmaxwell's suggestion in #20197 (comment). This branch now protects up to 1/4 onion peers (connected via our tor control service), if any, sorted by longest uptime. If any (or all) onion slots remain after that operation, they are then allocated to protect localhost peers, or a minimum of 2 localhost peers in the case that no onion slots remain and 2 or more onion peers were protected, sorted as before by longest uptime. This patch also adds test coverage for the longest uptime, localhost, and onion peer eviction protection logic to build on the welcome initial unit testing of #20477. Suggest reviewing the commits that move code with `colorMoved = dimmed-zebra` and `colorMovedWs = allow-indentation-change`. Closes #11537. ACKs for top commit: laanwj: Code review ACK 0cca08a vasild: ACK 0cca08a Tree-SHA512: 2f5a63f942acaae7882920fc61f0185dcd51da85e5b736df9d1fc72343726dd17da740e02f30fa5dc5eb3b2d8345707aed96031bec143d48a2497a610aa19abd
Summary: ``` Onion peers are disadvantaged under our eviction criteria, so prevent eventual eviction of them in the presence of contention for inbound slots by reserving some slots for localhost peers (sorted by longest uptime). Block-relay-only connections exist as a protection against eclipse attacks, by creating a path for block propagation that may be unknown to adversaries. Protect against inbound peer connection slot attacks from disconnecting such peers by attempting to protect up to 8 peers that are not relaying transactions but appear to be full-nodes, sorted by recency of last delivered block. ``` Backport of [[bitcoin/bitcoin#19670 | core#19670]]. Note that tests will be added when porting this PR: bitcoin/bitcoin#20477 Ref T1611. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Maniphest Tasks: T1611 Differential Revision: https://reviews.bitcoinabc.org/D9676
Summary: Backport of [[bitcoin/bitcoin#20477 | core#20477]]. Depends on D9683. Ref T1611. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Maniphest Tasks: T1611 Differential Revision: https://reviews.bitcoinabc.org/D9684
Add unit testing of node eviction logic.
Closes #19966.