1 minor finding · 5 suggestions
Findings
[minor] · Storage exceptions escape the pruning C API
A local storage exception during an eligible prune bypasses the documented error return and fatalError; no current test or caller producing a block-tree write failure was found.
Location: src/kernel/bitcoinkernel.cpp:1345 (head).
Details and suggested fix
Once file selection is nonempty, SetHavePruned() can throw dbwrapper_error from WriteFlag(), and WriteBlockStorage() can throw from the index write or fs::space(). Its Expected result covers only low-space and flat-file flush failures. Unlike FlushStateToDisk(), this path has no exception handler, so it bypasses the documented non-zero return and can terminate C/FFI callers. Catch storage exceptions around selection and writing, report them through FatalError(...), and return -1. Treat these as fatal rather than ordinary retryable failures: selection has already changed pruning metadata, and a failed index write has discarded its dirty entries. A C-API database-write failure test would cover the path that the existing blk-file open-failure test does not reach.
Optional improvements
[suggestion] · An in-memory flush satisfies the durable pruning bound
With an in-memory coins database and disk-backed block storage, pruning can remove blocks needed for rebuilding after restart; the API does not define whether this combination is disposable-only.
Location: src/kernel/bitcoinkernel.cpp:1336 (head).
Details and suggested fix
InitCoinsDB() selects NewMemEnv for chainstate_db_in_memory, but a successful Flush() still advances m_last_flushed_block. The pruning bound therefore accepts that flush even though the UTXO state does not survive teardown. Once eligible block files are deleted, rebuilding that state requires block data no longer available locally, including after a clean shutdown. Reject this combination at creation or prune time unless disposable use is intentional. If it is intentional, document the recovery exception in the prune and flush APIs and test that contract. Neither choice requires an implicit chainstate write during pruning.
[suggestion] · Wipe-plus-prune file deletion is missing from the API docs
Combining pruning and block-tree wiping deletes block and undo files during block-manager creation, before import or manual pruning, but the new option docs describe only database wiping.
Location: src/kernel/bitcoinkernel.h:1255 (head).
Details and suggested fix
With both options enabled, the constructor runs CleanupBlockRevFiles(), removing every rev?????.dat and every blk?????.dat after the first gap in the sequence starting at zero. If blk00000.dat is absent, all existing block files are removed, so the caller must supply the chain's blocks again. This is existing node cleanup newly exposed through the kernel API; the removed block-file suffix was already unusable by sequential reindexing. Document the creation-time deletion and external-block requirement in the wipe and prune option descriptions, rather than leaving callers to discover them when invoking btck_block_manager_create().
[suggestion] · NEEDS_FLUSH can be set when no file is held back
The height-only status can prompt a forced coins-cache sync even when flushing cannot make another file eligible for deletion.
Location: src/kernel/bitcoinkernel.cpp:1338 (head).
Details and suggested fix
flushed_height < max_height sets NEEDS_FLUSH before examining file boundaries. For example, if a small-block chain occupies a single file extending above max_height, neither the requested bound nor the flushed bound permits deleting that file. The header already says another prune only “may” delete blocks, but its status description still says blocks were kept because they were not flushed past. Document this as a conservative height-bound status rather than evidence that a file was withheld, so callers can decide whether to perform a potentially unproductive FORCE_SYNC. This leaves the safety bound unchanged.
[suggestion] · Reorg recovery after a persisted prune is not tested
The reorg fixture checks in-process readability but never reloads a persisted prune while the coins database still points to the stale branch.
Location: src/test/kernel/test_kernel.cpp:1446 (head).
Details and suggested fix
The fixture forks at height 16, below blk00000.dat's highest block, so its first NEEDS_FLUSH prune selects no files and never writes pruning metadata. It checks retained data in-process, then explicitly flushes; ordinary destruction force-flushes as well. Add a case with a fork above an eligible closed file and assert that pruning deletes the file while the coins database remains at the stale tip. Terminate a subprocess without running the chainstate-manager destructor, then reopen the directory and assert recovery to the new tip. That exercises disconnecting the stale branch and connecting the retained new branch against persisted pruning metadata.
[suggestion] · Deleting prunes do not test the no-chainstate-flush invariant
The kernel prune tests delete files only immediately after an explicit flush, so they do not detect a chainstate sync added only to the deleting path.
Location: src/test/kernel/test_kernel.cpp:1376 (head).
Details and suggested fix
The existing pre-flush attempts select no files, so their NEEDS_FLUSH assertions do not distinguish a storage-only write from a coins sync performed only after a nonempty selection. Flush at height F after a closed file ends below F, then extend without flushing until tip - 288 > F. Prune and assert both deletion of the old file and NEEDS_FLUSH. Prune again without processing another block and require NEEDS_FLUSH again. An implicit sync on the deleting path would advance the flushed bound to the tip and make the second result OK, so this public-API test would detect that regression.