Skip to content

Commit 0474ea2

Browse files
committed
[test] fix race conditions and test in p2p_filter
-grab mininode_lock for every access to mininode attributes, otherwise there are race conditions
1 parent 4ef80f0 commit 0474ea2

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

test/functional/p2p_filter.py

Lines changed: 28 additions & 3 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
22+
from test_framework.mininode import P2PInterface, mininode_lock
2323
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
2424
from test_framework.test_framework import BitcoinTestFramework
2525

@@ -36,6 +36,11 @@ class FilterNode(P2PInterface):
3636
nFlags=1,
3737
)
3838

39+
def __init__(self):
40+
super().__init__()
41+
self._tx_received = False
42+
self._merkleblock_received = False
43+
3944
def on_inv(self, message):
4045
want = msg_getdata()
4146
for i in message.inv:
@@ -48,10 +53,30 @@ def on_inv(self, message):
4853
self.send_message(want)
4954

5055
def on_merkleblock(self, message):
51-
self.merkleblock_received = True
56+
self._merkleblock_received = True
5257

5358
def on_tx(self, message):
54-
self.tx_received = True
59+
self._tx_received = True
60+
61+
@property
62+
def tx_received(self):
63+
with mininode_lock:
64+
return self._tx_received
65+
66+
@tx_received.setter
67+
def tx_received(self, value):
68+
with mininode_lock:
69+
self._tx_received = value
70+
71+
@property
72+
def merkleblock_received(self):
73+
with mininode_lock:
74+
return self._merkleblock_received
75+
76+
@merkleblock_received.setter
77+
def merkleblock_received(self, value):
78+
with mininode_lock:
79+
self._merkleblock_received = value
5580

5681

5782
class FilterTest(BitcoinTestFramework):

0 commit comments

Comments
 (0)