-
Notifications
You must be signed in to change notification settings - Fork 37.7k
p2p: Improve diversification of new connections #27264
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
Conversation
ADDR_FETCH and FEELER are short-lived connections, and they should not affect our choice of peers. Also, improve comments.
…onns Previously, we would make connections to peer from the netgroups to which our MANUAL outbound connections belong. However, they should be seen as regular connections from Addrman when it comes to netgroup diversity check, since the same rationale can be applied. Note, this has nothing to do with how we connect to MANUAL connections: we connect to them unconditionally.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
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.
I wasn't able to answer this #19860 (comment). (so didn't include it) |
I guess to ensure that it was set according to the expectations and also to serve as a hint to the reader that it will never be those values. Usually such asserts are put right after setting the variable is finished. It is ok without it too. Up to you. Thanks! |
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.
Code Review ACK 72e8ffd
(I had already ack'ed #19860 ).
I prefer the current version without the last commit of 19860. Even though the asserts are safe, they don't seem necessary. In general, I think we should use asserts very sparingly in p2p code (only in situations where not crashing would lead to serious problems), because of the risk of future remote crash bugs.
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.
crACK 72e8ffd
code review ACK 72e8ffd |
utACK I was least sure about excluding netgroups that we have MANUAL connections to. As best as I can tell, @lightlike's reason for doing so seems to be the strongest reason:
I think that makes sense to me. However, it occurred to me that for networks where we have authenticated connections -- I2P, onion, CJDNS(?) -- that this argument would not apply. Moreover I guess doing any kind of "netgroup"-based diversification for these peers doesn't make sense, since for those addresses, our group assignments are arbitrary and there's no relationship between the address and our route? (If that understanding is correct then that is a separate issue from the improvement here, so could be picked up in another PR.) |
Yes, in CJDNS the address is (a representation) of the owner's public key.
My understanding is that this is true for Tor, I2P and CJDNS. |
I agree, and I think there is another problem that is exacerbated by this PR: The grouping is not just arbitrary for these networks, it also prevents us from making connections to addresses from groups we are already connected to, which is a real issue here because there are only 16 possible netgroups for each of the non-clearnet networks (see NetGroupManager::GetGroup(), the code is not exactly trivial to understand though) |
yes! thanks @mzumsande, will address this in a follow-up PR. update: opened #27374 to skip tor/i2p/cjdns addresses in setConnected for now. |
How? I opened #27369 to discuss ideas on how to approach this. |
…ections for tor/i2p/cjdns b5585ba p2p: skip netgroup diversity of new connections for tor/i2p/cjdns networks (stratospher) Pull request description: Follow up for #27264. In order to make sure that our persistent outbound slots belong to different netgroups, distinct net groups of our peers are added to `setConnected`. We’d only open a persistent outbound connection to peers which have a different netgroup compared to those netgroups present in `setConnected`. Current `GetGroup()` logic assumes route-based diversification behaviour for tor/i2p/cjdns addresses (addresses are public key based and not route-based). Distinct netgroups possible (according to the current `GetGroup()` logic) for: 1. tor => 030f, 031f, .. 03ff (16 possibilities) 2. i2p => 040f, 041f, .. 04ff (16 possibilities) 3. cjdns => 05fc0f, 05fc1f, ... 05fcff (16 possibilities) `setConnected` is used in `ThreadOpenConnections()` before making [outbound](https://github.com/bitcoin/bitcoin/blob/84f4ac39fda7ffa5dc84e92d92dd1eeeb5e20f8c/src/net.cpp#L1846) and [anchor](https://github.com/bitcoin/bitcoin/blob/84f4ac39fda7ffa5dc84e92d92dd1eeeb5e20f8c/src/net.cpp#L1805) connections to new peers so that they belong to distinct netgroups. **behaviour on master** - if we run a node only on tor/i2p/cjdns - we wouldn't be able to open more than 16 outbound connections(manual, block-relay-only anchor, outbound full relay, block-relay-only connections) because we run out of possible netgroups. - see bitcoin/bitcoin#27264 (comment) - tested by changing `MAX_OUTBOUND_FULL_RELAY_CONNECTIONS` to 17 with `onlynet=onion` and observed how node wouldn't make more than 16 outbound connections. **behaviour on PR** - netgroup diversity checks are skipped for tor/i2p/cjdns addresses. - we don't insert tor/i2p/cjdns address in `setConnected` and `GetGroup` doesn't get called on tor/i2p/cjdns(see #27369) ACKs for top commit: achow101: ACK b5585ba mzumsande: ACK b5585ba vasild: ACK b5585ba Tree-SHA512: c120b3f9ca7f0be3f29ea665cd2f7dfb40cd1d7ec7058984252fb6e0295e414f736c5b4fba03c31188188a5ae4f543fb2654f6ee9776bad745c7ca72d23d5b9b
Revives #19860.
In order to make sure that our persistent outbound slots belong to different netgroups, distinct net groups of our peers are added to
setConnected
. We’d only open a persistent outbound connection to peers which have a different netgroup compared to those netgroups present insetConnected
.behaviour on master
we open persistent outbound connections to peers which have different netgroups compared to outbound full relay, block relay, addrfetch and feeler connection peers.
behaviour on PR
netgroup diversity is based on outbound full relay, block relay and manual connection peers.
rationale