0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-06 14:19:59 -05:00

Merge bitcoin/bitcoin#29352: test: fix intermittent failure in p2p_v2_earlykeyresponse

9642aefb81 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 https://github.com/bitcoin/bitcoin/pull/24748#issuecomment-1916996716.
  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 9642aefb81
  theStack:
    Tested ACK 9642aefb81

Tree-SHA512: f728bbceaf816ddefeee4957494ccb608ad4fc912cb5cbf5f2acf09836df969c4e8fa2bb441aadb94fa39b3ffbb005d4132e7b6a5a98d80811810d8bd1d624e3
This commit is contained in:
Ava Chow 2024-01-31 16:30:12 -05:00
commit 4b66877197
No known key found for this signature in database
GPG key ID: 17565732E08E5E41

View file

@ -49,6 +49,7 @@ class PeerEarlyKey(P2PInterface):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.v2_state = None self.v2_state = None
self.connection_opened = False
def connection_made(self, transport): def connection_made(self, transport):
"""64 bytes ellswift is sent in 2 parts during `initial_v2_handshake()`""" """64 bytes ellswift is sent in 2 parts during `initial_v2_handshake()`"""
@ -59,6 +60,8 @@ class PeerEarlyKey(P2PInterface):
# check that data can be received on recvbuf only when mismatch from V1_PREFIX happens (send_net_magic = False) # check that data can be received on recvbuf only when mismatch from V1_PREFIX happens (send_net_magic = False)
assert self.v2_state.can_data_be_received and not self.v2_state.send_net_magic assert self.v2_state.can_data_be_received and not self.v2_state.send_net_magic
def on_open(self):
self.connection_opened = True
class P2PEarlyKey(BitcoinTestFramework): class P2PEarlyKey(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
@ -73,6 +76,7 @@ class P2PEarlyKey(BitcoinTestFramework):
self.log.info('If a response is received, assertion failure would happen in our custom data_received() function') self.log.info('If a response is received, assertion failure would happen in our custom data_received() function')
# send happens in `initiate_v2_handshake()` in `connection_made()` # send happens in `initiate_v2_handshake()` in `connection_made()`
peer1 = node0.add_p2p_connection(PeerEarlyKey(), wait_for_verack=False, send_version=False, supports_v2_p2p=True) peer1 = node0.add_p2p_connection(PeerEarlyKey(), wait_for_verack=False, send_version=False, supports_v2_p2p=True)
self.wait_until(lambda: peer1.connection_opened)
self.log.info('Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is') self.log.info('Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is')
self.log.info('expected now, our custom data_received() function wouldn\'t result in assertion failure') self.log.info('expected now, our custom data_received() function wouldn\'t result in assertion failure')
ellswift_and_garbage_data = peer1.v2_state.initiate_v2_handshake() ellswift_and_garbage_data = peer1.v2_state.initiate_v2_handshake()