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 node responses to invalid locators.6"""8from test_framework.messages import msg_getheaders, msg_getblocks, MAX_LOCATOR_SZ9from test_framework.p2p import P2PInterface10from test_framework.test_framework import BitcoinTestFramework13class InvalidLocatorTest(BitcoinTestFramework):14def set_test_params(self):15self.num_nodes = 117def run_test(self):18node = self.nodes[0] # convenience reference to the node19self.generatetoaddress(node, 1, node.get_deterministic_priv_key().address) # Get node out of IBD21self.log.info('Test max locator size')22block_count = node.getblockcount()23for msg in [msg_getheaders(), msg_getblocks()]:24self.log.info('Wait for disconnect when sending {} hashes in locator'.format(MAX_LOCATOR_SZ + 1))25exceed_max_peer = node.add_p2p_connection(P2PInterface())26msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)]27exceed_max_peer.send_without_ping(msg)28exceed_max_peer.wait_for_disconnect()29node.disconnect_p2ps()31self.log.info('Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ))32within_max_peer = node.add_p2p_connection(P2PInterface())33msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)]34within_max_peer.send_without_ping(msg)35if type(msg) is msg_getheaders:36within_max_peer.wait_for_header(node.getbestblockhash())37else:38within_max_peer.wait_for_block(int(node.getbestblockhash(), 16))41if __name__ == '__main__':42InvalidLocatorTest(__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.