You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge bitcoin/bitcoin#29353: test: p2p: adhere to typical VERSION message protocol flow
c340503 test: p2p: adhere to typical VERSION message protocol flow (Sebastian Falbesoner)
7ddfc28 test: p2p: process post-v2-handshake data immediately (Sebastian Falbesoner)
b198b9c test: p2p: introduce helper for sending prepared VERSION message (Sebastian Falbesoner)
Pull request description:
This PR addresses a quirk in the test framework's p2p implementation regarding the version handshake protocol:
Currently, the VERSION message is sent immediately after an inbound connection (i.e. TestNode outbound connection) is made. This doesn't follow the usual protocol flow where the initiator sends a version first, the responder processes that and only then responds with its own version message. Change that accordingly by only sending immediate VERSION message for outbound connections (or after v2 handshake for v2 connections, respectively), and sending out VERSION message as response for incoming VERSION messages (i.e. in the function `on_version`) for inbound connections.
I first stumbled upon this issue through reading comment https://mirror.b10c.me/bitcoin-bitcoin/24748/#discussion_r1465420112 (see last paragraph) and recently again in the course of working on a v2-followup for #29279, where this causes issues for TestNode outbound connections that disconnect *before* sending out their own version message.
Note that these changes lead to slightly more code in some functional tests that override the `on_version` method, as the version reply has to be sent explicitly now, but I think is less confusing and reflects better what is actually happening.
ACKs for top commit:
epiccurious:
utACK c340503
stratospher:
tested ACK c340503. very useful to have since we'd want real node behaviour!
mzumsande:
ACK c340503
sr-gi:
tACK bitcoin/bitcoin@c340503
Tree-SHA512: 63eac287d3e1c87a01852bfd9f0530363354bbb642280298673b9c8817056356373adf348955c4e92af95c7c6efa8cc515cee2892e9f077bfbe1bce8e97ad082
assertmessage.nVersion>=MIN_P2P_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_P2P_VERSION_SUPPORTED)
560
-
# reconnection using v1 P2P has happened since version message can be processed, previously unsent version message is sent using v1 P2P here
561
-
ifself.reconnect:
562
-
ifself.on_connection_send_msg:
563
-
self.send_message(self.on_connection_send_msg)
564
-
self.on_connection_send_msg=None
563
+
# for inbound connections, reply to version with own version message
564
+
# (could be due to v1 reconnect after a failed v2 handshake)
565
+
ifnotself.p2p_connected_to_node:
566
+
self.send_version()
565
567
self.reconnect=False
566
568
ifmessage.nVersion>=70016andself.wtxidrelay:
567
569
self.send_message(msg_wtxidrelay())
@@ -676,6 +678,11 @@ def test_function():
676
678
677
679
# Message sending helper functions
678
680
681
+
defsend_version(self):
682
+
ifself.on_connection_send_msg:
683
+
self.send_message(self.on_connection_send_msg)
684
+
self.on_connection_send_msg=None# Never used again
0 commit comments