diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -8,6 +8,8 @@ from test_framework.messages import ( CInv, + MAX_BLOOM_FILTER_SIZE, + MAX_BLOOM_HASH_FUNCS, MSG_BLOCK, MSG_FILTERED_BLOCK, msg_filteradd, @@ -16,6 +18,7 @@ msg_getdata, ) from test_framework.mininode import P2PInterface +from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE from test_framework.test_framework import BitcoinTestFramework @@ -70,9 +73,16 @@ filter_node.send_and_ping( msg_filterload( data=b'\xaa', - nHashFuncs=51, - nTweak=0, - nFlags=1)) + nHashFuncs=MAX_BLOOM_HASH_FUNCS + 1)) + with self.nodes[0].assert_debug_log(['Misbehaving']): + filter_node.send_and_ping(msg_filterload( + data=b'\xbb' * (MAX_BLOOM_FILTER_SIZE + 1))) + + self.log.info( + 'Check that too large data element to add to the filter is rejected') + with self.nodes[0].assert_debug_log(['Misbehaving']): + filter_node.send_and_ping(msg_filteradd( + data=b'\xcc' * (MAX_SCRIPT_ELEMENT_SIZE + 1))) self.log.info('Add filtered P2P connection to the node') filter_node.send_and_ping(filter_node.watch_filter_init) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -41,6 +41,8 @@ MAX_LOCATOR_SZ = 101 MAX_BLOCK_BASE_SIZE = 1000000 +MAX_BLOOM_FILTER_SIZE = 36000 +MAX_BLOOM_HASH_FUNCS = 50 # 1 BCH in satoshis COIN = 100000000