Skip to content

Commit 9e2897d

Browse files
committed
scripted-diff: Rename mininode_lock to p2p_lock
-BEGIN VERIFY SCRIPT- sed -i 's/mininode_lock/p2p_lock/g' $(git grep -l "mininode_lock") -END VERIFY SCRIPT-
1 parent d254e6e commit 9e2897d

14 files changed

+97
-97
lines changed

test/functional/example_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from test_framework.messages import CInv, MSG_BLOCK
1919
from test_framework.mininode import (
2020
P2PInterface,
21-
mininode_lock,
21+
p2p_lock,
2222
msg_block,
2323
msg_getdata,
2424
)
@@ -203,13 +203,13 @@ def run_test(self):
203203

204204
# wait_until() will loop until a predicate condition is met. Use it to test properties of the
205205
# P2PInterface objects.
206-
wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock)
206+
wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=p2p_lock)
207207

208208
self.log.info("Check that each block was received only once")
209209
# The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving
210210
# messages. The test thread should acquire the global lock before accessing any P2PConnection data to avoid locking
211211
# and synchronization issues. Note wait_until() acquires this global lock when testing the predicate.
212-
with mininode_lock:
212+
with p2p_lock:
213213
for block in self.nodes[2].p2p.block_receive_map.values():
214214
assert_equal(block, 1)
215215

test/functional/feature_versionbits_warning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from test_framework.blocktools import create_block, create_coinbase
1414
from test_framework.messages import msg_block
15-
from test_framework.mininode import P2PInterface, mininode_lock
15+
from test_framework.mininode import P2PInterface, p2p_lock
1616
from test_framework.test_framework import BitcoinTestFramework
1717
from test_framework.util import wait_until
1818

@@ -91,7 +91,7 @@ def run_test(self):
9191

9292
# Generating one block guarantees that we'll get out of IBD
9393
node.generatetoaddress(1, node_deterministic_address)
94-
wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=mininode_lock)
94+
wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=p2p_lock)
9595
# Generating one more block will be enough to generate an error.
9696
node.generatetoaddress(1, node_deterministic_address)
9797
# Check that get*info() shows the versionbits unknown rules warning

test/functional/p2p_compactblocks.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment
1313
from 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
1515
from test_framework.script import CScript, OP_TRUE, OP_DROP
1616
from test_framework.test_framework import BitcoinTestFramework
1717
from 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

9494
class 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

test/functional/p2p_feefilter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from decimal import Decimal
88

99
from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter
10-
from test_framework.mininode import mininode_lock, P2PInterface
10+
from test_framework.mininode import p2p_lock, P2PInterface
1111
from test_framework.test_framework import BitcoinTestFramework
1212
from test_framework.util import assert_equal
1313

@@ -23,7 +23,7 @@ def on_feefilter(self, message):
2323
self.feefilter_received = True
2424

2525
def assert_feefilter_received(self, recv: bool):
26-
with mininode_lock:
26+
with p2p_lock:
2727
assert_equal(self.feefilter_received, recv)
2828

2929

@@ -42,7 +42,7 @@ def wait_for_invs_to_match(self, invs_expected):
4242
self.wait_until(lambda: invs_expected == sorted(self.txinvs), timeout=60)
4343

4444
def clear_invs(self):
45-
with mininode_lock:
45+
with p2p_lock:
4646
self.txinvs = []
4747

4848

test/functional/p2p_filter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
msg_mempool,
2020
msg_version,
2121
)
22-
from test_framework.mininode import P2PInterface, mininode_lock
22+
from test_framework.mininode import P2PInterface, p2p_lock
2323
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
2424
from test_framework.test_framework import BitcoinTestFramework
2525

@@ -60,22 +60,22 @@ def on_tx(self, message):
6060

6161
@property
6262
def tx_received(self):
63-
with mininode_lock:
63+
with p2p_lock:
6464
return self._tx_received
6565

6666
@tx_received.setter
6767
def tx_received(self, value):
68-
with mininode_lock:
68+
with p2p_lock:
6969
self._tx_received = value
7070

7171
@property
7272
def merkleblock_received(self):
73-
with mininode_lock:
73+
with p2p_lock:
7474
return self._merkleblock_received
7575

7676
@merkleblock_received.setter
7777
def merkleblock_received(self, value):
78-
with mininode_lock:
78+
with p2p_lock:
7979
self._merkleblock_received = value
8080

8181

test/functional/p2p_getaddr_caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from test_framework.mininode import (
1616
P2PInterface,
17-
mininode_lock
17+
p2p_lock
1818
)
1919
from test_framework.test_framework import BitcoinTestFramework
2020
from test_framework.util import (
@@ -44,7 +44,7 @@ def __init__(self):
4444
self.received_addrs = None
4545

4646
def get_received_addrs(self):
47-
with mininode_lock:
47+
with p2p_lock:
4848
return self.received_addrs
4949

5050
def on_addr(self, message):

test/functional/p2p_leak.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
msg_ping,
1818
msg_version,
1919
)
20-
from test_framework.mininode import mininode_lock, P2PInterface
20+
from test_framework.mininode import p2p_lock, P2PInterface
2121
from test_framework.test_framework import BitcoinTestFramework
2222
from test_framework.util import (
2323
assert_equal,
@@ -114,9 +114,9 @@ def run_test(self):
114114
# verack, since we never sent one
115115
no_verack_idle_peer.wait_for_verack()
116116

117-
wait_until(lambda: no_version_disconnect_peer.ever_connected, timeout=10, lock=mininode_lock)
118-
wait_until(lambda: no_version_idle_peer.ever_connected, timeout=10, lock=mininode_lock)
119-
wait_until(lambda: no_verack_idle_peer.version_received, timeout=10, lock=mininode_lock)
117+
wait_until(lambda: no_version_disconnect_peer.ever_connected, timeout=10, lock=p2p_lock)
118+
wait_until(lambda: no_version_idle_peer.ever_connected, timeout=10, lock=p2p_lock)
119+
wait_until(lambda: no_verack_idle_peer.version_received, timeout=10, lock=p2p_lock)
120120

121121
# Mine a block and make sure that it's not sent to the connected peers
122122
self.nodes[0].generate(nblocks=1)

0 commit comments

Comments
 (0)