Skip to content

Commit a9ecbdf

Browse files
theStackMarcoFalke
andcommitted
test: add more inactive filter tests to p2p_filter.py
check the following expected behaviors if no filter is set: -> filtered block requests are ignored by the node -> sending a 'filteradd' message is treated as misbehavior (i.e. the peer's banscore increases by 100) also fixes a bug in the on_inv() callback method, which directly modified the type from BLOCK to FILTERED_BLOCK in the received 'inv' message rather than just for the reply Co-authored-by: MarcoFalke <[email protected]>
1 parent 5eae034 commit a9ecbdf

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

test/functional/p2p_filter.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
"""
88

99
from test_framework.messages import (
10+
CInv,
1011
MSG_BLOCK,
1112
MSG_FILTERED_BLOCK,
12-
msg_getdata,
13-
msg_filterload,
1413
msg_filteradd,
1514
msg_filterclear,
15+
msg_filterload,
16+
msg_getdata,
1617
)
1718
from test_framework.mininode import (
1819
P2PInterface,
1920
mininode_lock,
2021
)
2122
from test_framework.test_framework import BitcoinTestFramework
23+
from test_framework.util import assert_equal
2224

2325

2426
class FilterNode(P2PInterface):
@@ -38,8 +40,9 @@ def on_inv(self, message):
3840
for i in message.inv:
3941
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
4042
if i.type == MSG_BLOCK:
41-
i.type = MSG_FILTERED_BLOCK
42-
want.inv.append(i)
43+
want.inv.append(CInv(MSG_FILTERED_BLOCK, i.hash))
44+
else:
45+
want.inv.append(i)
4346
if len(want.inv):
4447
self.send_message(want)
4548

@@ -104,6 +107,21 @@ def run_test(self):
104107
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 7)
105108
filter_node.wait_for_tx(txid)
106109

110+
self.log.info('Check that request for filtered blocks is ignored if no filter is set')
111+
filter_node.merkleblock_received = False
112+
filter_node.tx_received = False
113+
with self.nodes[0].assert_debug_log(expected_msgs=['received getdata']):
114+
block_hash = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
115+
filter_node.wait_for_inv([CInv(MSG_BLOCK, int(block_hash, 16))])
116+
filter_node.sync_with_ping()
117+
assert not filter_node.merkleblock_received
118+
assert not filter_node.tx_received
119+
120+
self.log.info('Check that sending "filteradd" if no filter is set is treated as misbehavior (+100)')
121+
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 0)
122+
filter_node.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
123+
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 100)
124+
107125
self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
108126
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
109127
filter_node.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))

0 commit comments

Comments
 (0)