Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2015-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test invalid p2p messages for nodes with bloom filters disabled.7Test that, when bloom filters are not enabled, peers are disconnected if:81. They send a p2p mempool message92. They send a p2p filterload message103. They send a p2p filteradd message114. They send a p2p filterclear message12"""14from test_framework.messages import msg_mempool, msg_filteradd, msg_filterload, msg_filterclear, CInv, MSG_FILTERED_BLOCK, msg_getdata15from test_framework.p2p import P2PInterface16from test_framework.test_framework import BitcoinTestFramework17from test_framework.util import assert_equal20class P2PNoBloomFilterMessages(BitcoinTestFramework):21def set_test_params(self):22self.setup_clean_chain = True23self.num_nodes = 124self.extra_args = [["-peerbloomfilters=0"]]26def test_message_causes_disconnect(self, message):27"""Add a p2p connection that sends a message and check that it disconnects."""28peer = self.nodes[0].add_p2p_connection(P2PInterface())29peer.send_without_ping(message)30peer.wait_for_disconnect()31assert_equal(self.nodes[0].getconnectioncount(), 0)33def run_test(self):34self.log.info("Test that peer is disconnected if it sends mempool message")35self.test_message_causes_disconnect(msg_mempool())37self.log.info("Test that peer is disconnected if it sends filterload message")38self.test_message_causes_disconnect(msg_filterload())40self.log.info("Test that peer is disconnected if it sends filteradd message")41self.test_message_causes_disconnect(msg_filteradd(data=b'\xcc'))43self.log.info("Test that peer is disconnected if it sends a filterclear message")44self.test_message_causes_disconnect(msg_filterclear())46self.log.info("Test that peer is disconnected if it requests a filtered block")47with self.nodes[0].assert_debug_log(['filtered block request received when NODE_BLOOM service disabled']):48self.test_message_causes_disconnect(msg_getdata([CInv(MSG_FILTERED_BLOCK, int(self.nodes[0].getbestblockhash(), 16))]))51if __name__ == '__main__':52P2PNoBloomFilterMessages(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.