8000 test: p2p: adhere to typical VERSION message protocol flow by theStack · Pull Request #29353 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: p2p: adhere to typical VERSION message protocol flow #29353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/functional/p2p_add_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def on_version(self, message):
# message is received from the test framework. Don't send any responses
# to the node's version message since the connection will already be
# closed.
pass
self.send_version()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really just calling super().send_version. We could get rid of the whole class given no other method is being overwritten (or leave the alias if we want it for readability, but get rid of the method)


class P2PAddConnections(BitcoinTestFramework):
def set_test_params(self):
Expand Down
1 change: 1 addition & 0 deletions test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def addr_received(self):
return self.num_ipv4_received != 0

def on_version(self, message):
self.send_version()
self.send_message(msg_verack())
if (self.send_getaddr):
self.send_message(msg_getaddr())
Expand Down
4 changes: 3 additions & 1 deletion test/functional/p2p_sendtxrcncl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def on_version(self, message):
# Avoid sending verack in response to version.
# When calling add_p2p_connection, wait_for_verack=False must be set (see
# comment in add_p2p_connection).
self.send_version()
if message.nVersion >= 70016 and self.wtxidrelay:
self.send_message(msg_wtxidrelay())

Expand All @@ -43,7 +44,8 @@ def on_sendtxrcncl(self, message):

class P2PFeelerReceiver(SendTxrcnclReceiver):
def on_version(self, message):
pass # feeler connections can not send any message other than their own version
# feeler connections can not send any message other than their own version
self.send_version()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for p2p_add_connections::P2PFeelerReceiver



class PeerTrackMsgOrder(P2PInterface):
Expand Down
33 changes: 20 additions & 13 deletions test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,10 @@ def connection_made(self, transport):
if self.supports_v2_p2p and self.v2_state.initiating and not self.v2_state.tried_v2_handshake:
send_handshake_bytes = self.v2_state.initiate_v2_handshake()
self.send_raw_message(send_handshake_bytes)
# if v2 connection, send `on_connection_send_msg` after initial v2 handshake.
# if reconnection situation, send `on_connection_send_msg` after version message is received in `on_version()`.
if self.on_connection_send_msg and not self.supports_v2_p2p and not self.reconnect:
self.send_message(self.on_connection_send_msg)
self.on_connection_send_msg = None # Never used again
# for v1 outbound connections, send version message immediately after opening
# (for v2 outbound connections, send it after the initial v2 handshake)
if self.p2p_connected_to_node and not self.supports_v2_p2p:
self.send_version()
self.on_open()

def connection_lost(self, exc):
Expand Down Expand Up @@ -284,9 +283,13 @@ def v2_handshake(self):
if not is_mac_auth:
raise ValueError("invalid v2 mac tag in handshake authentication")
self.recvbuf = self.recvbuf[length:]
if self.v2_state.tried_v2_handshake and self.on_connection_send_msg:
self.send_message(self.on_connection_send_msg)
self.on_connection_send_msg = None
if self.v2_state.tried_v2_handshake:
# for v2 outbound connections, send version message immediately after v2 handshake
if self.p2p_connected_to_node:
self.send_version()
# process post-v2-handshake data immediately, if available
if len(self.recvbuf) > 0:
self._on_data()

# Socket read methods

Expand Down Expand Up @@ -557,11 +560,10 @@ def on_verack(self, message):

def on_version(self, message):
assert message.nVersion >= MIN_P2P_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_P2P_VERSION_SUPPORTED)
# reconnection using v1 P2P has happened since version message can be processed, previously unsent version message is sent using v1 P2P here
if self.reconnect:
if self.on_connection_send_msg:
self.send_message(self.on_connection_send_msg)
self.on_connection_send_msg = None
# for inbound connections, reply to version with own version message
# (could be due to v1 reconnect after a failed v2 handshake)
if not self.p2p_connected_to_node:
self.send_version()
self.reconnect = False
if message.nVersion >= 70016 and self.wtxidrelay:
self.send_message(msg_wtxidrelay())
Expand Down Expand Up @@ -676,6 +678,11 @@ def test_function():

# Message sending helper functions

def send_version(self):
if self.on_connection_send_msg:
self.send_message(self.on_connection_send_msg)
self.on_connection_send_msg = None # Never used again

def send_and_ping(self, message, timeout=60):
self.send_message(message)
self.sync_with_ping(timeout=timeout)
Expand Down
0