test: p2p: check that connecting to ourself leads to disconnect #30362

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202406-test-add_check_for_self_connect changing 1 files +7 −0
  1. theStack commented at 10:42 pm on June 28, 2024: contributor

    This small PR adds test coverage for the scenario of connecting to ourself, leading to an immediate disconnect: https://github.com/bitcoin/bitcoin/blob/2f6dca4d1c01ee47275a4292f128d714736837a1/src/net_processing.cpp#L3729-L3735

    This logic has been first introduced by Satoshi in October 2009, together with a couple of other changes and a version bump to “v0.1.6 BETA” (see commit cc0b4c3b62367a2aebe5fc1f4d0ed4b97e9c2ac9).

  2. test: p2p: check that connecting to ourself leads to disconnect
    The "connect to ourself" detection logic has been first introduced
    by Satoshi in October 2009, together with a couple of other changes
    and a version bump to "v0.1.6 BETA" (see commit
    cc0b4c3b62367a2aebe5fc1f4d0ed4b97e9c2ac9).
    5d2fb14baf
  3. DrahtBot commented at 10:42 pm on June 28, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK fjahr, kevkevinpal, tdb3, maflcko

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

  4. DrahtBot added the label Tests on Jun 28, 2024
  5. in test/functional/p2p_handshake.py:94 in 5d2fb14baf
    88@@ -88,6 +89,12 @@ def run_test(self):
    89         with node.assert_debug_log([f"feeler connection completed"]):
    90             self.add_outbound_connection(node, "feeler", NODE_NONE, wait_for_disconnect=True)
    91 
    92+        self.log.info("Check that connecting to ourself leads to immediate disconnect")
    93+        with node.assert_debug_log(["connected to self", "disconnecting"]):
    94+            node_listen_addr = f"127.0.0.1:{p2p_port(0)}"
    


    fjahr commented at 10:49 pm on June 28, 2024:
    nit: Could pull this up two lines and use it to check the exact log line I think, but not a blocker for me

    theStack commented at 0:09 am on June 29, 2024:
    Tried that initially, but the log line shows not the destination, but the source address of the connection, which contains an ephemeral port (i.e. randomly assigned by the OS) and hence can’t be predicted.
  6. fjahr commented at 10:54 pm on June 28, 2024: contributor

    tACK 5d2fb14bafe4e80c0a482d99e5ebde07c477f000

    Nice find!

  7. kevkevinpal commented at 3:56 am on June 29, 2024: contributor

    tACK 5d2fb14

    looks good to me and I ran it locally on my machine and looks to work well

  8. in test/functional/p2p_handshake.py:95 in 5d2fb14baf
    88@@ -88,6 +89,12 @@ def run_test(self):
    89         with node.assert_debug_log([f"feeler connection completed"]):
    90             self.add_outbound_connection(node, "feeler", NODE_NONE, wait_for_disconnect=True)
    91 
    92+        self.log.info("Check that connecting to ourself leads to immediate disconnect")
    93+        with node.assert_debug_log(["connected to self", "disconnecting"]):
    94+            node_listen_addr = f"127.0.0.1:{p2p_port(0)}"
    95+            node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
    


    tdb3 commented at 2:15 pm on June 29, 2024:
    I like how this is using self.options.v2transport as the argument, enabling the script list in test_runner to specify whether or not v2transport should be used for the test.
  9. tdb3 approved
  10. tdb3 commented at 2:26 pm on June 29, 2024: contributor

    ACK 5d2fb14bafe4e80c0a482d99e5ebde07c477f000 Good addition. Tested locally with the following:

    1. Running the p2p_handshake test variants with test_runner (passed)
    2. Running a purposefully separate node (src/bitcoind -regtest -bind=127.0.0.1:1234), and modifying p2p_handshake to run the test against it (node_listen_addr = f"127.0.0.1:{1234}"). Test failed as expected (expected messages weren’t found).
    3. Stopping the node at 1234 and running the modified test. Test failed as expected (connection refused).
  11. maflcko commented at 6:19 am on July 1, 2024: member
    ACK 5d2fb14bafe4e80c0a482d99e5ebde07c477f000
  12. fanquake merged this on Jul 1, 2024
  13. fanquake closed this on Jul 1, 2024

  14. theStack deleted the branch on Jul 1, 2024
  15. vasild commented at 3:57 pm on July 1, 2024: contributor
    So this tiny new test revealed a race and a bug in the existent code, excellent! :heart:

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: 2024-09-19 01:12 UTC

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