-
Notifications
You must be signed in to change notification settings - Fork 36.4k
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
Refactoring and minor improvement for self-advertisements #19843
Refactoring and minor improvement for self-advertisements #19843
Conversation
Build failing
|
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. |
954e678
to
2fba385
Compare
2fba385
to
49804a7
Compare
Concept ACK. |
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.
While AdvertiseLocal()
is refactored, mind adding a descriptive Doxygen comment to its declaration?
Moving the responsibility to check fListen
to callers looks a bit fragile. Maybe it would better to self-document it with the Assert(fListen);
?
3d4322c
to
af81f77
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.
concept ACK. have read through the code, but I'm still understanding the specifics of address semantics to work towards being able to leave a review ACK.
some structural feedback- it took a while for me to discern which parts were pure refactor vs behavioral change. breaking the first commit into 2 separate parts to clarify those boundaries would help ease review.
@amitiuttarwar how would you suggest to split the first commit into two? I'd be happy to take suggestions :) The only way I see is to add a flag to |
af81f77
to
85c9839
Compare
Per @amitiuttarwar 's suggestion, here's one way I might split your first commit 89c77a0 into two separate parts for easier review: Alternatively, here's a more fine-grained approach, in which I split your first commit 89c77a0 into 8 separate commits, 5 refactoring only commits and 3 behavior changes: The more fine-grained approach might also be helpful for PR Review Club participants who are trying to understand exactly what changed in your first commit. |
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.
The first commit seems ok, although it should be restructured to separate the pure refactor parts from the behaviour change parts.
I'm not sure that the second commit actually achieves anything. We have a rolling bloom filter m_addr_known
for each peer that prevents us from resending the same address multiple times, so I think even if we do call AdvertiseLocal()
again shortly after the verack, it won't actually result in us sending our address again.
@jnewbery thanks for the feedback, all addressed. Let's see others' preferences, I'm fine with dropping this commit too. |
eb59506
to
b77272e
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.
Thanks, I think I have a better understanding what's going on after your response. Just some nitty ideas. :)
src/net.h
Outdated
bool IsPeerAddrLocalGood(CNode& pnode); | ||
|
||
/** | ||
* Add our "best" local address to the batch of addresses we are planning |
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.
If we hear multiple addresses for ourselves from peers, how do we determine "best"?
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.
Expanded this comment a bit to refer to GetLocal
.
Evaluating the security of GetLocal
is on my TODO list, but for now we can assume it works I guess...
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
b77272e
to
25e674e
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.
I've re-reviewed. My comments have been addressed and I have no further comments at the moment.
5cda36f
to
314d755
Compare
…_local_addr_send This locking was mistakenly introduced in PR bitcoin#13123. Related conversation: bitcoin#13123 (comment) Making these fields atomic would ensure safety if multiple RPC accesses them.
They're not called outside net.cpp, so they only need internal linkage.
These functions can't be called with null ptrs, so change the signatures to take references.
Also make them doxygen comments.
…Local This is a pure refactor commit and moves the checks to the calling function.
Previously AdvertiseLocal() used either the address a peer thinks we are, or the address we think we are. Use both instead (assuming the local one is routable), as it would increase our chances of getting connected to.
Previously, we would prepare to self-announce to a new peer while parsing a VERSION message from that peer. This is useless, because we do something very similar in AdvertiseLocal(), although there are a couple differences: 1) AdvertiseLocal() does this for all peers, not just outbound 2) AdvertiseLocal() always asks the peer to advertise based on what they think we are AND what we think we are (assuming it's routable), while PushAddress(self) on VERSION always does one of the two. (1) and the fact that AdvertiseLocal() is called right before actually sending out ADDR message with our address makes it fully encompassing PushAddress(self) on VERSION. Per (2), AdvertiseLocal() seems like a better version of PushAddress(self) on VERSION. Thus, it's fine to drop PushAddress(self) on VERSION.
314d755
to
99f6768
Compare
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
Much changed since I opened this PR. Pretty sure dropping a redundant self-announcement from |
@naumenkogs - do you plan on picking this up now that #21186 is merged? Should we mark this PR up for grabs? |
@jnewbery Yeah I'd be happy to let someone else lead this. Let's mark it up for grabs. |
@dergoegge @mzumsande either of you might be interested in following up with the final commit, 99f6768, if it's still relevant? |
Only saw this now, because I was looking at the self-advertising logic, and I think it's still relevant, so I'm planing on following up. Another problem with the self-advertising within Version message processing is that it doesn't work well with addrv2: |
956c670 refactor, doc: Improve SetupAddressRelay call in version processing (Martin Zumsande) 3c43d9d p2p: Don't self-advertise during VERSION processing (Gleb Naumenko) Pull request description: This picks up the last commit from bitcoin#19843. Previously, we would prepare to self-announce to a new peer while parsing a `version` message from that peer. This is redundant, because we do something very similar in `MaybeSendAddr()`, which is called from `SendMessages()` after the version handshake is finished. There are a couple of differences: 1) `MaybeSendAddr()` self-advertises to all peers we do address relay with, not just outbound ones. 2) `GetLocalAddrForPeer()` called from `MaybeSendAddr()` makes a probabilistic decision to either advertise what they think we are or what we think we are, while `PushAddress()` on `version` deterministically only does the former if the address from the latter is unroutable. 3) During `version` processing, we haven't received a potential sendaddrv2 message from our peer yet, so self-advertisements with addresses from addrV2-only networks would always be dropped in `PushAddress()`. Since it's confusing to have two slightly different mechanisms for self-advertising, and the one in `MaybeSendAddr()` is better, remove the one in `version`. ACKs for top commit: stratospher: ACK 956c670 naumenkogs: ACK 956c670 amitiuttarwar: reACK 956c670 Tree-SHA512: 933d40615289f055c022170dde7bad0ac0a1d4be377538bfe9ba64375cfeb03bcd803901591f0739ac4850c880e8475a68fd1ab0330800030ab7f19e38c00274
956c670 refactor, doc: Improve SetupAddressRelay call in version processing (Martin Zumsande) 3c43d9d p2p: Don't self-advertise during VERSION processing (Gleb Naumenko) Pull request description: This picks up the last commit from bitcoin#19843. Previously, we would prepare to self-announce to a new peer while parsing a `version` message from that peer. This is redundant, because we do something very similar in `MaybeSendAddr()`, which is called from `SendMessages()` after the version handshake is finished. There are a couple of differences: 1) `MaybeSendAddr()` self-advertises to all peers we do address relay with, not just outbound ones. 2) `GetLocalAddrForPeer()` called from `MaybeSendAddr()` makes a probabilistic decision to either advertise what they think we are or what we think we are, while `PushAddress()` on `version` deterministically only does the former if the address from the latter is unroutable. 3) During `version` processing, we haven't received a potential sendaddrv2 message from our peer yet, so self-advertisements with addresses from addrV2-only networks would always be dropped in `PushAddress()`. Since it's confusing to have two slightly different mechanisms for self-advertising, and the one in `MaybeSendAddr()` is better, remove the one in `version`. ACKs for top commit: stratospher: ACK 956c670 naumenkogs: ACK 956c670 amitiuttarwar: reACK 956c670 Tree-SHA512: 933d40615289f055c022170dde7bad0ac0a1d4be377538bfe9ba64375cfeb03bcd803901591f0739ac4850c880e8475a68fd1ab0330800030ab7f19e38c00274
We have (almost) the same code chunk used twice. Improve that by slight refactoring.
The only behavior change is that the following will be also applied to the first (pre-VERACK) self-announcement:
And I think it's a good change anyway.
The last commit is just to consider the first self-announcement as regular and reset the timer, so that we don't send the second self-announcement too soon.
Note that since the first self-announcement is made at the end of processing VERSION, at that point addrLocal would be already filled with what the peers tells us we are, so this self-announcement would be no worse than any further one.