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) 2026-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 restart with a pruned stale-fork block whose parent has no transactions."""7from test_framework.blocktools import create_empty_fork8from test_framework.test_framework import BitcoinTestFramework9from test_framework.util import assert_equal, assert_raises_rpc_error12class FeaturePruneStaleForkTest(BitcoinTestFramework):13def set_test_params(self):14self.num_nodes = 115self.extra_args = [["-prune=1", "-fastprune"]]17def run_test(self):18node = self.nodes[0]20self.log.info("Create a 2-block stale fork: parent has no transactions, child has transactions")21[side_parent, side_child] = create_empty_fork(node, 2)23node.submitheader(side_parent.serialize().hex())24node.submitblock(side_child.serialize().hex())25assert_equal(node.getblockheader(side_parent.hash_hex)["nTx"], 0)26assert_equal(node.getblockheader(side_child.hash_hex)["nTx"], 1)28self.log.info("Advance and prune so the stale-fork child's block data is removed from disk")29self.generate(node, 500)30node.pruneblockchain(node.getblockcount() - 100)31assert_raises_rpc_error(-1, "Block not available (pruned data)", node.getblock, side_child.hash_hex)33self.log.info("Restart and mine; node must reload cleanly after the stale-fork child was pruned")34self.restart_node(0)35self.generate(node, 1)38if __name__ == '__main__':39FeaturePruneStaleForkTest(__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.