test: use ephemeral ports in p2p_private_broadcast.py #34300

pull vasild wants to merge 1 commits into bitcoin:master from vasild:auto_ports_in_p2p_private_broadcast changing 1 files +4 −5
  1. vasild commented at 9:33 AM on January 15, 2026: contributor

    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. #34186 made it possible to let the OS select a free port, so use that in p2p_private_broadcast.py.


    Suggested in #29415 (review)

  2. test: use ephemeral ports in p2p_private_broadcast.py
    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`.
    3e340672ec
  3. DrahtBot added the label Tests on Jan 15, 2026
  4. DrahtBot commented at 9:33 AM on January 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34300.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK polespinasa, l0rinc, mzumsande

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. vasild commented at 9:35 AM on January 15, 2026: contributor

    Before this PR:

    Instructing the SOCKS5 proxy to redirect connection i=0 to 127.0.0.1:21337 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=1 to 127.0.0.1:21338 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=2 to 127.0.0.1:21339 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=3 to 127.0.0.1:21340 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=4 to 127.0.0.1:21341 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=5 to 127.0.0.1:21342 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=6 to 127.0.0.1:21343 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=7 to 127.0.0.1:21344 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=8 to 127.0.0.1:21345 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=9 to 127.0.0.1:21346 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=10 to 127.0.0.1:21325 (nodes[1])
    Instructing the SOCKS5 proxy to redirect connection i=11 to 127.0.0.1:21348 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=12 to 127.0.0.1:21349 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=13 to 127.0.0.1:21350 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=14 to 127.0.0.1:21351 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=15 to 127.0.0.1:21352 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=16 to 127.0.0.1:21353 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=17 to 127.0.0.1:21354 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=18 to 127.0.0.1:21355 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=19 to 127.0.0.1:21356 (a Python node)
    

    After:

    Instructing the SOCKS5 proxy to redirect connection i=0 to 127.0.0.1:48136 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=1 to 127.0.0.1:56793 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=2 to 127.0.0.1:57372 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=3 to 127.0.0.1:47092 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=4 to 127.0.0.1:60047 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=5 to 127.0.0.1:47150 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=6 to 127.0.0.1:45511 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=7 to 127.0.0.1:51333 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=8 to 127.0.0.1:38784 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=9 to 127.0.0.1:59711 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=10 to 127.0.0.1:23153 (nodes[1])
    Instructing the SOCKS5 proxy to redirect connection i=11 to 127.0.0.1:59840 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=12 to 127.0.0.1:42837 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=13 to 127.0.0.1:56980 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=14 to 127.0.0.1:34703 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=15 to 127.0.0.1:38243 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=16 to 127.0.0.1:54689 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=17 to 127.0.0.1:59958 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=18 to 127.0.0.1:45564 (a Python node)
    Instructing the SOCKS5 proxy to redirect connection i=19 to 127.0.0.1:35246 (a Python node)
    
  6. maflcko added this to the milestone 31.0 on Jan 15, 2026
  7. fanquake requested review from mzumsande on Jan 15, 2026
  8. polespinasa approved
  9. polespinasa commented at 12:07 PM on January 15, 2026: member

    tACK 3e340672ecadb2a32b19574a99a5162806af645e

    The change is clean and make much sense. Not much to add, tested on a pc with ubuntu and the behavior is the expected (as can be seen in the details), ports assigned are random free ports.

    <details>

    $ cat ~/Escritorio/debug_test.log | grep "Instructing the SOCKS5"
    2026-01-15T12:02:08.677968Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=0 to 127.0.0.1:40527 (a Python node)
    2026-01-15T12:02:09.180927Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=1 to 127.0.0.1:38025 (a Python node)
    2026-01-15T12:02:09.684747Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=2 to 127.0.0.1:45841 (a Python node)
    2026-01-15T12:02:10.187254Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=3 to 127.0.0.1:41685 (a Python node)
    2026-01-15T12:02:10.688802Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=4 to 127.0.0.1:37435 (a Python node)
    2026-01-15T12:02:11.193521Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=5 to 127.0.0.1:33293 (a Python node)
    2026-01-15T12:02:11.694581Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=6 to 127.0.0.1:41929 (a Python node)
    2026-01-15T12:02:12.195421Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=7 to 127.0.0.1:44423 (a Python node)
    2026-01-15T12:02:12.697424Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=8 to 127.0.0.1:39815 (a Python node)
    2026-01-15T12:02:13.199038Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=9 to 127.0.0.1:33761 (a Python node)
    2026-01-15T12:02:13.253484Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=10 to 127.0.0.1:25729 (nodes[1])
    2026-01-15T12:02:13.305812Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=11 to 127.0.0.1:41703 (a Python node)
    2026-01-15T12:02:13.357092Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=12 to 127.0.0.1:39827 (a Python node)
    2026-01-15T12:02:30.717269Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=13 to 127.0.0.1:33897 (a Python node)
    2026-01-15T12:02:30.768344Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=14 to 127.0.0.1:39527 (a Python node)
    2026-01-15T12:02:30.824610Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=15 to 127.0.0.1:41825 (a Python node)
    2026-01-15T12:02:31.025510Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=16 to 127.0.0.1:39307 (a Python node)
    2026-01-15T12:02:31.077260Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=17 to 127.0.0.1:35991 (a Python node)
    2026-01-15T12:02:31.334837Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=18 to 127.0.0.1:34345 (a Python node)
    2026-01-15T12:02:31.551738Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=19 to 127.0.0.1:34477 (a Python node)
    2026-01-15T12:02:31.708905Z TestFramework (DEBUG): Instructing the SOCKS5 proxy to redirect connection i=20 to 127.0.0.1:42799 (a Python node)
    
    

    </details>

  10. l0rinc commented at 12:29 PM on January 15, 2026: contributor

    code review ACK 3e340672ecadb2a32b19574a99a5162806af645e

  11. mzumsande commented at 12:52 PM on January 15, 2026: contributor

    utACK 3e340672ecadb2a32b19574a99a5162806af645e

  12. fanquake merged this on Jan 15, 2026
  13. fanquake closed this on Jan 15, 2026

  14. stickies-v referenced this in commit 9fa736f8e4 on Jan 22, 2026
  15. Sjors commented at 7:58 AM on January 23, 2026: member

    This might be triggering occasional test failures, e.g. #34387.

  16. vasild commented at 11:47 AM on January 23, 2026: contributor

    This might be triggering occasional test failures, e.g. #34387.

    This PR fiddles with bind ports. If it causes a test failure it would be something like "cannot bind to address: already in use". The failure in #34387 is a timeout because the transaction was not received by the expected recipient (within 60 seconds). Here is some tentative explanation: #34387 (comment)

  17. sedited referenced this in commit f5c7e7fe6b on Jan 23, 2026
  18. sedited referenced this in commit 319b3a3270 on Jan 23, 2026
  19. stringintech referenced this in commit 67e0422ca0 on Feb 2, 2026
  20. fanquake added the label Private Broadcast on Apr 21, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me