Skip to content

Conversation

@dergoegge
Copy link
Member

The addr cache id randomizer is currently supposed to be seeded with the network of the inbound connection and the local socket (only the address is used not the port):

bitcoin/src/net.cpp

Lines 2800 to 2804 in a8098f2

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

For inbound onion connections CNode::addr.GetNetwork() returns NET_UNROUTABLE and CNode::addrBind is set to 127.0.0.1:<onion bind port>. This results in the same addr cache for all inbound connections on 127.0.0.1 binds.

To avoid the same addr cache across all onion and other 127.0.0.1 binds, we should seed the addr cache randomizer with the correct network for inbound onion connections (using CNode::ConnectedThroughNetwork()) as well as the port of CNode::addrBind.

@fanquake fanquake added the P2P label May 9, 2022
@jonatack
Copy link
Member

jonatack commented May 9, 2022

Concept ACK

@dergoegge dergoegge force-pushed the 2022-05-improve-addr-cache branch 2 times, most recently from 1968c8a to 4df29c9 Compare May 10, 2022 10:33
@theStack
Copy link
Contributor

Concept ACK

@dergoegge dergoegge force-pushed the 2022-05-improve-addr-cache branch from 4df29c9 to 224d765 Compare May 10, 2022 18:57
@DrahtBot
Copy link
Contributor

DrahtBot commented May 10, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24571 (p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge)
  • #23127 (tests: Use test framework utils where possible by vincenzopalazzo)

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
Copy link
Contributor

Concept ACK

@naumenkogs
Copy link
Contributor

utACK f5e1269fbeaaf37fdb3945381231d5ff9834e42e

@fanquake fanquake requested review from jnewbery and mzumsande May 25, 2022 08:51
Copy link
Contributor

@mzumsande mzumsande 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 f5e1269fbeaaf37fdb3945381231d5ff9834e42e

If it was somehow possible for inbound peers to make us generate additional bind addresses, this could be abused to make us create a lot of caches, but I don't think this is possible in any way.

@dergoegge dergoegge force-pushed the 2022-05-improve-addr-cache branch from f5e1269 to 292828c Compare June 2, 2022 17:16
@dergoegge
Copy link
Member Author

Thanks @mzumsande for the review, I took both of your suggestions.

@sipa
Copy link
Member

sipa commented Jun 2, 2022

utACK 292828c

@mzumsande
Copy link
Contributor

Code Review ACK 292828c

@naumenkogs
Copy link
Contributor

utACK 292828c

@fanquake fanquake merged commit b9416c3 into bitcoin:master Jun 8, 2022
def set_test_params(self):
self.num_nodes = 1
# Start onion ports after p2p and rpc ports.
port = PORT_MIN + 2 * PORT_RANGE
Copy link
Member

Choose a reason for hiding this comment

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

pretty sure the tests only pass by accident? Locally they fail for me:

./test/functional/test_runner.py p2p_getaddr_caching feature_proxy feature_bind_extra p2p_add_connections 

p2p_add_connections.py | ✓ Passed  | 7 s
feature_bind_extra.py  | ✖ Failed  | 1 s
feature_proxy.py       | ✖ Failed  | 1 s
p2p_getaddr_caching.py | ✖ Failed  | 20 s

The basic idea is that all port ranges for all tests are fully assigned once the test_runner starts. Using the same range for different tests is asking for collisions.

One option to fix this would be to start a third range for "other" ports or just use one of the 12 ports assigned to each test (initially intended to be used by the test nodes itself).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops sorry about that, will have a PR up shortly...

maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Jun 10, 2022
…getaddr_caching.py

ea54ba2 [test] Fix port collisions caused by p2p_getaddr_caching.py (dergoegge)
f9682e7 [test_framework] Set PortSeed.n directly after initialising params (dergoegge)

Pull request description:

  This PR fixes the issue mentioned [here](bitcoin/bitcoin#25096 (comment)), to avoid port collisions between nodes spun up by the test framework.

Top commit has no ACKs.

Tree-SHA512: ec9159f0af90db636f7889d664c24e1430cf2bcb3c02a9ab2dcfe531b2a4d18f6e3a0f8ba73071bdf2f7db518df9d5d86a9cd06695e67644d20fe4515fac32b7
maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Jun 10, 2022
fa7a711 test: Fix out-of-range port collisions (MacroFake)

Pull request description:

  Otherwise the test will fail if two tests running in parallel use the same port. See bitcoin/bitcoin#25096 (comment) and bitcoin/bitcoin#25312

ACKs for top commit:
  dergoegge:
    ACK fa7a711 - This gets rid of some rather arbitrary choices for ports in some of our functional tests that can cause port collisions across test runs, resulting in intermittent failures.

Tree-SHA512: ac73da8a498230b992ab12e1ee3c4ff3d868cd63c00d2c71537d156cb7c8f8be8598ec574646b17c5a44ae3ac5bb54bf29d300f054a36cec6f6ce8054a0da0a4
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 13, 2022
292828c [test] Test addr cache for multiple onion binds (dergoegge)
3382905 [net] Seed addr cache randomizer with port from binding address (dergoegge)
f10e80b [net] Use ConnectedThroughNetwork() instead of GetNetwork() to seed addr cache randomizer (dergoegge)

Pull request description:

  The addr cache id randomizer is currently supposed to be seeded with the network of the inbound connection and the local socket (only the address is used not the port):  https://github.com/bitcoin/bitcoin/blob/a8098f2cef53ec003edae91100afce564e9c6f23/src/net.cpp#L2800-L2804

  For inbound onion connections `CNode::addr.GetNetwork()` returns `NET_UNROUTABLE` and `CNode::addrBind` is set to `127.0.0.1:<onion bind port>`. This results in the same addr cache for all inbound connections on 127.0.0.1 binds.

  To avoid the same addr cache across all onion and other 127.0.0.1 binds, we should seed the addr cache randomizer with the correct network for inbound onion connections (using `CNode::ConnectedThroughNetwork()`) as well as the port of `CNode::addrBind`.

ACKs for top commit:
  sipa:
    utACK 292828c
  mzumsande:
    Code Review ACK 292828c
  naumenkogs:
    utACK 292828c

Tree-SHA512: d0be13bab6bc121c2926d4b168687f6c2ed4ce0c9dd19be71eb4886adeba8afc3daacdc4e232a0ba3b03a89d69b618abc5595b69abd1ad0c476d825bc6ea1f9f
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 13, 2022
…caching.py

ea54ba2 [test] Fix port collisions caused by p2p_getaddr_caching.py (dergoegge)
f9682e7 [test_framework] Set PortSeed.n directly after initialising params (dergoegge)

Pull request description:

  This PR fixes the issue mentioned [here](bitcoin#25096 (comment)), to avoid port collisions between nodes spun up by the test framework.

Top commit has no ACKs.

Tree-SHA512: ec9159f0af90db636f7889d664c24e1430cf2bcb3c02a9ab2dcfe531b2a4d18f6e3a0f8ba73071bdf2f7db518df9d5d86a9cd06695e67644d20fe4515fac32b7
@bitcoin bitcoin locked and limited conversation to collaborators Jun 8, 2023
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.

9 participants