Repository navigation
Conversation
Without this, -prune and -fastprune in extra_args have no effect.
Move the blk file aside instead of deleting it, so it can be restored.
The pruned blk/rev files are not deleted, even after a later flush succeeds.
Files selected for pruning were kept in a local, so a failed flush left them on disk until the next startup. Keep them in BlockManager and delete them after the next block index write. Take them with the dirty entries, which WriteBlockIndexDB() drops even if the write fails. Drop a file from the set once a block is written to it. Pending files wait for the next periodic, forced or shutdown flush rather than forcing one, which would retry a failing write on every block.
Move the block and undo file flush, block index write and pruned file deletion from FlushStateToDisk into BlockManager. Their bench log lines change from FlushStateToDisk to WriteBlockStorage.
Validation read BlockManager's prune locks directly. Move that code and PRUNE_LOCK_BUFFER into BlockManager.
BlockManager read the chainstate to decide what to prune. Decide in validation and pass the height range and sizes instead. An Assume checks the heights are non-negative.
Move FlushStateToDisk's handling of the prune request, prune locks, pruned flag, files to delete and blocks directory space check into BlockManager. The prune request is cleared before the prune locks are applied rather than after selection, which differs only if selection throws. An Assume checks that the pruned flag is set before files are queued for deletion, so a restart knows blocks were deleted.
ChainMan declares m_context last, which destroys it before the ChainstateManager that refers into it. Reset the chainstate manager explicitly, making the order independent of member declaration order.
Create the BlockManager first and pass it in by reference. NodeContext and the kernel own both and destroy ChainstateManager first. The block tree database opens before the script verification threads start, which swaps their startup log lines.
The flag duplicated the BlockManager's prune mode. Init and the test setup copied it, and the kernel left it false. Check the BlockManager directly, keeping one source of truth before the kernel can enable pruning.
Block storage was configured and read through the chainstate manager. Add btck_BlockManagerOptions and btck_BlockManager, and pass the block manager to btck_chainstate_manager_create, which keeps a shared reference, so either can be destroyed first. A block manager serves one chainstate manager. btck_block_read and btck_block_spent_outputs_read take the block manager. Each options object takes the total database cache and uses its part. Wiping the block tree db also wipes the chainstate db.
Add a block manager prune option and btck_block_manager_prune_up_to_height. The option also lets the kernel open data directories Bitcoin Core has pruned. The chainstate manager created with the block manager decides what may be deleted, so pruning fails without one. Pruning writes only block storage. It keeps blocks above the last chainstate flush, which the chainstate on disk may still need after an unclean shutdown, and reports when it did. Add btck_chainstate_manager_flush to flush before pruning again. Add a fast prune option for tests, since test chains never fill a 128 MiB block file.
An application that reads blocks after they are connected needs them kept until it has read them. Add block manager functions to set and delete prune locks.
The kernel needs the room FindFilesToPrune keeps below a prune target.
An application that wants block storage kept below a size would have to pick prune heights itself. Add btck_block_manager_prune_to_target, which deletes the oldest blocks until usage is below a target and keeps the same blocks as btck_block_manager_prune_up_to_height. The kernel never prunes on its own, so the caller decides when. Target pruning uses BeginManualPrune. BeginTargetPrune only proceeds after a new block file is allocated, and the periodic flush in block processing already consumes that.
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. LLM Linter (✨ experimental)Possible places where comparison-specific test macros should replace generic comparisons:
2026-11-13 15:38:38 |
Contributor
|
🐙 This pull request conflicts with the target branch and needs rebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This adds more of the pruning API discussed in #35627:
btck_block_manager_update_prune_lockandbtck_block_manager_delete_prune_lockkeep blocks at and above a height until the application deletes the lock. Like the node's prune locks, they are held in memory, so an application sets them again after a restart before it prunes.btck_block_manager_prune_to_targetdeletes the oldest block files until usage, with room for the next allocation, is below a target. It keeps the same blocks asbtck_block_manager_prune_up_to_height. Unlike-prune, the target has no minimum, and pruning doesn't wait for the chain to reach a minimum height.Target pruning uses
BeginManualPrune.BeginTargetPruneonly proceeds after a new block file is allocated, and the periodic flush during block processing already consumes that, so it would never prune.Names the buffer
FindFilesToPrunekeeps below a target. The kernel uses it to tell whether a flush would help.Based on #36856. Draft until it is merged.