test: avoid internet traffic #31646

pull vasild wants to merge 3 commits into bitcoin:master from vasild:test_avoid_internet_traffic changing 4 files +27 −17
  1. vasild commented at 9:24 am on January 13, 2025: contributor

    Avoid generating outbound traffic on a non-loopback interface during tests. Fix all tests, including ones that generate DNS traffic.


    This is a subset of #31349 containing only the changes to the tests, without the CI changes to detect future regressions.

  2. DrahtBot commented at 9:24 am on January 13, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK brunoerg, kevkevinpal, BrandonOdiwuor, jonatack
    Concept ACK tdb3
    Stale ACK mzumsande

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31349 (ci: detect outbound internet traffic generated while running tests by vasild)

    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.

  3. DrahtBot added the label Tests on Jan 13, 2025
  4. brunoerg commented at 12:50 pm on January 13, 2025: contributor

    Concept ACK

    What about having an option to set this in BitcoinTestFramework and avoid the duplicated code?

  5. vasild force-pushed on Jan 13, 2025
  6. vasild commented at 5:31 pm on January 13, 2025: contributor
    3eb4ad7740...66dbfaca22: dedup the definition of the unreachable proxy arg variable, thanks @brunoerg
  7. DrahtBot added the label CI failed on Jan 13, 2025
  8. DrahtBot removed the label CI failed on Jan 13, 2025
  9. in test/functional/p2p_seednode.py:21 in 67487c6664 outdated
    16@@ -17,32 +17,34 @@
    17 class P2PSeedNodes(BitcoinTestFramework):
    18     def set_test_params(self):
    19         self.num_nodes = 1
    20+        # Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
    21+        self.extra_args = [["-proxy=127.0.0.1:1"]]
    


    mzumsande commented at 11:31 pm on January 13, 2025:
    could use UNREACHABLE_PROXY_ARG here as well

    vasild commented at 8:23 am on January 14, 2025:
    Indeed! Done, thanks!
  10. mzumsande commented at 11:32 pm on January 13, 2025: contributor
    Code Review ACK 66dbfaca22ba55aea3a5e7ab73974b42134ba8f4
  11. DrahtBot requested review from brunoerg on Jan 13, 2025
  12. tdb3 commented at 1:08 am on January 14, 2025: contributor

    Concept ACK

    Nice. Better consistency/privacy as well as a test runtime reduction. Will circle back to take a deeper look.

  13. test: avoid generating non-loopback traffic from p2p_seednode.py
    `p2p_seednode.py` would try to connect to `0.0.0.1` and `0.0.0.2` as
    seed nodes. This sends outbound TCP packets on a non-loopback interface
    to the default router.
    
    Configure an unavailable proxy for all executions of `bitcoind` during
    this test. Also change `0.0.0.1` and `0.0.0.2` because connecting to
    them would skip the `-proxy=` setting because for such an address:
    * `CNetAddr::IsLocal()` is true, thus
    * `CNetAddr::IsRoutable()` is false, thus
    * `CNetAddr::GetNetwork()` is `NET_UNROUTABLE`, even though
      `CNetAddr::m_net` is `NET_IPV4`.
    
    This speeds up the execution time of `p2p_seednode.py`
    from 12.5s to 2.5s.
    6b3f6eae70
  14. test: avoid generating non-loopback traffic from feature_config_args.py
    `feature_config_args.py` uses a proxy address of `1.2.3.4`. This results
    in actually trying to open TCP connections over the internet to
    `1.2.3.4:9050`.
    
    The test does not need those to succeed so use `127.0.0.1:1` instead.
    
    Also avoid `-noconnect=0` because that is interpreted as `-connect=1`
    which is interpreted as `-connect=0.0.0.1` and a connection to
    `0.0.0.1:18444` is attempted.
    a5746dc559
  15. test: avoid generating non-loopback traffic from p2p_dns_seeds.py
    `p2p_dns_seeds.py` would try to connect to the DNS server configured on
    the machine and resolve `dummySeed.invalid`.
    
    To block that configure an unavailable proxy which will be used also to
    connect to the name server. The test needs 2 successful connections to
    other peers (two Python `P2PInterface`s) and they work in spite of the
    unavailable proxy because they are on `127.0.0.1` (`NET_UNROUTABLE`) and
    the proxy is not used for that.
    2ed161c5ce
  16. vasild force-pushed on Jan 14, 2025
  17. vasild commented at 8:23 am on January 14, 2025: contributor
    66dbfaca22...2ed161c5ce: do #31646 (review)
  18. brunoerg approved
  19. brunoerg commented at 11:21 am on January 14, 2025: contributor
    code review ACK 2ed161c5ce648cb66ec3d2941b02d68b6ca4c390
  20. DrahtBot requested review from tdb3 on Jan 14, 2025
  21. DrahtBot requested review from mzumsande on Jan 14, 2025
  22. kevkevinpal commented at 12:13 pm on January 14, 2025: contributor

    light code review ACK 2ed161c

    I think it makes sense that our test suite should not attempt to make outbound connections this is a welcomed change

  23. BrandonOdiwuor approved
  24. BrandonOdiwuor commented at 12:28 pm on January 14, 2025: contributor
    Code Review ACK 2ed161c5ce648cb66ec3d2941b02d68b6ca4c390
  25. jonatack commented at 3:48 pm on January 14, 2025: member

    ACK 2ed161c5ce648cb66ec3d2941b02d68b6ca4c390

    (did not observe an increase in speed on arm64 m1 max macos 15.2)

  26. glozow merged this on Jan 14, 2025
  27. glozow closed this on Jan 14, 2025

  28. tdb3 commented at 3:11 am on January 15, 2025: contributor

    Post-merge ACK 2ed161c5ce648cb66ec3d2941b02d68b6ca4c390

    Executed functional tests while running Wireshark. Observed no node related traffic with external addresses. Traffic to 0.0.0.1, 0.0.0.2, and 1.2.3.4 was observed on master before this PR was merged (e.g. bb5f76ee013ee439f70e86319d22f308db8a24ea).

  29. manlovepang approved
  30. vasild deleted the branch on Jan 15, 2025
  31. fjahr commented at 7:22 pm on January 15, 2025: contributor
    Post-merge tACK 2ed161c5ce648cb66ec3d2941b02d68b6ca4c390

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: 2025-01-21 03:12 UTC

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