From edae6075aa3b1169c84b65e76fd48d68242a294e Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 5 Jun 2020 10:57:13 -0400 Subject: [PATCH 1/4] [tests] Only acquire lock once in p2p_compactblocks.py --- test/functional/p2p_compactblocks.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index d77a744758..0b3738b572 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -305,10 +305,9 @@ class CompactBlocksTest(BitcoinTestFramework): self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block) # Now fetch the compact block using a normal non-announce getdata - with mininode_lock: - test_node.clear_block_announcement() - inv = CInv(MSG_CMPCT_BLOCK, block_hash) - test_node.send_message(msg_getdata([inv])) + test_node.clear_block_announcement() + inv = CInv(MSG_CMPCT_BLOCK, block_hash) + test_node.send_message(msg_getdata([inv])) wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock) From 9d80762fa0931fe553fad241e95bcc1515ef0e95 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 5 Jun 2020 10:58:25 -0400 Subject: [PATCH 2/4] [tests] Don't acquire mininode_lock twice in wait_for_broadcast() --- test/functional/test_framework/mininode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py index 45063aaff2..69307d1960 100755 --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -669,6 +669,6 @@ class P2PTxInvStore(P2PInterface): The mempool should mark unbroadcast=False for these transactions. """ # Wait until invs have been received (and getdatas sent) for each txid. - self.wait_until(lambda: set(self.get_invs()) == set([int(tx, 16) for tx in txns]), timeout) + self.wait_until(lambda: set(self.tx_invs_received.keys()) == set([int(tx, 16) for tx in txns]), timeout) # Flush messages and wait for the getdatas to be processed self.sync_with_ping() From c67c1f2c032a8efa141d776a7e5be58f052159ea Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 5 Jun 2020 10:59:40 -0400 Subject: [PATCH 3/4] [tests] Don't call super twice in P2PTxInvStore.on_inv() --- test/functional/test_framework/mininode.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py index 69307d1960..a2c695a704 100755 --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -658,8 +658,6 @@ class P2PTxInvStore(P2PInterface): # save txid self.tx_invs_received[i.hash] += 1 - super().on_inv(message) - def get_invs(self): with mininode_lock: return list(self.tx_invs_received.keys()) From 62068381a3b9c065d81300be79abba7aecfdb41b Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 5 Jun 2020 11:01:54 -0400 Subject: [PATCH 4/4] [tests] Make mininode_lock non-reentrant There's no need for mininode_lock to be reentrant. Use a simpler non-recursive lock. --- test/functional/test_framework/mininode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py index a2c695a704..b6c37bc7e0 100755 --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -492,7 +492,7 @@ class P2PInterface(P2PConnection): # 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.RLock() +mininode_lock = threading.Lock() class NetworkThread(threading.Thread):