-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Improvements on ADDR caching #19697
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
Improvements on ADDR caching #19697
Conversation
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. Nice explanation in 3a09c7b.
src/net.cpp
Outdated
@@ -2539,15 +2539,44 @@ std::vector<CAddress> CConnman::GetAddresses() | |||
return addresses; | |||
} | |||
|
|||
std::vector<CAddress> CConnman::GetAddresses(Network requestor_network) | |||
const std::vector<CAddress>& CConnman::GetAddresses(Network requestor_network, CAddress local_socket_address) |
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.
Is there any scenario where CAddress does not imply a Network?
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.
With Tor we may be seeing an IPv4 connection between Bitcoin Core and the Tor proxy (with IPv4 addresses) but the "requestor network" should be Tor, not IPv4.
src/net.cpp
Outdated
{ | ||
auto local_socket_bytes = local_socket_address.GetAddrBytes(); | ||
uint64_t cache_id = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE) |
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.
Ever overlapping caches sounds dangerous. Why not just index a unique cache per bind address?
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 can't grasp your concern, could you rephrase?
I believe the caches won't overlap across nodes because seeds inside GetDeterministicRandomizer
are unique. Or perhaps you are concerned with something else?
Concept ACK |
2e356dc
to
213bd3b
Compare
Ready for re-review :) |
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. |
213bd3b
to
49ce876
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.
Looks good. Just a few minor style comments.
49ce876
to
a3f1c2f
Compare
utACK a3f1c2f but needs rebase |
51bdb93
to
da184b0
Compare
da184b0
to
f680ae4
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.
ACK f680ae4
Perhaps the commit Address nits in ADDR caching
should be squashed into the previous commit Add indexing ADDR cache by local socket addr
?
@vasild Fixed the comment issue you pointed out!
I would leave it as is, that stuff doesn't have to do with indexing by local socket... |
f680ae4
to
0d04784
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.
ACK 0d04784
utACK 0d04784 |
{ | ||
SOCKET socket; | ||
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket); |
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.
Not really sure what is the purpose of cs_hSocket
, but looks like this should be
vector<unsigned char> local_socket_bytes = WITH_LOCK(requestor.cs_hSocket, return GetBindAddress(requestor.hSocket).GetAddrBytes())
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.
True, this looks better.
I'd keep it the way it is for now to save the review energy if you don't mind.
I will update these lines if I have other reasons to update the PR.
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.
It's fine, can come next too if it's the only thing that needs to be addressed.
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 0d04784
@@ -21,21 +16,9 @@ | |||
assert_equal, | |||
) | |||
|
|||
# As defined in net_processing. |
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.
-# As defined in net_processing.
-MAX_ADDR_TO_SEND = 1000
-MAX_PCT_ADDR_TO_SEND = 23
+MAX_ADDR_TO_SEND = 1000 # As defined in net.h
+MAX_PCT_ADDR_TO_SEND = 23 # As defined in net_processing.cpp
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.
Looks like a good suggestion,, but we can add more documentation later, didn't want to hold up the PR on this
Concept ACK. |
0d04784 Refactor the functional test (Gleb Naumenko) 83ad65f Address nits in ADDR caching (Gleb Naumenko) 81b00f8 Add indexing ADDR cache by local socket addr (Gleb Naumenko) 42ec558 Justify the choice of ADDR cache lifetime (Gleb Naumenko) Pull request description: This is a follow-up on bitcoin#18991 which does 3 things: - improves privacy of a node listening to multiple addresses via adding cache index by local socket addr (suggested [here](bitcoin#18991 (comment))) - documents on the choice of 24h cache lifetime - addresses nits from bitcoin#18991 ACKs for top commit: jnewbery: utACK 0d04784 vasild: ACK 0d04784 jonatack: Code review ACK 0d04784 Tree-SHA512: bb65a34dd1ce2811186d3e4469bc33e8399cebaaa494ce13041c7cff23275870e4176a719f7a72f8d779c49f8b2344bf4fa1aeb3ea4e2626d5ae76514f00a750
SOCKET socket; | ||
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket); | ||
auto local_socket_bytes = GetBindAddress(socket).GetAddrBytes(); |
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.
Can this be simplified like:
SOCKET socket; | |
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket); | |
auto local_socket_bytes = GetBindAddress(socket).GetAddrBytes(); | |
auto local_socket_bytes = requestor.addrBind.GetAddrBytes(); |
Our local address is already saved in CNode::addrBind
.
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 think you're right?
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.
Ok, will include this tiny change in another PR:
net: avoid unnecessary GetBindAddress() call
commit 15ba60e9a
Parent: 25dcd4ad9
Author: Vasil Dimov <vd@FreeBSD.org>
AuthorDate: Tue Nov 24 15:36:27 2020 +0100
Commit: Vasil Dimov <vd@FreeBSD.org>
CommitDate: Tue Nov 24 15:36:27 2020 +0100
net: avoid unnecessary GetBindAddress() call
Our local (bind) address is already saved in `CNode::addrBind` and there
is no need to re-retrieve it again with `GetBindAddress()`.
Also, for I2P connections `CNode::addrBind` would contain our I2P
address, but `GetBindAddress()` would return something like
`127.0.0.1:RANDOM_PORT`.
diff --git a/src/net.cpp b/src/net.cpp
index a811732e2..94a424ca3 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2601,15 +2601,13 @@ std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pc
}
return addresses;
}
std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct)
{
- SOCKET socket;
- WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket);
- auto local_socket_bytes = GetBindAddress(socket).GetAddrBytes();
+ auto local_socket_bytes = requestor.addrBind.GetAddrBytes();
uint64_t cache_id = GetDeterministicRandomizer(RANDOMIZER_ID_ADDRCACHE)
.Write(requestor.addr.GetNetwork())
.Write(local_socket_bytes.data(), local_socket_bytes.size())
.Finalize();
const auto current_time = GetTime<std::chrono::microseconds>();
auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
You just reviewed that! 🥳
Summary: PR description > This is a follow-up on #18991 which does 3 things: > > - improves privacy of a node listening to multiple addresses via adding cache index by local socket addr (suggested here) > - documents on the choice of 24h cache lifetime > - addresses nits from "Cache responses to GETADDR to prevent topology leaks" #18991 This is a backport of [[bitcoin/bitcoin#19697 | core#19697]] [1/4] bitcoin/bitcoin@42ec558 Test Plan: `ninja` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10290
Summary: This is a backport of [[bitcoin/bitcoin#19697 | core#19697]] [2/4] bitcoin/bitcoin@81b00f8 Depends on D10290 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10291
Summary: This is a backport of [[bitcoin/bitcoin#19697 | core#19697]] [3/4] bitcoin/bitcoin@83ad65f Depends on D10291 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien, baby636 Reviewed By: #bitcoin_abc, Fabien, baby636 Subscribers: baby636, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10292
Summary: This is a backport of [[bitcoin/bitcoin#19697 | core#19697]] [4/4] bitcoin/bitcoin@0d04784 Depends on D10292 Test Plan: `test/functional/test_runner.py p2p_getaddr_caching.py` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10293
This is a follow-up on #18991 which does 3 things: