diff --git a/test/functional/abc-get-invalid-block.py b/test/functional/abc-get-invalid-block.py --- a/test/functional/abc-get-invalid-block.py +++ b/test/functional/abc-get-invalid-block.py @@ -12,7 +12,7 @@ MSG_BLOCK, MSG_CMPCT_BLOCK, ) -from test_framework.mininode import mininode_lock, P2PInterface +from test_framework.mininode import p2p_lock, P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal @@ -34,7 +34,7 @@ assert_equal(chaintip, node.getbestblockhash()) # Clear any old messages - with mininode_lock: + with p2p_lock: node.p2p.last_message.pop("block", None) node.p2p.last_message.pop("cmpctblock", None) node.p2p.last_message.pop("headers", None) diff --git a/test/functional/abc-invalid-message.py b/test/functional/abc-invalid-message.py --- a/test/functional/abc-invalid-message.py +++ b/test/functional/abc-invalid-message.py @@ -12,7 +12,7 @@ from test_framework.messages import NODE_NETWORK, msg_version from test_framework.mininode import ( - mininode_lock, + p2p_lock, msg_ping, P2PInterface, ) @@ -82,7 +82,7 @@ if not interface.last_message.get("pong"): return False return interface.last_message["pong"].nonce == interface.ping_counter - wait_until(check_ping, lock=mininode_lock) + wait_until(check_ping, lock=p2p_lock) interface.ping_counter += 1 # The valid message is accepted diff --git a/test/functional/abc_p2p_avalanche.py b/test/functional/abc_p2p_avalanche.py --- a/test/functional/abc_p2p_avalanche.py +++ b/test/functional/abc_p2p_avalanche.py @@ -10,7 +10,7 @@ ECKey, ECPubKey, ) -from test_framework.mininode import P2PInterface, mininode_lock +from test_framework.mininode import P2PInterface, p2p_lock from test_framework.messages import ( AvalancheResponse, AvalancheVote, @@ -84,9 +84,9 @@ wait_until( lambda: len(self.avaresponses) > 0, timeout=timeout, - lock=mininode_lock) + lock=p2p_lock) - with mininode_lock: + with p2p_lock: return self.avaresponses.pop(0) def send_poll(self, hashes): @@ -98,16 +98,16 @@ self.send_message(msg) def get_avapoll_if_available(self): - with mininode_lock: + with p2p_lock: return self.avapolls.pop(0) if len(self.avapolls) > 0 else None def wait_for_avahello(self, timeout=5): wait_until( lambda: self.avahello is not None, timeout=timeout, - lock=mininode_lock) + lock=p2p_lock) - with mininode_lock: + with p2p_lock: return self.avahello diff --git a/test/functional/abc_p2p_compactblocks.py b/test/functional/abc_p2p_compactblocks.py --- a/test/functional/abc_p2p_compactblocks.py +++ b/test/functional/abc_p2p_compactblocks.py @@ -33,7 +33,7 @@ ser_compact_size, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PDataStore, P2PInterface, ) @@ -80,7 +80,7 @@ x.calc_sha256() def clear_block_data(self): - with mininode_lock: + with p2p_lock: self.last_sendcmpct = None self.last_cmpctblock = None diff --git a/test/functional/example_test.py b/test/functional/example_test.py --- a/test/functional/example_test.py +++ b/test/functional/example_test.py @@ -23,7 +23,7 @@ ) from test_framework.mininode import ( P2PInterface, - mininode_lock, + p2p_lock, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -218,14 +218,14 @@ # wait_until() will loop until a predicate condition is met. Use it to test properties of the # P2PInterface objects. wait_until(lambda: sorted(blocks) == sorted( - list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock) + list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=p2p_lock) self.log.info("Check that each block was received only once") # The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving # messages. The test thread should acquire the global lock before accessing any P2PConnection data to avoid locking # and synchronization issues. Note wait_until() acquires this global # lock when testing the predicate. - with mininode_lock: + with p2p_lock: for block in self.nodes[2].p2p.block_receive_map.values(): assert_equal(block, 1) diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -43,7 +43,7 @@ ToHex, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.script import CScript, OP_TRUE @@ -88,12 +88,12 @@ self.block_announced = True self.announced_blockhashes.add(x.hash) - # Requires caller to hold mininode_lock + # Requires caller to hold p2p_lock def received_block_announcement(self): return self.block_announced def clear_block_announcement(self): - with mininode_lock: + with p2p_lock: self.block_announced = False self.last_message.pop("inv", None) self.last_message.pop("headers", None) @@ -114,7 +114,7 @@ self.clear_block_announcement() self.get_headers(locator, hashstop) wait_until(self.received_block_announcement, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) self.clear_block_announcement() # Block until a block announcement for a particular block hash is @@ -122,7 +122,7 @@ def wait_for_block_announcement(self, block_hash, timeout=30): def received_hash(): return (block_hash in self.announced_blockhashes) - wait_until(received_hash, timeout=timeout, lock=mininode_lock) + wait_until(received_hash, timeout=timeout, lock=p2p_lock) def send_await_disconnect(self, message, timeout=30): """Sends a message to the node and wait for disconnect. @@ -131,7 +131,7 @@ will get us disconnected, eg an invalid block.""" self.send_message(message) wait_until(lambda: not self.is_connected, - timeout=timeout, lock=mininode_lock) + timeout=timeout, lock=p2p_lock) class CompactBlocksTest(BitcoinTestFramework): @@ -194,8 +194,8 @@ # Make sure we get a SENDCMPCT message from our peer def received_sendcmpct(): return (len(test_node.last_sendcmpct) > 0) - wait_until(received_sendcmpct, timeout=30, lock=mininode_lock) - with mininode_lock: + wait_until(received_sendcmpct, timeout=30, lock=p2p_lock) + with p2p_lock: # Check that the first version received is the preferred one assert_equal( test_node.last_sendcmpct[0].version, preferred_version) @@ -211,7 +211,7 @@ peer.wait_for_block_announcement(block_hash, timeout=30) assert peer.block_announced - with mininode_lock: + with p2p_lock: assert predicate(peer), ( "block_hash={!r}, cmpctblock={!r}, inv={!r}".format( block_hash, peer.last_message.get("cmpctblock", None), peer.last_message.get("inv", None))) @@ -341,11 +341,11 @@ # Wait until the block was announced (via compact blocks) wait_until(test_node.received_block_announcement, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) # Now fetch and check the compact block header_and_shortids = None - with mininode_lock: + with p2p_lock: assert "cmpctblock" in test_node.last_message # Convert the on-the-wire representation to absolute indexes header_and_shortids = HeaderAndShortIDs( @@ -359,11 +359,11 @@ test_node.send_message(msg_getdata([inv])) wait_until(test_node.received_block_announcement, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) # Now fetch and check the compact block header_and_shortids = None - with mininode_lock: + with p2p_lock: assert "cmpctblock" in test_node.last_message # Convert the on-the-wire representation to absolute indexes header_and_shortids = HeaderAndShortIDs( @@ -421,7 +421,7 @@ test_node.send_message( msg_inv([CInv(MSG_BLOCK, block.sha256)])) wait_until(lambda: "getheaders" in test_node.last_message, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) test_node.send_header_for_blocks([block]) else: test_node.send_header_for_blocks([block]) @@ -439,7 +439,7 @@ test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p())) assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock) # Expect a getblocktxn message. - with mininode_lock: + with p2p_lock: assert "getblocktxn" in test_node.last_message absolute_indexes = test_node.last_message["getblocktxn"].block_txn_request.to_absolute( ) @@ -481,7 +481,7 @@ def test_getblocktxn_response(compact_block, peer, expected_result): msg = msg_cmpctblock(compact_block.to_p2p()) peer.send_and_ping(msg) - with mininode_lock: + with p2p_lock: assert "getblocktxn" in peer.last_message absolute_indexes = peer.last_message["getblocktxn"].block_txn_request.to_absolute( ) @@ -558,14 +558,14 @@ assert tx.hash in mempool # Clear out last request. - with mininode_lock: + with p2p_lock: test_node.last_message.pop("getblocktxn", None) # Send compact block comp_block.initialize_from_block(block, prefill_list=[0]) test_tip_after_message( node, test_node, msg_cmpctblock(comp_block.to_p2p()), block.sha256) - with mininode_lock: + with p2p_lock: # Shouldn't have gotten a request for any transaction assert "getblocktxn" not in test_node.last_message @@ -593,7 +593,7 @@ comp_block.initialize_from_block(block, prefill_list=[0]) test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p())) absolute_indices = [] - with mininode_lock: + with p2p_lock: assert "getblocktxn" in test_node.last_message absolute_indices = test_node.last_message["getblocktxn"].block_txn_request.to_absolute( ) @@ -644,10 +644,10 @@ sorted(random.sample(range(len(block.vtx)), num_to_request))) test_node.send_message(msg) wait_until(lambda: "blocktxn" in test_node.last_message, - timeout=10, lock=mininode_lock) + timeout=10, lock=p2p_lock) [tx.calc_sha256() for tx in block.vtx] - with mininode_lock: + with p2p_lock: assert_equal(test_node.last_message["blocktxn"].block_transactions.blockhash, int( block_hash, 16)) all_indices = msg.block_txn_request.to_absolute() @@ -664,11 +664,11 @@ block_hash = node.getblockhash(current_height) msg.block_txn_request = BlockTransactionsRequest( int(block_hash, 16), [0]) - with mininode_lock: + with p2p_lock: test_node.last_message.pop("block", None) test_node.last_message.pop("blocktxn", None) test_node.send_and_ping(msg) - with mininode_lock: + with p2p_lock: test_node.last_message["block"].block.calc_sha256() assert_equal( test_node.last_message["block"].block.sha256, int(block_hash, 16)) @@ -682,26 +682,26 @@ test_node.clear_block_announcement() new_blocks.append(node.generate(1)[0]) wait_until(test_node.received_block_announcement, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) test_node.clear_block_announcement() test_node.send_message(msg_getdata( [CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))])) wait_until(lambda: "cmpctblock" in test_node.last_message, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) test_node.clear_block_announcement() node.generate(1) wait_until(test_node.received_block_announcement, - timeout=30, lock=mininode_lock) + timeout=30, lock=p2p_lock) test_node.clear_block_announcement() - with mininode_lock: + with p2p_lock: test_node.last_message.pop("block", None) test_node.send_message(msg_getdata( [CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))])) wait_until(lambda: "block" in test_node.last_message, - timeout=30, lock=mininode_lock) - with mininode_lock: + timeout=30, lock=p2p_lock) + with p2p_lock: test_node.last_message["block"].block.calc_sha256() assert_equal( test_node.last_message["block"].block.sha256, int(new_blocks[0], 16)) @@ -730,10 +730,10 @@ # (to avoid fingerprinting attacks). msg = msg_getblocktxn() msg.block_txn_request = BlockTransactionsRequest(block.sha256, [0]) - with mininode_lock: + with p2p_lock: test_node.last_message.pop("blocktxn", None) test_node.send_and_ping(msg) - with mininode_lock: + with p2p_lock: assert "blocktxn" not in test_node.last_message def test_end_to_end_block_relay(self, node, listeners): @@ -747,8 +747,8 @@ for listener in listeners: wait_until(lambda: listener.received_block_announcement(), - timeout=30, lock=mininode_lock) - with mininode_lock: + timeout=30, lock=p2p_lock) + with p2p_lock: for listener in listeners: assert "cmpctblock" in listener.last_message listener.last_message["cmpctblock"].header_and_shortids.header.calc_sha256( @@ -801,7 +801,7 @@ cmpct_block.initialize_from_block(block) msg = msg_cmpctblock(cmpct_block.to_p2p()) peer.send_and_ping(msg) - with mininode_lock: + with p2p_lock: assert "getblocktxn" in peer.last_message return block, cmpct_block diff --git a/test/functional/p2p_feefilter.py b/test/functional/p2p_feefilter.py --- a/test/functional/p2p_feefilter.py +++ b/test/functional/p2p_feefilter.py @@ -9,7 +9,7 @@ from test_framework.messages import MSG_TX, msg_feefilter from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework @@ -24,7 +24,7 @@ def allInvsMatch(invsExpected, testnode): for x in range(60): - with mininode_lock: + with p2p_lock: if (sorted(invsExpected) == sorted(testnode.txinvs)): return True time.sleep(1) @@ -38,7 +38,7 @@ self.feefilter_received = True def assert_feefilter_received(self, recv: bool): - with mininode_lock: + with p2p_lock: assert_equal(self.feefilter_received, recv) @@ -53,7 +53,7 @@ self.txinvs.append(hashToHex(i.hash)) def clear_invs(self): - with mininode_lock: + with p2p_lock: self.txinvs = [] diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -19,7 +19,7 @@ msg_mempool, msg_version, ) -from test_framework.mininode import P2PInterface, mininode_lock +from test_framework.mininode import P2PInterface, p2p_lock from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE from test_framework.test_framework import BitcoinTestFramework @@ -61,22 +61,22 @@ @property def tx_received(self): - with mininode_lock: + with p2p_lock: return self._tx_received @tx_received.setter def tx_received(self, value): - with mininode_lock: + with p2p_lock: self._tx_received = value @property def merkleblock_received(self): - with mininode_lock: + with p2p_lock: return self._merkleblock_received @merkleblock_received.setter def merkleblock_received(self, value): - with mininode_lock: + with p2p_lock: self._merkleblock_received = value diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py --- a/test/functional/p2p_leak.py +++ b/test/functional/p2p_leak.py @@ -20,7 +20,7 @@ msg_version, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework @@ -154,11 +154,11 @@ wait_until( lambda: no_version_disconnect_node.ever_connected, timeout=10, - lock=mininode_lock) + lock=p2p_lock) wait_until(lambda: no_version_idlenode.ever_connected, - timeout=10, lock=mininode_lock) + timeout=10, lock=p2p_lock) wait_until(lambda: no_verack_idlenode.version_received, - timeout=10, lock=mininode_lock) + timeout=10, lock=p2p_lock) # Mine a block and make sure that it's not sent to the connected nodes self.nodes[0].generatetoaddress( diff --git a/test/functional/p2p_node_network_limited.py b/test/functional/p2p_node_network_limited.py --- a/test/functional/p2p_node_network_limited.py +++ b/test/functional/p2p_node_network_limited.py @@ -17,7 +17,7 @@ NODE_NETWORK_LIMITED, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework @@ -41,7 +41,7 @@ def wait_for_addr(self, timeout=5): def test_function(): return self.last_message.get("addr") - wait_until(test_function, timeout=timeout, lock=mininode_lock) + wait_until(test_function, timeout=timeout, lock=p2p_lock) def send_getdata_for_block(self, blockhash): getdata_request = msg_getdata() diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -99,7 +99,7 @@ msg_sendheaders, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework @@ -149,7 +149,7 @@ def wait_for_block_announcement(self, block_hash, timeout=60): def test_function(): return self.last_blockhash_announced == block_hash - wait_until(test_function, timeout=timeout, lock=mininode_lock) + wait_until(test_function, timeout=timeout, lock=p2p_lock) def on_inv(self, message): self.block_announced = True @@ -166,7 +166,7 @@ self.last_blockhash_announced = message.headers[-1].sha256 def clear_block_announcements(self): - with mininode_lock: + with p2p_lock: self.block_announced = False self.last_message.pop("inv", None) self.last_message.pop("headers", None) @@ -177,8 +177,8 @@ Headers may be announced across more than one message.""" def test_function(): return (len(self.recent_headers_announced) >= len(headers)) - wait_until(test_function, timeout=60, lock=mininode_lock) - with mininode_lock: + wait_until(test_function, timeout=60, lock=p2p_lock) + with p2p_lock: assert_equal(self.recent_headers_announced, headers) self.block_announced = False self.last_message.pop("headers", None) @@ -189,9 +189,9 @@ inv should be a list of block hashes.""" def test_function(): return self.block_announced - wait_until(test_function, timeout=60, lock=mininode_lock) + wait_until(test_function, timeout=60, lock=p2p_lock) - with mininode_lock: + with p2p_lock: compare_inv = [] if "inv" in self.last_message: compare_inv = [x.hash for x in self.last_message["inv"].inv] @@ -320,7 +320,7 @@ # make sure this block is processed test_node.send_and_ping(msg_block(new_block)) wait_until(lambda: inv_node.block_announced, - timeout=60, lock=mininode_lock) + timeout=60, lock=p2p_lock) inv_node.clear_block_announcements() test_node.clear_block_announcements() @@ -488,7 +488,7 @@ test_node.send_header_for_blocks(blocks) test_node.sync_with_ping() # should not have received any getdata messages - with mininode_lock: + with p2p_lock: assert "getdata" not in test_node.last_message # This time, direct fetch should work @@ -529,7 +529,7 @@ test_node.last_message.pop("getdata", None) test_node.send_header_for_blocks(blocks[0:1]) test_node.sync_with_ping() - with mininode_lock: + with p2p_lock: assert "getdata" not in test_node.last_message # Announcing one more block on fork should trigger direct fetch for @@ -550,7 +550,7 @@ test_node.last_message.pop("getdata", None) test_node.send_header_for_blocks(blocks[18:19]) test_node.sync_with_ping() - with mininode_lock: + with p2p_lock: assert "getdata" not in test_node.last_message self.log.info("Part 4: success!") @@ -574,7 +574,7 @@ block_time += 1 height += 1 # Send the header of the second block -> this won't connect. - with mininode_lock: + with p2p_lock: test_node.last_message.pop("getheaders", None) test_node.send_header_for_blocks([blocks[1]]) test_node.wait_for_getheaders() @@ -600,7 +600,7 @@ for i in range(1, MAX_UNCONNECTING_HEADERS): # Send a header that doesn't connect, check that we get a # getheaders. - with mininode_lock: + with p2p_lock: test_node.last_message.pop("getheaders", None) test_node.send_header_for_blocks([blocks[i]]) test_node.wait_for_getheaders() @@ -616,7 +616,7 @@ for i in range(5 * MAX_UNCONNECTING_HEADERS - 1): # Send a header that doesn't connect, check that we get a # getheaders. - with mininode_lock: + with p2p_lock: test_node.last_message.pop("getheaders", None) test_node.send_header_for_blocks([blocks[i % len(blocks)]]) test_node.wait_for_getheaders() diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py --- a/test/functional/p2p_tx_download.py +++ b/test/functional/p2p_tx_download.py @@ -18,7 +18,7 @@ ) from test_framework.mininode import ( P2PInterface, - mininode_lock, + p2p_lock, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -72,7 +72,7 @@ def getdata_found(peer_index): p = self.nodes[0].p2ps[peer_index] - with mininode_lock: + with p2p_lock: return p.last_message.get( "getdata") and p.last_message["getdata"].inv[-1].hash == txid @@ -136,7 +136,7 @@ p = self.nodes[0].p2ps[0] - with mininode_lock: + with p2p_lock: p.tx_getdata_count = 0 mock_time = int(time.time() + 1) @@ -162,7 +162,7 @@ OVERLOADED_PEER_DELAY - 1) p.sync_with_ping() - with mininode_lock: + with p2p_lock: assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT) self.log.info( "If we wait {} seconds after announcement, we should eventually get more requests".format( @@ -187,7 +187,7 @@ lambda: sum( p.tx_getdata_count for p in [ peer1, peer2]) == 1) - with mininode_lock: + with p2p_lock: peer_expiry, peer_fallback = ( peer1, peer2) if peer1.tx_getdata_count == 1 else ( peer2, peer1) @@ -196,7 +196,7 @@ self.nodes[0].setmocktime(int(time.time()) + GETDATA_TX_INTERVAL + 1) peer_fallback.wait_until( lambda: peer_fallback.tx_getdata_count >= 1, timeout=1) - with mininode_lock: + with p2p_lock: assert_equal(peer_fallback.tx_getdata_count, 1) # reset mocktime self.restart_node(0) @@ -214,7 +214,7 @@ lambda: sum( p.tx_getdata_count for p in [ peer1, peer2]) == 1) - with mininode_lock: + with p2p_lock: peer_disconnect, peer_fallback = ( peer1, peer2) if peer1.tx_getdata_count == 1 else ( peer2, peer1) @@ -223,7 +223,7 @@ peer_disconnect.wait_for_disconnect() peer_fallback.wait_until( lambda: peer_fallback.tx_getdata_count >= 1, timeout=1) - with mininode_lock: + with p2p_lock: assert_equal(peer_fallback.tx_getdata_count, 1) def test_notfound_fallback(self): @@ -239,7 +239,7 @@ lambda: sum( p.tx_getdata_count for p in [ peer1, peer2]) == 1) - with mininode_lock: + with p2p_lock: peer_notfound, peer_fallback = ( peer1, peer2) if peer1.tx_getdata_count == 1 else ( peer2, peer1) @@ -248,7 +248,7 @@ peer_notfound.send_and_ping(msg_notfound(vec=[CInv(MSG_TX, TXID)])) peer_fallback.wait_until( lambda: peer_fallback.tx_getdata_count >= 1, timeout=1) - with mininode_lock: + with p2p_lock: assert_equal(peer_fallback.tx_getdata_count, 1) def test_preferred_inv(self): @@ -258,7 +258,7 @@ peer = self.nodes[0].add_p2p_connection(TestP2PConn()) peer.send_message(msg_inv([CInv(t=MSG_TX, h=0xff00ff00)])) peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1) - with mininode_lock: + with p2p_lock: assert_equal(peer.tx_getdata_count, 1) def test_large_inv_batch(self): @@ -267,7 +267,7 @@ self.restart_node(0, extra_args=['-whitelist=relay@127.0.0.1']) peer = self.nodes[0].add_p2p_connection(TestP2PConn()) peer.send_message(msg_inv([CInv(t=MSG_TX, h=txid) - for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) + for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) peer.wait_until(lambda: peer.tx_getdata_count == MAX_PEER_TX_ANNOUNCEMENTS + 1) @@ -276,11 +276,11 @@ self.restart_node(0) peer = self.nodes[0].add_p2p_connection(TestP2PConn()) peer.send_message(msg_inv([CInv(t=MSG_TX, h=txid) - for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) + for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) peer.wait_until(lambda: peer.tx_getdata_count == MAX_PEER_TX_ANNOUNCEMENTS) peer.sync_with_ping() - with mininode_lock: + with p2p_lock: assert_equal(peer.tx_getdata_count, MAX_PEER_TX_ANNOUNCEMENTS) def test_spurious_notfound(self): diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -67,7 +67,7 @@ msg_inv, ) from test_framework.mininode import ( - mininode_lock, + p2p_lock, P2PInterface, ) from test_framework.test_framework import BitcoinTestFramework @@ -238,13 +238,13 @@ # 6. Try to get node to request the missing block. # Poke the node with an inv for block at height 3 and see if that # triggers a getdata on block 2 (it should if block 2 is missing). - with mininode_lock: + with p2p_lock: # Clear state so we can check the getdata request test_node.last_message.pop("getdata", None) test_node.send_message(msg_inv([CInv(MSG_BLOCK, block_h3.sha256)])) test_node.sync_with_ping() - with mininode_lock: + with p2p_lock: getdata = test_node.last_message["getdata"] # Check that the getdata includes the right block diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -198,7 +198,7 @@ def data_received(self, t): """asyncio callback when data is read from the socket.""" - with mininode_lock: + with p2p_lock: if len(t) > 0: self.recvbuf += t @@ -215,7 +215,7 @@ parses and verifies the P2P header, then passes the P2P payload to the on_message callback for processing.""" try: - with mininode_lock: + with p2p_lock: if len(self.recvbuf) < 4: return None if self.recvbuf[:4] != self.magic_bytes: @@ -362,7 +362,7 @@ We keep a count of how many of each message type has been received and the most recent message of each type.""" - with mininode_lock: + with p2p_lock: try: msgtype = message.msgtype.decode('ascii') self.message_count[msgtype] += 1 @@ -473,7 +473,7 @@ assert self.is_connected return test_function_in() - wait_until(test_function, timeout=timeout, lock=mininode_lock, + wait_until(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor) def wait_for_disconnect(self, timeout=60): @@ -581,7 +581,7 @@ # P2PConnection acquires this lock whenever delivering a message to a P2PInterface. # This lock should be acquired in the thread running the test logic to synchronize # access to any data shared with the P2PInterface or P2PConnection. -mininode_lock = threading.Lock() +p2p_lock = threading.Lock() class NetworkThread(threading.Thread): @@ -683,7 +683,7 @@ - if success is False: assert that the node's tip doesn't advance - if reject_reason is set: assert that the correct reject message is logged""" - with mininode_lock: + with p2p_lock: for block in blocks: self.block_store[block.sha256] = block self.last_block_hash = block.sha256 @@ -729,7 +729,7 @@ - if expect_disconnect is True: Skip the sync with ping - if reject_reason is set: assert that the correct reject message is logged.""" - with mininode_lock: + with p2p_lock: for tx in txs: self.tx_store[tx.sha256] = tx @@ -778,7 +778,7 @@ self.tx_invs_received[i.hash] += 1 def get_invs(self): - with mininode_lock: + with p2p_lock: return list(self.tx_invs_received.keys()) def wait_for_broadcast(self, txns, timeout=60): diff --git a/test/functional/wallet_resendwallettransactions.py b/test/functional/wallet_resendwallettransactions.py --- a/test/functional/wallet_resendwallettransactions.py +++ b/test/functional/wallet_resendwallettransactions.py @@ -7,7 +7,7 @@ from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ToHex -from test_framework.mininode import P2PTxInvStore, mininode_lock +from test_framework.mininode import P2PTxInvStore, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, wait_until @@ -36,7 +36,7 @@ # Can take a few seconds due to transaction trickling wait_until( lambda: node.p2p.tx_invs_received[txid] >= 1, - lock=mininode_lock) + lock=p2p_lock) # Add a second peer since txs aren't rebroadcast to the same peer (see # filterInventoryKnown) @@ -77,7 +77,7 @@ node.setmocktime(now + 36 * 60 * 60 + 600) wait_until( lambda: node.p2ps[1].tx_invs_received[txid] >= 1, - lock=mininode_lock) + lock=p2p_lock) if __name__ == '__main__':