mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
[test] fix race conditions and test in p2p_filter
-grab mininode_lock for every access to mininode attributes, otherwise there are race conditions
This commit is contained in:
parent
4ef80f0827
commit
0474ea25af
1 changed files with 28 additions and 3 deletions
|
@ -19,7 +19,7 @@ from test_framework.messages import (
|
|||
msg_mempool,
|
||||
msg_version,
|
||||
)
|
||||
from test_framework.mininode import P2PInterface
|
||||
from test_framework.mininode import P2PInterface, mininode_lock
|
||||
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
|
@ -36,6 +36,11 @@ class FilterNode(P2PInterface):
|
|||
nFlags=1,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._tx_received = False
|
||||
self._merkleblock_received = False
|
||||
|
||||
def on_inv(self, message):
|
||||
want = msg_getdata()
|
||||
for i in message.inv:
|
||||
|
@ -48,10 +53,30 @@ class FilterNode(P2PInterface):
|
|||
self.send_message(want)
|
||||
|
||||
def on_merkleblock(self, message):
|
||||
self.merkleblock_received = True
|
||||
self._merkleblock_received = True
|
||||
|
||||
def on_tx(self, message):
|
||||
self.tx_received = True
|
||||
self._tx_received = True
|
||||
|
||||
@property
|
||||
def tx_received(self):
|
||||
with mininode_lock:
|
||||
return self._tx_received
|
||||
|
||||
@tx_received.setter
|
||||
def tx_received(self, value):
|
||||
with mininode_lock:
|
||||
self._tx_received = value
|
||||
|
||||
@property
|
||||
def merkleblock_received(self):
|
||||
with mininode_lock:
|
||||
return self._merkleblock_received
|
||||
|
||||
@merkleblock_received.setter
|
||||
def merkleblock_received(self, value):
|
||||
with mininode_lock:
|
||||
self._merkleblock_received = value
|
||||
|
||||
|
||||
class FilterTest(BitcoinTestFramework):
|
||||
|
|
Loading…
Add table
Reference in a new issue