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) 2020-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 GETDATA processing behavior"""6from collections import defaultdict8from test_framework.messages import (9CInv,10msg_getdata,11)12from test_framework.p2p import P2PInterface13from test_framework.test_framework import BitcoinTestFramework16class P2PStoreBlock(P2PInterface):17def __init__(self):18super().__init__()19self.blocks = defaultdict(int)21def on_block(self, message):22self.blocks[message.block.hash_int] += 125class GetdataTest(BitcoinTestFramework):26def set_test_params(self):27self.num_nodes = 129def test_invalid_getdata(self):30p2p_block_store = self.nodes[0].add_p2p_connection(P2PStoreBlock())32self.log.info("test that an invalid GETDATA doesn't prevent processing of future messages")34# Send invalid message and verify that node responds to later ping35invalid_getdata = msg_getdata()36invalid_getdata.inv.append(CInv(t=0, h=0)) # INV type 0 is invalid.37p2p_block_store.send_and_ping(invalid_getdata)39# Check getdata still works by fetching tip block40best_block = int(self.nodes[0].getbestblockhash(), 16)41good_getdata = msg_getdata()42good_getdata.inv.append(CInv(t=2, h=best_block))43p2p_block_store.send_and_ping(good_getdata)44p2p_block_store.wait_until(lambda: p2p_block_store.blocks[best_block] == 1)47def run_test(self):48self.test_invalid_getdata()51if __name__ == '__main__':52GetdataTest(__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.