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) 2022-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"""Tests around pruning rev and blk files on startup."""7import platform8from test_framework.test_framework import BitcoinTestFramework9from test_framework.util import assert_equal12class FeatureRemovePrunedFilesOnStartupTest(BitcoinTestFramework):13def set_test_params(self):14self.num_nodes = 115self.extra_args = [["-fastprune", "-prune=1"]]17def mine_batches(self, blocks):18n = blocks // 25019for _ in range(n):20self.generate(self.nodes[0], 250)21self.generate(self.nodes[0], blocks % 250)23def run_test(self):24blk0 = self.nodes[0].blocks_path / "blk00000.dat"25rev0 = self.nodes[0].blocks_path / "rev00000.dat"26blk1 = self.nodes[0].blocks_path / "blk00001.dat"27rev1 = self.nodes[0].blocks_path / "rev00001.dat"28self.mine_batches(800)30self.log.info("Open some files to check that this may delay deletion")31fd1 = open(blk0, "rb")32fd2 = open(rev1, "rb")33self.nodes[0].pruneblockchain(600)35# Windows systems will not remove files with an open fd36if platform.system() != 'Windows':37assert not blk0.exists()38assert not rev0.exists()39assert not blk1.exists()40assert not rev1.exists()41else:42assert blk0.exists()43assert not rev0.exists()44assert not blk1.exists()45assert rev1.exists()47self.log.info("Check that the files are removed on restart once the fds are closed")48fd1.close()49fd2.close()50self.restart_node(0)51assert not blk0.exists()52assert not rev1.exists()54self.log.info("Check that a reindex will wipe all files")56def ls_files():57ls = [58entry.name59for entry in self.nodes[0].blocks_path.iterdir()60if entry.is_file() and any(map(entry.name.startswith, ["rev", "blk"]))61]62return sorted(ls)64assert_equal(len(ls_files()), 4)65self.restart_node(0, extra_args=self.extra_args[0] + ["-reindex"])66assert_equal(self.nodes[0].getblockcount(), 0)67self.stop_node(0) # Stop node to flush the two newly created files68assert_equal(ls_files(), ["blk00000.dat", "rev00000.dat"])71if __name__ == '__main__':72FeatureRemovePrunedFilesOnStartupTest(__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.