14
14
from test_framework .p2p import p2p_lock , P2PInterface
15
15
from test_framework .script import CScript , OP_TRUE , OP_DROP
16
16
from test_framework .test_framework import BitcoinTestFramework
17
- from test_framework .util import assert_equal , wait_until , softfork_active
17
+ from test_framework .util import assert_equal , softfork_active
18
18
19
19
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
20
20
class TestP2PConn (P2PInterface ):
@@ -73,23 +73,23 @@ def send_header_for_blocks(self, new_blocks):
73
73
def request_headers_and_sync (self , locator , hashstop = 0 ):
74
74
self .clear_block_announcement ()
75
75
self .get_headers (locator , hashstop )
76
- wait_until (self .received_block_announcement , timeout = 30 , lock = p2p_lock )
76
+ self . wait_until (self .received_block_announcement , timeout = 30 )
77
77
self .clear_block_announcement ()
78
78
79
79
# Block until a block announcement for a particular block hash is
80
80
# received.
81
81
def wait_for_block_announcement (self , block_hash , timeout = 30 ):
82
82
def received_hash ():
83
83
return (block_hash in self .announced_blockhashes )
84
- wait_until (received_hash , timeout = timeout , lock = p2p_lock )
84
+ self . wait_until (received_hash , timeout = timeout )
85
85
86
86
def send_await_disconnect (self , message , timeout = 30 ):
87
87
"""Sends a message to the node and wait for disconnect.
88
88
89
89
This is used when we want to send a message into the node that we expect
90
90
will get us disconnected, eg an invalid block."""
91
91
self .send_message (message )
92
- wait_until ( lambda : not self .is_connected , timeout = timeout , lock = p2p_lock )
92
+ self .wait_for_disconnect ( timeout )
93
93
94
94
class CompactBlocksTest (BitcoinTestFramework ):
95
95
def set_test_params (self ):
@@ -154,7 +154,7 @@ def test_sendcmpct(self, test_node, old_node=None):
154
154
# Make sure we get a SENDCMPCT message from our peer
155
155
def received_sendcmpct ():
156
156
return (len (test_node .last_sendcmpct ) > 0 )
157
- wait_until (received_sendcmpct , timeout = 30 , lock = p2p_lock )
157
+ test_node . wait_until (received_sendcmpct , timeout = 30 )
158
158
with p2p_lock :
159
159
# Check that the first version received is the preferred one
160
160
assert_equal (test_node .last_sendcmpct [0 ].version , preferred_version )
@@ -294,7 +294,7 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
294
294
block .rehash ()
295
295
296
296
# Wait until the block was announced (via compact blocks)
297
- wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
297
+ test_node . wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 )
298
298
299
299
# Now fetch and check the compact block
300
300
header_and_shortids = None
@@ -308,7 +308,7 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
308
308
inv = CInv (MSG_CMPCT_BLOCK , block_hash )
309
309
test_node .send_message (msg_getdata ([inv ]))
310
310
311
- wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
311
+ test_node . wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 )
312
312
313
313
# Now fetch and check the compact block
314
314
header_and_shortids = None
@@ -378,7 +378,7 @@ def test_compactblock_requests(self, test_node, segwit=True):
378
378
379
379
if announce == "inv" :
380
380
test_node .send_message (msg_inv ([CInv (MSG_BLOCK , block .sha256 )]))
381
- wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 , lock = p2p_lock )
381
+ test_node . wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 )
382
382
test_node .send_header_for_blocks ([block ])
383
383
else :
384
384
test_node .send_header_for_blocks ([block ])
@@ -588,7 +588,7 @@ def test_getblocktxn_handler(self, test_node):
588
588
num_to_request = random .randint (1 , len (block .vtx ))
589
589
msg .block_txn_request .from_absolute (sorted (random .sample (range (len (block .vtx )), num_to_request )))
590
590
test_node .send_message (msg )
591
- wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 , lock = p2p_lock )
591
+ test_node . wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 )
592
592
593
593
[tx .calc_sha256 () for tx in block .vtx ]
594
594
with p2p_lock :
@@ -628,20 +628,20 @@ def test_compactblocks_not_at_tip(self, test_node):
628
628
for _ in range (MAX_CMPCTBLOCK_DEPTH + 1 ):
629
629
test_node .clear_block_announcement ()
630
630
new_blocks .append (node .generate (1 )[0 ])
631
- wait_until (test_node .received_block_announcement , timeout = 30 , lock = p2p_lock )
631
+ test_node . wait_until (test_node .received_block_announcement , timeout = 30 )
632
632
633
633
test_node .clear_block_announcement ()
634
634
test_node .send_message (msg_getdata ([CInv (MSG_CMPCT_BLOCK , int (new_blocks [0 ], 16 ))]))
635
- wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
635
+ test_node . wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 )
636
636
637
637
test_node .clear_block_announcement ()
638
638
node .generate (1 )
639
- wait_until (test_node .received_block_announcement , timeout = 30 , lock = p2p_lock )
639
+ test_node . wait_until (test_node .received_block_announcement , timeout = 30 )
640
640
test_node .clear_block_announcement ()
641
641
with p2p_lock :
642
642
test_node .last_message .pop ("block" , None )
643
643
test_node .send_message (msg_getdata ([CInv (MSG_CMPCT_BLOCK , int (new_blocks [0 ], 16 ))]))
644
- wait_until (lambda : "block" in test_node .last_message , timeout = 30 , lock = p2p_lock )
644
+ test_node . wait_until (lambda : "block" in test_node .last_message , timeout = 30 )
645
645
with p2p_lock :
646
646
test_node .last_message ["block" ].block .calc_sha256 ()
647
647
assert_equal (test_node .last_message ["block" ].block .sha256 , int (new_blocks [0 ], 16 ))
@@ -689,7 +689,7 @@ def test_end_to_end_block_relay(self, listeners):
689
689
node .submitblock (ToHex (block ))
690
690
691
691
for l in listeners :
692
- wait_until (lambda : "cmpctblock" in l .last_message , timeout = 30 , lock = p2p_lock )
692
+ l . wait_until (lambda : "cmpctblock" in l .last_message , timeout = 30 )
693
693
with p2p_lock :
694
694
for l in listeners :
695
695
l .last_message ["cmpctblock" ].header_and_shortids .header .calc_sha256 ()
0 commit comments