mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-15 04:30:42 +02:00
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 <falke.marco@gmail.com>
This commit is contained in:
parent
5eae034996
commit
a9ecbdfcaa
@ -7,18 +7,20 @@ Test BIP 37
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
|
CInv,
|
||||||
MSG_BLOCK,
|
MSG_BLOCK,
|
||||||
MSG_FILTERED_BLOCK,
|
MSG_FILTERED_BLOCK,
|
||||||
msg_getdata,
|
|
||||||
msg_filterload,
|
|
||||||
msg_filteradd,
|
msg_filteradd,
|
||||||
msg_filterclear,
|
msg_filterclear,
|
||||||
|
msg_filterload,
|
||||||
|
msg_getdata,
|
||||||
)
|
)
|
||||||
from test_framework.mininode import (
|
from test_framework.mininode import (
|
||||||
P2PInterface,
|
P2PInterface,
|
||||||
mininode_lock,
|
mininode_lock,
|
||||||
)
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
from test_framework.util import assert_equal
|
||||||
|
|
||||||
|
|
||||||
class FilterNode(P2PInterface):
|
class FilterNode(P2PInterface):
|
||||||
@ -38,7 +40,8 @@ class FilterNode(P2PInterface):
|
|||||||
for i in message.inv:
|
for i in message.inv:
|
||||||
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
|
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
|
||||||
if i.type == MSG_BLOCK:
|
if i.type == MSG_BLOCK:
|
||||||
i.type = MSG_FILTERED_BLOCK
|
want.inv.append(CInv(MSG_FILTERED_BLOCK, i.hash))
|
||||||
|
else:
|
||||||
want.inv.append(i)
|
want.inv.append(i)
|
||||||
if len(want.inv):
|
if len(want.inv):
|
||||||
self.send_message(want)
|
self.send_message(want)
|
||||||
@ -104,6 +107,21 @@ class FilterTest(BitcoinTestFramework):
|
|||||||
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 7)
|
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 7)
|
||||||
filter_node.wait_for_tx(txid)
|
filter_node.wait_for_tx(txid)
|
||||||
|
|
||||||
|
self.log.info('Check that request for filtered blocks is ignored if no filter is set')
|
||||||
|
filter_node.merkleblock_received = False
|
||||||
|
filter_node.tx_received = False
|
||||||
|
with self.nodes[0].assert_debug_log(expected_msgs=['received getdata']):
|
||||||
|
block_hash = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
|
||||||
|
filter_node.wait_for_inv([CInv(MSG_BLOCK, int(block_hash, 16))])
|
||||||
|
filter_node.sync_with_ping()
|
||||||
|
assert not filter_node.merkleblock_received
|
||||||
|
assert not filter_node.tx_received
|
||||||
|
|
||||||
|
self.log.info('Check that sending "filteradd" if no filter is set is treated as misbehavior (+100)')
|
||||||
|
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 0)
|
||||||
|
filter_node.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
|
||||||
|
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 100)
|
||||||
|
|
||||||
self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
|
self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
|
||||||
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
|
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
|
||||||
filter_node.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
|
filter_node.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
|
||||||
|
Loading…
Reference in New Issue
Block a user