Skip to content

Commit 497a619

Browse files
committed
[test] add BIP 37 test for node with fRelay=false
A node with fRelay=False should not receive any invs until filter is set using filterload; all other behavior should be identical.
1 parent e8acc60 commit 497a619

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

test/functional/p2p_filter.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
msg_filterload,
1818
msg_getdata,
1919
msg_mempool,
20+
msg_version,
2021
)
2122
from test_framework.mininode import P2PInterface
2223
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
@@ -108,13 +109,23 @@ def test_msg_mempool(self):
108109
self.nodes[0].p2p.send_message(msg_mempool())
109110
filter_peer.wait_for_tx(txid)
110111

111-
def run_test(self):
112-
filter_node = self.nodes[0].add_p2p_connection(FilterNode())
112+
def test_frelay_false(self, filter_peer):
113+
self.log.info("Check that a node with fRelay set to false does not receive invs until the filter is set")
114+
filter_peer.tx_received = False
115+
filter_address = self.nodes[0].decodescript(filter_peer.watch_script_pubkey)['addresses'][0]
116+
self.nodes[0].sendtoaddress(filter_address, 90)
117+
# Sync to make sure the reason filter_peer doesn't receive the tx is not p2p delays
118+
filter_peer.sync_with_ping()
119+
assert not filter_peer.tx_received
113120

114-
self.test_size_limits(filter_node)
121+
# Clear the mempool so that this transaction does not impact subsequent tests
122+
self.nodes[0].generate(1)
115123

116-
self.log.info('Add filtered P2P connection to the node')
124+
def test_filter(self, filter_node):
125+
# Set the bloomfilter using filterload
117126
filter_node.send_and_ping(filter_node.watch_filter_init)
127+
# If fRelay is not already True, sending filterload sets it to True
128+
assert self.nodes[0].getpeerinfo()[0]['relaytxes']
118129
filter_address = self.nodes[0].decodescript(filter_node.watch_script_pubkey)['addresses'][0]
119130

120131
self.log.info('Check that we receive merkleblock and tx if the filter matches a tx in a block')
@@ -169,6 +180,29 @@ def run_test(self):
169180
filter_node.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
170181
self.nodes[0].disconnect_p2ps()
171182

183+
def run_test(self):
184+
filter_peer = self.nodes[0].add_p2p_connection(FilterNode())
185+
self.log.info('Test filter size limits')
186+
self.test_size_limits(filter_peer)
187+
188+
self.log.info('Test BIP 37 for a node with fRelay = True (default)')
189+
self.test_filter(filter_peer)
190+
self.nodes[0].disconnect_p2ps()
191+
192+
self.log.info('Test BIP 37 for a node with fRelay = False')
193+
# Add peer but do not send version yet
194+
filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(FilterNode(), send_version=False, wait_for_verack=False)
195+
# Send version with fRelay=False
196+
filter_peer_without_nrelay.wait_until(lambda: filter_peer_without_nrelay.is_connected, timeout=10)
197+
version_without_fRelay = msg_version()
198+
version_without_fRelay.nRelay = 0
199+
filter_peer_without_nrelay.send_message(version_without_fRelay)
200+
filter_peer_without_nrelay.wait_for_verack()
201+
assert not self.nodes[0].getpeerinfo()[0]['relaytxes']
202+
self.test_frelay_false(filter_peer_without_nrelay)
203+
self.test_filter(filter_peer_without_nrelay)
204+
205+
self.log.info('Test msg_mempool')
172206
self.test_msg_mempool()
173207

174208
if __name__ == '__main__':

0 commit comments

Comments
 (0)