Skip to content

Commit 4b66877

Browse files
committed
Merge bitcoin/bitcoin#29352: test: fix intermittent failure in p2p_v2_earlykeyresponse
9642aef test: fix intermittent failure in p2p_v2_earlykeyresponse (Martin Zumsande) Pull request description: The test fails intermittently, see https://cirrus-ci.com/task/6403578080788480?logs=ci#L3521 and bitcoin/bitcoin#24748 (comment). I think it's because of a race between the python NetworkThread and the actual test, which will both call `initiate_v2_handshake`. I could reproduce it by adding a sleep into `initiate_v2_handshake` after the line `self.sent_garbage = random.randbytes(garbage_len)`. Fix this by waiting for the first `initiate_v2_handshake` to have finished before calling it a second time. ACKs for top commit: stratospher: tested ACK 9642aef. achow101: ACK 9642aef theStack: Tested ACK 9642aef Tree-SHA512: f728bbceaf816ddefeee4957494ccb608ad4fc912cb5cbf5f2acf09836df969c4e8fa2bb441aadb94fa39b3ffbb005d4132e7b6a5a98d80811810d8bd1d624e3
2 parents 6f7395b + 9642aef commit 4b66877

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/functional/p2p_v2_earlykeyresponse.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PeerEarlyKey(P2PInterface):
4949
def __init__(self):
5050
super().__init__()
5151
self.v2_state = None
52+
self.connection_opened = False
5253

5354
def connection_made(self, transport):
5455
"""64 bytes ellswift is sent in 2 parts during `initial_v2_handshake()`"""
@@ -59,6 +60,8 @@ def data_received(self, t):
5960
# check that data can be received on recvbuf only when mismatch from V1_PREFIX happens (send_net_magic = False)
6061
assert self.v2_state.can_data_be_received and not self.v2_state.send_net_magic
6162

63+
def on_open(self):
64+
self.connection_opened = True
6265

6366
class P2PEarlyKey(BitcoinTestFramework):
6467
def set_test_params(self):
@@ -73,6 +76,7 @@ def run_test(self):
7376
self.log.info('If a response is received, assertion failure would happen in our custom data_received() function')
7477
# send happens in `initiate_v2_handshake()` in `connection_made()`
7578
peer1 = node0.add_p2p_connection(PeerEarlyKey(), wait_for_verack=False, send_version=False, supports_v2_p2p=True)
79+
self.wait_until(lambda: peer1.connection_opened)
7680
self.log.info('Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is')
7781
self.log.info('expected now, our custom data_received() function wouldn\'t result in assertion failure')
7882
ellswift_and_garbage_data = peer1.v2_state.initiate_v2_handshake()

0 commit comments

Comments
 (0)