1111
1212from test_framework .blocktools import create_block , create_coinbase , add_witness_commitment
1313from test_framework .messages import BlockTransactions , BlockTransactionsRequest , calculate_shortid , CBlock , CBlockHeader , CInv , COutPoint , CTransaction , CTxIn , CTxInWitness , CTxOut , FromHex , HeaderAndShortIDs , msg_no_witness_block , msg_no_witness_blocktxn , msg_cmpctblock , msg_getblocktxn , msg_getdata , msg_getheaders , msg_headers , msg_inv , msg_sendcmpct , msg_sendheaders , msg_tx , msg_block , msg_blocktxn , MSG_BLOCK , MSG_CMPCT_BLOCK , MSG_WITNESS_FLAG , NODE_NETWORK , P2PHeaderAndShortIDs , PrefilledTransaction , ser_uint256 , ToHex
14- from test_framework .mininode import mininode_lock , P2PInterface
14+ from test_framework .mininode import p2p_lock , P2PInterface
1515from test_framework .script import CScript , OP_TRUE , OP_DROP
1616from test_framework .test_framework import BitcoinTestFramework
1717from test_framework .util import assert_equal , wait_until , softfork_active
@@ -48,12 +48,12 @@ def on_inv(self, message):
4848 self .block_announced = True
4949 self .announced_blockhashes .add (x .hash )
5050
51- # Requires caller to hold mininode_lock
51+ # Requires caller to hold p2p_lock
5252 def received_block_announcement (self ):
5353 return self .block_announced
5454
5555 def clear_block_announcement (self ):
56- with mininode_lock :
56+ with p2p_lock :
5757 self .block_announced = False
5858 self .last_message .pop ("inv" , None )
5959 self .last_message .pop ("headers" , None )
@@ -73,23 +73,23 @@ def send_header_for_blocks(self, new_blocks):
7373 def request_headers_and_sync (self , locator , hashstop = 0 ):
7474 self .clear_block_announcement ()
7575 self .get_headers (locator , hashstop )
76- wait_until (self .received_block_announcement , timeout = 30 , lock = mininode_lock )
76+ wait_until (self .received_block_announcement , timeout = 30 , lock = p2p_lock )
7777 self .clear_block_announcement ()
7878
7979 # Block until a block announcement for a particular block hash is
8080 # received.
8181 def wait_for_block_announcement (self , block_hash , timeout = 30 ):
8282 def received_hash ():
8383 return (block_hash in self .announced_blockhashes )
84- wait_until (received_hash , timeout = timeout , lock = mininode_lock )
84+ wait_until (received_hash , timeout = timeout , lock = p2p_lock )
8585
8686 def send_await_disconnect (self , message , timeout = 30 ):
8787 """Sends a message to the node and wait for disconnect.
8888
8989 This is used when we want to send a message into the node that we expect
9090 will get us disconnected, eg an invalid block."""
9191 self .send_message (message )
92- wait_until (lambda : not self .is_connected , timeout = timeout , lock = mininode_lock )
92+ wait_until (lambda : not self .is_connected , timeout = timeout , lock = p2p_lock )
9393
9494class CompactBlocksTest (BitcoinTestFramework ):
9595 def set_test_params (self ):
@@ -154,8 +154,8 @@ def test_sendcmpct(self, test_node, old_node=None):
154154 # Make sure we get a SENDCMPCT message from our peer
155155 def received_sendcmpct ():
156156 return (len (test_node .last_sendcmpct ) > 0 )
157- wait_until (received_sendcmpct , timeout = 30 , lock = mininode_lock )
158- with mininode_lock :
157+ wait_until (received_sendcmpct , timeout = 30 , lock = p2p_lock )
158+ with p2p_lock :
159159 # Check that the first version received is the preferred one
160160 assert_equal (test_node .last_sendcmpct [0 ].version , preferred_version )
161161 # And that we receive versions down to 1.
@@ -170,7 +170,7 @@ def check_announcement_of_new_block(node, peer, predicate):
170170 peer .wait_for_block_announcement (block_hash , timeout = 30 )
171171 assert peer .block_announced
172172
173- with mininode_lock :
173+ with p2p_lock :
174174 assert predicate (peer ), (
175175 "block_hash={!r}, cmpctblock={!r}, inv={!r}" .format (
176176 block_hash , peer .last_message .get ("cmpctblock" , None ), peer .last_message .get ("inv" , None )))
@@ -294,11 +294,11 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
294294 block .rehash ()
295295
296296 # Wait until the block was announced (via compact blocks)
297- wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = mininode_lock )
297+ wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
298298
299299 # Now fetch and check the compact block
300300 header_and_shortids = None
301- with mininode_lock :
301+ with p2p_lock :
302302 # Convert the on-the-wire representation to absolute indexes
303303 header_and_shortids = HeaderAndShortIDs (test_node .last_message ["cmpctblock" ].header_and_shortids )
304304 self .check_compactblock_construction_from_block (version , header_and_shortids , block_hash , block )
@@ -308,11 +308,11 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
308308 inv = CInv (MSG_CMPCT_BLOCK , block_hash )
309309 test_node .send_message (msg_getdata ([inv ]))
310310
311- wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = mininode_lock )
311+ wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
312312
313313 # Now fetch and check the compact block
314314 header_and_shortids = None
315- with mininode_lock :
315+ with p2p_lock :
316316 # Convert the on-the-wire representation to absolute indexes
317317 header_and_shortids = HeaderAndShortIDs (test_node .last_message ["cmpctblock" ].header_and_shortids )
318318 self .check_compactblock_construction_from_block (version , header_and_shortids , block_hash , block )
@@ -378,7 +378,7 @@ def test_compactblock_requests(self, test_node, segwit=True):
378378
379379 if announce == "inv" :
380380 test_node .send_message (msg_inv ([CInv (MSG_BLOCK , block .sha256 )]))
381- wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 , lock = mininode_lock )
381+ wait_until (lambda : "getheaders" in test_node .last_message , timeout = 30 , lock = p2p_lock )
382382 test_node .send_header_for_blocks ([block ])
383383 else :
384384 test_node .send_header_for_blocks ([block ])
@@ -397,7 +397,7 @@ def test_compactblock_requests(self, test_node, segwit=True):
397397 test_node .send_and_ping (msg_cmpctblock (comp_block .to_p2p ()))
398398 assert_equal (int (node .getbestblockhash (), 16 ), block .hashPrevBlock )
399399 # Expect a getblocktxn message.
400- with mininode_lock :
400+ with p2p_lock :
401401 assert "getblocktxn" in test_node .last_message
402402 absolute_indexes = test_node .last_message ["getblocktxn" ].block_txn_request .to_absolute ()
403403 assert_equal (absolute_indexes , [0 ]) # should be a coinbase request
@@ -439,7 +439,7 @@ def test_getblocktxn_requests(self, test_node):
439439 def test_getblocktxn_response (compact_block , peer , expected_result ):
440440 msg = msg_cmpctblock (compact_block .to_p2p ())
441441 peer .send_and_ping (msg )
442- with mininode_lock :
442+ with p2p_lock :
443443 assert "getblocktxn" in peer .last_message
444444 absolute_indexes = peer .last_message ["getblocktxn" ].block_txn_request .to_absolute ()
445445 assert_equal (absolute_indexes , expected_result )
@@ -504,13 +504,13 @@ def test_tip_after_message(node, peer, msg, tip):
504504 assert tx .hash in mempool
505505
506506 # Clear out last request.
507- with mininode_lock :
507+ with p2p_lock :
508508 test_node .last_message .pop ("getblocktxn" , None )
509509
510510 # Send compact block
511511 comp_block .initialize_from_block (block , prefill_list = [0 ], use_witness = with_witness )
512512 test_tip_after_message (node , test_node , msg_cmpctblock (comp_block .to_p2p ()), block .sha256 )
513- with mininode_lock :
513+ with p2p_lock :
514514 # Shouldn't have gotten a request for any transaction
515515 assert "getblocktxn" not in test_node .last_message
516516
@@ -537,7 +537,7 @@ def test_incorrect_blocktxn_response(self, test_node):
537537 comp_block .initialize_from_block (block , prefill_list = [0 ], use_witness = (version == 2 ))
538538 test_node .send_and_ping (msg_cmpctblock (comp_block .to_p2p ()))
539539 absolute_indexes = []
540- with mininode_lock :
540+ with p2p_lock :
541541 assert "getblocktxn" in test_node .last_message
542542 absolute_indexes = test_node .last_message ["getblocktxn" ].block_txn_request .to_absolute ()
543543 assert_equal (absolute_indexes , [6 , 7 , 8 , 9 , 10 ])
@@ -588,10 +588,10 @@ def test_getblocktxn_handler(self, test_node):
588588 num_to_request = random .randint (1 , len (block .vtx ))
589589 msg .block_txn_request .from_absolute (sorted (random .sample (range (len (block .vtx )), num_to_request )))
590590 test_node .send_message (msg )
591- wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 , lock = mininode_lock )
591+ wait_until (lambda : "blocktxn" in test_node .last_message , timeout = 10 , lock = p2p_lock )
592592
593593 [tx .calc_sha256 () for tx in block .vtx ]
594- with mininode_lock :
594+ with p2p_lock :
595595 assert_equal (test_node .last_message ["blocktxn" ].block_transactions .blockhash , int (block_hash , 16 ))
596596 all_indices = msg .block_txn_request .to_absolute ()
597597 for index in all_indices :
@@ -611,11 +611,11 @@ def test_getblocktxn_handler(self, test_node):
611611 # allowed depth for a blocktxn response.
612612 block_hash = node .getblockhash (current_height )
613613 msg .block_txn_request = BlockTransactionsRequest (int (block_hash , 16 ), [0 ])
614- with mininode_lock :
614+ with p2p_lock :
615615 test_node .last_message .pop ("block" , None )
616616 test_node .last_message .pop ("blocktxn" , None )
617617 test_node .send_and_ping (msg )
618- with mininode_lock :
618+ with p2p_lock :
619619 test_node .last_message ["block" ].block .calc_sha256 ()
620620 assert_equal (test_node .last_message ["block" ].block .sha256 , int (block_hash , 16 ))
621621 assert "blocktxn" not in test_node .last_message
@@ -628,21 +628,21 @@ def test_compactblocks_not_at_tip(self, test_node):
628628 for _ in range (MAX_CMPCTBLOCK_DEPTH + 1 ):
629629 test_node .clear_block_announcement ()
630630 new_blocks .append (node .generate (1 )[0 ])
631- wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
631+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = p2p_lock )
632632
633633 test_node .clear_block_announcement ()
634634 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 = mininode_lock )
635+ wait_until (lambda : "cmpctblock" in test_node .last_message , timeout = 30 , lock = p2p_lock )
636636
637637 test_node .clear_block_announcement ()
638638 node .generate (1 )
639- wait_until (test_node .received_block_announcement , timeout = 30 , lock = mininode_lock )
639+ wait_until (test_node .received_block_announcement , timeout = 30 , lock = p2p_lock )
640640 test_node .clear_block_announcement ()
641- with mininode_lock :
641+ with p2p_lock :
642642 test_node .last_message .pop ("block" , None )
643643 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 = mininode_lock )
645- with mininode_lock :
644+ wait_until (lambda : "block" in test_node .last_message , timeout = 30 , lock = p2p_lock )
645+ with p2p_lock :
646646 test_node .last_message ["block" ].block .calc_sha256 ()
647647 assert_equal (test_node .last_message ["block" ].block .sha256 , int (new_blocks [0 ], 16 ))
648648
@@ -670,10 +670,10 @@ def test_compactblocks_not_at_tip(self, test_node):
670670 # (to avoid fingerprinting attacks).
671671 msg = msg_getblocktxn ()
672672 msg .block_txn_request = BlockTransactionsRequest (block .sha256 , [0 ])
673- with mininode_lock :
673+ with p2p_lock :
674674 test_node .last_message .pop ("blocktxn" , None )
675675 test_node .send_and_ping (msg )
676- with mininode_lock :
676+ with p2p_lock :
677677 assert "blocktxn" not in test_node .last_message
678678
679679 def test_end_to_end_block_relay (self , listeners ):
@@ -689,8 +689,8 @@ def test_end_to_end_block_relay(self, listeners):
689689 node .submitblock (ToHex (block ))
690690
691691 for l in listeners :
692- wait_until (lambda : "cmpctblock" in l .last_message , timeout = 30 , lock = mininode_lock )
693- with mininode_lock :
692+ wait_until (lambda : "cmpctblock" in l .last_message , timeout = 30 , lock = p2p_lock )
693+ with p2p_lock :
694694 for l in listeners :
695695 l .last_message ["cmpctblock" ].header_and_shortids .header .calc_sha256 ()
696696 assert_equal (l .last_message ["cmpctblock" ].header_and_shortids .header .sha256 , block .sha256 )
@@ -747,7 +747,7 @@ def announce_cmpct_block(node, peer):
747747 cmpct_block .initialize_from_block (block )
748748 msg = msg_cmpctblock (cmpct_block .to_p2p ())
749749 peer .send_and_ping (msg )
750- with mininode_lock :
750+ with p2p_lock :
751751 assert "getblocktxn" in peer .last_message
752752 return block , cmpct_block
753753
0 commit comments