@@ -70,27 +70,23 @@ def send_header_for_blocks(self, new_blocks):
7070 def request_headers_and_sync (self , locator , hashstop = 0 ):
7171 self .clear_block_announcement ()
7272 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 )
7474 self .clear_block_announcement ()
7575
7676 # Block until a block announcement for a particular block hash is
7777 # received.
7878 def wait_for_block_announcement (self , block_hash , timeout = 30 ):
7979 def received_hash ():
8080 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 )
8282
8383 def send_await_disconnect (self , message , timeout = 30 ):
8484 """Sends a message to the node and wait for disconnect.
8585
8686 This is used when we want to send a message into the node that we expect
8787 will get us disconnected, eg an invalid block."""
8888 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 )
9490
9591class CompactBlocksTest (BitcoinTestFramework ):
9692 def __init__ (self ):
@@ -150,9 +146,7 @@ def test_sendcmpct(self, node, test_node, preferred_version, old_node=None):
150146 # Make sure we get a SENDCMPCT message from our peer
151147 def received_sendcmpct ():
152148 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 )
156150 with mininode_lock :
157151 # Check that the first version received is the preferred one
158152 assert_equal (test_node .last_sendcmpct [0 ].version , preferred_version )
@@ -167,7 +161,6 @@ def check_announcement_of_new_block(node, peer, predicate):
167161 block_hash = int (node .generate (1 )[0 ], 16 )
168162 peer .wait_for_block_announcement (block_hash , timeout = 30 )
169163 assert (peer .block_announced )
170- assert (got_message )
171164
172165 with mininode_lock :
173166 assert predicate (peer ), (
@@ -282,7 +275,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
282275
283276 # Wait until we've seen the block announcement for the resulting tip
284277 tip = int (node .getbestblockhash (), 16 )
285- assert ( test_node .wait_for_block_announcement (tip ) )
278+ test_node .wait_for_block_announcement (tip )
286279
287280 # Make sure we will receive a fast-announce compact block
288281 self .request_cb_announcements (test_node , node , version )
@@ -297,8 +290,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
297290 block .rehash ()
298291
299292 # 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 )
302294
303295 # Now fetch and check the compact block
304296 header_and_shortids = None
@@ -314,8 +306,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
314306 inv = CInv (4 , block_hash ) # 4 == "CompactBlock"
315307 test_node .send_message (msg_getdata ([inv ]))
316308
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 )
319310
320311 # Now fetch and check the compact block
321312 header_and_shortids = None
@@ -386,13 +377,11 @@ def test_compactblock_requests(self, node, test_node, version, segwit):
386377
387378 if announce == "inv" :
388379 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 )
391381 test_node .send_header_for_blocks ([block ])
392382 else :
393383 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 )
396385 assert_equal (len (test_node .last_message ["getdata" ].inv ), 1 )
397386 assert_equal (test_node .last_message ["getdata" ].inv [0 ].type , 4 )
398387 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):
571560 assert_equal (int (node .getbestblockhash (), 16 ), block .hashPrevBlock )
572561
573562 # 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 )
576564 assert_equal (len (test_node .last_message ["getdata" ].inv ), 1 )
577565 assert (test_node .last_message ["getdata" ].inv [0 ].type == 2 or test_node .last_message ["getdata" ].inv [0 ].type == 2 | MSG_WITNESS_FLAG )
578566 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):
599587 num_to_request = random .randint (1 , len (block .vtx ))
600588 msg .block_txn_request .from_absolute (sorted (random .sample (range (len (block .vtx )), num_to_request )))
601589 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 )
604591
605592 [tx .calc_sha256 () for tx in block .vtx ]
606593 with mininode_lock :
@@ -639,22 +626,20 @@ def test_compactblocks_not_at_tip(self, node, test_node):
639626 for i in range (MAX_CMPCTBLOCK_DEPTH + 1 ):
640627 test_node .clear_block_announcement ()
641628 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 )
643630
644631 test_node .clear_block_announcement ()
645632 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 )
648634
649635 test_node .clear_block_announcement ()
650636 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 )
652638 test_node .clear_block_announcement ()
653639 with mininode_lock :
654640 test_node .last_message .pop ("block" , None )
655641 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 )
658643 with mininode_lock :
659644 test_node .last_message ["block" ].block .calc_sha256 ()
660645 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):
705690 node .submitblock (ToHex (block ))
706691
707692 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 )
709694 with mininode_lock :
710695 for l in listeners :
711696 assert "cmpctblock" in l .last_message
0 commit comments