Skip to content

Commit 50171df

Browse files
committed
Merge bitcoin/bitcoin#27212: test: Make the unlikely race in p2p_invalid_messages impossible
fa1eb0e test: Make the unlikely race in p2p_invalid_messages impossible (MarcoFalke) Pull request description: After `add_p2p_connection` both sides have the verack processed. However the pong from conn in reply to the ping from the node has not been processed and recorded in totalbytesrecv. Flush the pong from conn by sending a ping from conn. This should make the unlikely race impossible. ACKs for top commit: mzumsande: ACK fa1eb0e pinheadmz: ACK fa1eb0e Tree-SHA512: 44166587572e8c0c758cac460fcfd5cf403b2883880128b13dc62e7f74ca5cb8f145bb68a903df177ff0e62faa360f913fd409b009d4cd1360f1f4403ade39ae
2 parents db03248 + fa1eb0e commit 50171df

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def run_test(self):
8080
def test_buffer(self):
8181
self.log.info("Test message with header split across two buffers is received")
8282
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
83+
# After add_p2p_connection both sides have the verack processed.
84+
# However the pong from conn in reply to the ping from the node has not
85+
# been processed and recorded in totalbytesrecv.
86+
# Flush the pong from conn by sending a ping from conn.
87+
conn.sync_with_ping(timeout=1)
8388
# Create valid message
8489
msg = conn.build_message(msg_ping(nonce=12345))
8590
cut_pos = 12 # Chosen at an arbitrary position within the header
@@ -89,8 +94,6 @@ def test_buffer(self):
8994
# Wait until node has processed the first half of the message
9095
self.wait_until(lambda: self.nodes[0].getnettotals()['totalbytesrecv'] != before)
9196
middle = self.nodes[0].getnettotals()['totalbytesrecv']
92-
# If this assert fails, we've hit an unlikely race
93-
# where the test framework sent a message in between the two halves
9497
assert_equal(middle, before + cut_pos)
9598
conn.send_raw_message(msg[cut_pos:])
9699
conn.sync_with_ping(timeout=1)

0 commit comments

Comments
 (0)