aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-03-17 14:43:06 +0000
committerfanquake <fanquake@gmail.com>2023-03-17 14:55:48 +0000
commit50171df26c719c128dfb9c6a288ca7956562ba8e (patch)
tree7c729b940e6f8f94809ebe0f26735b38c4f23e10 /test
parentdb03248070f39d795b64894c312311df33521427 (diff)
parentfa1eb0ecaef14d428812f956082d29ab134fc728 (diff)
downloadbitcoin-50171df26c719c128dfb9c6a288ca7956562ba8e.tar.xz
Merge bitcoin/bitcoin#27212: test: Make the unlikely race in p2p_invalid_messages impossible
fa1eb0ecaef14d428812f956082d29ab134fc728 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 fa1eb0ecaef14d428812f956082d29ab134fc728 pinheadmz: ACK fa1eb0ecaef14d428812f956082d29ab134fc728 Tree-SHA512: 44166587572e8c0c758cac460fcfd5cf403b2883880128b13dc62e7f74ca5cb8f145bb68a903df177ff0e62faa360f913fd409b009d4cd1360f1f4403ade39ae
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/p2p_invalid_messages.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py
index ea4999a965..644abda914 100755
--- a/test/functional/p2p_invalid_messages.py
+++ b/test/functional/p2p_invalid_messages.py
@@ -80,6 +80,11 @@ class InvalidMessagesTest(BitcoinTestFramework):
def test_buffer(self):
self.log.info("Test message with header split across two buffers is received")
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
+ # 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.
+ conn.sync_with_ping(timeout=1)
# Create valid message
msg = conn.build_message(msg_ping(nonce=12345))
cut_pos = 12 # Chosen at an arbitrary position within the header
@@ -89,8 +94,6 @@ class InvalidMessagesTest(BitcoinTestFramework):
# Wait until node has processed the first half of the message
self.wait_until(lambda: self.nodes[0].getnettotals()['totalbytesrecv'] != before)
middle = self.nodes[0].getnettotals()['totalbytesrecv']
- # If this assert fails, we've hit an unlikely race
- # where the test framework sent a message in between the two halves
assert_equal(middle, before + cut_pos)
conn.send_raw_message(msg[cut_pos:])
conn.sync_with_ping(timeout=1)