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) 2019-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 bitcoind aborts if can't disconnect a block.7- Start a single node and generate 3 blocks.8- Delete the undo data.9- Mine a fork that requires disconnecting the tip.10- Verify that bitcoind AbortNode's.11"""12from test_framework.test_framework import BitcoinTestFramework15class AbortNodeTest(BitcoinTestFramework):16def set_test_params(self):17self.setup_clean_chain = True18self.num_nodes = 220def setup_network(self):21self.setup_nodes()22# We'll connect the nodes later24def run_test(self):25self.generate(self.nodes[0], 3, sync_fun=self.no_op)27# Deleting the undo file will result in reorg failure28(self.nodes[0].blocks_path / "rev00000.dat").unlink()30# Connecting to a node with a more work chain will trigger a reorg31# attempt.32self.generate(self.nodes[1], 3, sync_fun=self.no_op)33with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):34self.connect_nodes(0, 1)35self.generate(self.nodes[1], 1, sync_fun=self.no_op)37# Check that node0 aborted38self.log.info("Waiting for crash")39self.nodes[0].wait_until_stopped(timeout=5, expect_error=True, expected_stderr="Error: A fatal internal error occurred, see debug.log for details: Failed to disconnect block.")40self.log.info("Node crashed - now verifying restart fails")41self.nodes[0].assert_start_raises_init_error()44if __name__ == '__main__':45AbortNodeTest(__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.