@@ -70,27 +70,23 @@ def send_header_for_blocks(self, new_blocks):
70
70
def request_headers_and_sync (self , locator , hashstop = 0 ):
71
71
self .clear_block_announcement ()
72
72
self .get_headers (locator , hashstop )
73
- assert wait_until (self .received_block_announcement , timeout = 30 )
73
+ wait_until (self .received_block_announcement , timeout = 30 , lock = mininode_lock )
74
74
self .clear_block_announcement ()
75
75
76
76
# Block until a block announcement for a particular block hash is
77
77
# received.
78
78
def wait_for_block_announcement (self , block_hash , timeout = 30 ):
79
79
def received_hash ():
80
80
return (block_hash in self .announced_blockhashes )
81
- return wait_until (received_hash , timeout = timeout )
81
+ wait_until (received_hash , timeout = timeout , lock = mininode_lock )
82
82
83
83
def send_await_disconnect (self , message , timeout = 30 ):
84
84
"""Sends a message to the node and wait for disconnect.
85
85
86
86
This is used when we want to send a message into the node that we expect
87
87
will get us disconnected, eg an invalid block."""
88
88
self .send_message (message )
89
- success = wait_until (lambda : not self .connected , timeout = timeout )
90
- if not success :
91
- logger .error ("send_await_disconnect failed!" )
92
- raise AssertionError ("send_await_disconnect failed!" )
93
- return success
89
+ wait_until (lambda : not self .connected , timeout = timeout , lock = mininode_lock )
94
90
95
91
class CompactBlocksTest (BitcoinTestFramework ):
96
92
def __init__ (self ):
@@ -150,9 +146,7 @@ def test_sendcmpct(self, node, test_node, preferred_version, old_node=None):
150
146
# Make sure we get a SENDCMPCT message from our peer
151
147
def received_sendcmpct ():
152
148
return (len (test_node .last_sendcmpct ) > 0 )
153
- got_message = wait_until (received_sendcmpct , timeout = 30 )
154
- assert (received_sendcmpct ())
155
- assert (got_message )
149
+ wait_until (received_sendcmpct , timeout = 30 , lock = mininode_lock )
156
150
with mininode_lock :
157
151
# Check that the first version received is the preferred one
158
152
assert_equal (test_node .last_sendcmpct [0 ].version , preferred_version )
@@ -167,7 +161,6 @@ def check_announcement_of_new_block(node, peer, predicate):
167
161
block_hash = int (node .generate (1 )[0 ], 16 )
168
162
peer .wait_for_block_announcement (block_hash , timeout = 30 )
169
163
assert (peer .block_announced )
170
- assert (got_message )
171
164
172
165
with mininode_lock :
173
166
assert predicate (peer ), (
@@ -282,7 +275,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
282
275
283
276
# Wait until we've seen the block announcement for the resulting tip
284
277
tip = int (node .getbestblockhash (), 16 )
285
- assert ( test_node .wait_for_block_announcement (tip ) )
278
+ test_node .wait_for_block_announcement (tip )
286
279
287
280
# Make sure we will receive a fast-announce compact block
288
281
self .request_cb_announcements (test_node , node , version )
@@ -297,8 +290,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
297
290
block .rehash ()
298
291
299
292
# Wait until the block was announced (via compact blocks)
300
- wait_until (test_node .received_block_announcement , timeout = 30 )
301
- assert (test_node .received_block_announcement ())
293
+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
302
294
303
295
# Now fetch and check the compact block
304
296
header_and_shortids = None
@@ -314,8 +306,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
314
306
inv = CInv (4 , block_hash ) # 4 == "CompactBlock"
315
307
test_node .send_message (msg_getdata ([inv ]))
316
308
317
- wait_until (test_node .received_block_announcement , timeout = 30 )
318
- assert (test_node .received_block_announcement ())
309
+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
319
310
320
311
# Now fetch and check the compact block
321
312
header_and_shortids = None
@@ -386,13 +377,11 @@ def test_compactblock_requests(self, node, test_node, version, segwit):
386
377
387
378
if announce == "inv" :
388
379
test_node .send_message (msg_inv ([CInv (2 , block .sha256 )]))
389
- success = wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 )
390
- assert (success )
380
+ wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 , lock = mininode_lock )
391
381
test_node .send_header_for_blocks ([block ])
392
382
else :
393
383
test_node .send_header_for_blocks ([block ])
394
- success = wait_until (lambda : "getdata" in test_node .last_message , timeout = 30 )
395
- assert (success )
384
+ wait_until (lambda : "getdata" in test_node .last_message , timeout = 30 , lock = mininode_lock )
396
385
assert_equal (len (test_node .last_message ["getdata" ].inv ), 1 )
397
386
assert_equal (test_node .last_message ["getdata" ].inv [0 ].type , 4 )
398
387
assert_equal (test_node .last_message ["getdata" ].inv [0 ].hash , block .sha256 )
@@ -571,8 +560,7 @@ def test_incorrect_blocktxn_response(self, node, test_node, version):
571
560
assert_equal (int (node .getbestblockhash (), 16 ), block .hashPrevBlock )
572
561
573
562
# We should receive a getdata request
574
- success = wait_until (lambda : "getdata" in test_node .last_message , timeout = 10 )
575
- assert (success )
563
+ wait_until (lambda : "getdata" in test_node .last_message , timeout = 10 , lock = mininode_lock )
576
564
assert_equal (len (test_node .last_message ["getdata" ].inv ), 1 )
577
565
assert (test_node .last_message ["getdata" ].inv [0 ].type == 2 or test_node .last_message ["getdata" ].inv [0 ].type == 2 | MSG_WITNESS_FLAG )
578
566
assert_equal (test_node .last_message ["getdata" ].inv [0 ].hash , block .sha256 )
@@ -599,8 +587,7 @@ def test_getblocktxn_handler(self, node, test_node, version):
599
587
num_to_request = random .randint (1 , len (block .vtx ))
600
588
msg .block_txn_request .from_absolute (sorted (random .sample (range (len (block .vtx )), num_to_request )))
601
589
test_node .send_message (msg )
602
- success = wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 )
603
- assert (success )
590
+ wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 , lock = mininode_lock )
604
591
605
592
[tx .calc_sha256 () for tx in block .vtx ]
606
593
with mininode_lock :
@@ -639,22 +626,20 @@ def test_compactblocks_not_at_tip(self, node, test_node):
639
626
for i in range (MAX_CMPCTBLOCK_DEPTH + 1 ):
640
627
test_node .clear_block_announcement ()
641
628
new_blocks .append (node .generate (1 )[0 ])
642
- wait_until (test_node .received_block_announcement , timeout = 30 )
629
+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
643
630
644
631
test_node .clear_block_announcement ()
645
632
test_node .send_message (msg_getdata ([CInv (4 , int (new_blocks [0 ], 16 ))]))
646
- success = wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 )
647
- assert (success )
633
+ wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = mininode_lock )
648
634
649
635
test_node .clear_block_announcement ()
650
636
node .generate (1 )
651
- wait_until (test_node .received_block_announcement , timeout = 30 )
637
+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
652
638
test_node .clear_block_announcement ()
653
639
with mininode_lock :
654
640
test_node .last_message .pop ("block" , None )
655
641
test_node .send_message (msg_getdata ([CInv (4 , int (new_blocks [0 ], 16 ))]))
656
- success = wait_until (lambda : "block" in test_node .last_message , timeout = 30 )
657
- assert (success )
642
+ wait_until (lambda : "block" in test_node .last_message , timeout = 30 , lock = mininode_lock )
658
643
with mininode_lock :
659
644
test_node .last_message ["block" ].block .calc_sha256 ()
660
645
assert_equal (test_node .last_message ["block" ].block .sha256 , int (new_blocks [0 ], 16 ))
@@ -705,7 +690,7 @@ def test_end_to_end_block_relay(self, node, listeners):
705
690
node .submitblock (ToHex (block ))
706
691
707
692
for l in listeners :
708
- wait_until (lambda : l .received_block_announcement (), timeout = 30 )
693
+ wait_until (lambda : l .received_block_announcement (), timeout = 30 , lock = mininode_lock )
709
694
with mininode_lock :
710
695
for l in listeners :
711
696
assert "cmpctblock" in l .last_message
0 commit comments