Skip to content

Conversation

naumenkogs
Copy link
Member

This is a follow-up on #18991 which does 3 things:

@naumenkogs naumenkogs changed the title Minor improvements on ADDR caching Improvements on ADDR caching Aug 11, 2020
@fanquake fanquake added the P2P label Aug 11, 2020
Copy link
Contributor

@promag promag left a 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)
Copy link
Member

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?

Copy link
Contributor

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)
Copy link
Member

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?

Copy link
Member Author

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?

@practicalswift
Copy link
Contributor

Concept ACK

@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch 2 times, most recently from 2e356dc to 213bd3b Compare August 23, 2020 15:38
@naumenkogs
Copy link
Member Author

Ready for re-review :)

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 24, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, 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.

@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch from 213bd3b to 49ce876 Compare August 25, 2020 09:57
Copy link
Contributor

@jnewbery jnewbery 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 a few minor style comments.

@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch from 49ce876 to a3f1c2f Compare August 25, 2020 11:09
@jnewbery
Copy link
Contributor

utACK a3f1c2f but needs rebase

@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch 2 times, most recently from 51bdb93 to da184b0 Compare August 26, 2020 06:30
@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch from da184b0 to f680ae4 Compare August 27, 2020 07:54
Copy link
Contributor

@vasild vasild left a 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?

@naumenkogs
Copy link
Member Author

@vasild Fixed the comment issue you pointed out!

Perhaps the commit Address nits in ADDR caching should be squashed into the previous commit Add indexing ADDR cache by local socket addr?

I would leave it as is, that stuff doesn't have to do with indexing by local socket...

@naumenkogs naumenkogs force-pushed the 2020-08-addr-cache-follow-up branch from f680ae4 to 0d04784 Compare September 2, 2020 07:34
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 0d04784

@jnewbery
Copy link
Contributor

jnewbery commented Sep 2, 2020

utACK 0d04784

@naumenkogs naumenkogs closed this Sep 8, 2020
@naumenkogs naumenkogs reopened this Sep 8, 2020
{
SOCKET socket;
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket);
Copy link
Contributor

Choose a reason for hiding this comment

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

81b00f8

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())

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

@jonatack jonatack left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

0d04784

-# 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

Copy link
Member

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

@hebasto
Copy link
Member

hebasto commented Sep 21, 2020

Concept ACK.

@laanwj laanwj merged commit c0c409d into bitcoin:master Sep 21, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 21, 2020
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
Comment on lines +2545 to +2547
SOCKET socket;
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket);
auto local_socket_bytes = GetBindAddress(socket).GetAddrBytes();
Copy link
Contributor

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:

Suggested change
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.

Copy link
Member Author

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?

Copy link
Contributor

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! 🥳

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.