Merge bitcoin/bitcoin#34300: test: use ephemeral ports in p2p_private_broadcast.py

3e340672ecadb2a32b19574a99a5162806af645e test: use ephemeral ports in p2p_private_broadcast.py (w0xlt)

Pull request description:

  The test `p2p_private_broadcast.py` gets some Python P2P nodes to listen and instructs the SOCKS5 proxy to redirect connections to them instead of to the requested addresses. This way the `bitcoind` which uses the proxy is tricked to think it has connected to real routable internet IP addresses or `.onion` addresses.

  Picking the ports where to Python P2P nodes to listen however is tricky to be done in a non-conflicting way, given that other tests may run in parallel. https://github.com/bitcoin/bitcoin/pull/34186 made it possible to let the OS select a free port, so use that in
  `p2p_private_broadcast.py`.

  ---

  _Suggested in https://github.com/bitcoin/bitcoin/pull/29415#discussion_r2654849875_

ACKs for top commit:
  l0rinc:
    code review ACK 3e340672ecadb2a32b19574a99a5162806af645e
  polespinasa:
    tACK 3e340672ecadb2a32b19574a99a5162806af645e
  mzumsande:
    utACK 3e340672ecadb2a32b19574a99a5162806af645e

Tree-SHA512: e94efd33a1845e1767aaada55f91c60bc5fc1166c281ef578a391e95e2791a922d84aa6ed1ce06e7d6ca1a65f84da52fd79d9b2f40705c1944a53c67b7392e4d
This commit is contained in:
merge-script 2026-01-15 14:29:14 +00:00
commit 697bc7f6a2
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -36,7 +36,6 @@ from test_framework.test_framework import (
BitcoinTestFramework,
)
from test_framework.util import (
MAX_NODES,
assert_equal,
assert_not_equal,
assert_raises_rpc_error,
@ -181,9 +180,6 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
self.socks5_server = Socks5Server(socks5_server_config)
self.socks5_server.start()
# Tor ports are the highest among p2p/rpc/tor, so this should be the first available port.
ports_base = tor_port(MAX_NODES) + 1
self.destinations = []
self.destinations_lock = threading.Lock()
@ -215,9 +211,12 @@ class P2PPrivateBroadcast(BitcoinTestFramework):
actual_to_addr = addr
actual_to_port = port
# Use port=0 to let the OS assign an available port. This
# avoids "address already in use" errors when tests run
# concurrently or ports are still in TIME_WAIT state.
self.network_thread.listen(
addr="127.0.0.1",
port=ports_base + i,
port=0,
p2p=listener,
callback=on_listen_done)
# Wait until the callback has been called.