2 minor findings · 6 suggestions
Findings
[minor] · A reorg lowers manual prune locks whose heights were never reached
A reorg lowers future-height manual locks and leaves extra retention until they are reset; no in-tree production caller creating these locks was found.
Location: src/rpc/blockchain.cpp:1001 (head).
Details and suggested fix
At tip 1500, setprunelock app add 100000 stores 100000, but disconnecting the tip, including via invalidateblock, changes it to 1499. DisconnectTip applies its existing consumer-progress rewind even when a user lock's requested height has never been reached, contrary to the new help. ConnectTip does not restore user locks. Once recent-block retention no longer dominates, the lowered boundary retains additional files between the lowered and requested boundaries and can cause the node to exceed its prune target earlier than requested. Updating or removing the lock, or restarting, clears the effect. Skip the rewind for user locks above the disconnected block's height while preserving rewind protection for active consumers, and add an above-tip invalidateblock regression test.
[minor] · -prunelock takes effect after IPC block submission is enabled
On multiprocess nodes using -ipcbind and automatic pruning, a valid-PoW block submitted during an over-target restart can prune history before -prunelock registration; no occurrence has been observed.
Location: src/init.cpp:2056 (head).
Details and suggested fix
InitAndLoadChainstate publishes chainstate_loaded before index initialization and wallet loading, releasing MakeMining waiters while the configured locks are still absent. A trusted local IPC client can then call submitBlock, which reaches ProcessNewBlock and AcceptBlock without another startup barrier. If writing that block allocates a new chunk, it requests pruning, and AcceptBlock calls FlushStateToDisk(NONE). With indexed block files, sufficient eligible history, and no other lock preventing deletion, this can remove files before the registration loop runs. Installing the lock afterwards cannot recover them. Register the configured locks inside InitAndLoadChainstate before publishing readiness, so each initialization attempt installs them before accepting IPC submissions.
Optional improvements
[suggestion] · listprunelocks exposes storage ids rather than RPC ids
A listed manual lock's id cannot be passed directly to setprunelock; the extra prefix can target another valid manual lock instead.
Location: src/rpc/blockchain.cpp:981 (head).
Details and suggested fix
After setprunelock app add, the listing returns user:app, but setprunelock user:app remove looks for user:user:app. It normally reports not-found; if a client separately created the valid RPC id user:app, it removes that other lock instead. Cleanup clients must therefore recognize the storage namespace and strip exactly one prefix. Keep the internal prefix for system-lock isolation, but expose the public RPC identifier separately for manual entries, for example as user_id, and test a list-to-remove round trip.
[suggestion] · Startup and RPC prune locks accept different identifier sets
An RPC id such as wallet:w1 cannot be reused in -prunelock, although every accepted startup id is manageable through the RPC.
Location: src/init.cpp:1044 (head).
Details and suggested fix
setprunelock accepts any nonempty id, but -prunelock=wallet:w1 fails initialization because startup additionally rejects :. An application using that runtime name must introduce a different startup guard instead of pre-creating its own lock. Both paths already prepend user:, so accepting colons at startup preserves system-lock isolation. Share an identifier validator between the two entry points, allow the same names in both, and add matching boundary tests.
[suggestion] · The height description obscures the default's pruning effect
The help labels height both optional and “only required for add”, without explaining that omission intentionally retains all remaining block data and may exceed the prune target.
Location: src/rpc/blockchain.cpp:1006 (head).
Details and suggested fix
Although generated help displays optional, default=0, the appended description suggests that add requires a height. The implementation instead accepts omission and creates a height-zero lock, as the functional test intentionally checks. Replace the contradictory description with wording that height is optional, is used for add, and defaults to zero to prevent pruning of remaining block data. This makes the storage consequence explicit without changing acceptance.
[suggestion] · The startup-lock test never exercises automatic file deletion
The -prunelock startup test uses -prune=1 and asserts log order, so it cannot detect an automatic-pruning path that deletes protected files while the lock remains listed.
Location: test/functional/rpc_prunelock.py:207 (head).
Details and suggested fix
-prune=1 maps to PRUNE_TARGET_MANUAL, the maximum uint64_t target. This fixture cannot reach that target, so startup pruning deletes nothing with or without the lock. The registry assertions and log-order check cover installation, while the file-retention assertions exercise the manual RPC path. Add an automatic-pruning contrast using the large-chain fixture in the extended feature_pruning.py test: establish sufficient height, over-target usage, and an eligible old file; restart with -prunelock and verify its data remains readable; then restart without the lock and verify the same data is pruned. This tests observable retention without adding the large fixture to the default suite.
[suggestion] · Mixed user and index lock behavior lacks coverage
The new RPC test enables no index, so filtering internal locks from listprunelocks or allowing a manual operation to alter a same-named index lock would go undetected.
Location: test/functional/rpc_prunelock.py:54 (head).
Details and suggested fix
The multiple-lock assertions cover only user:testlock and user:another, whereas indexes register unprefixed names through BaseIndex::SetBestBlockIndex. Add a separate fixture with coinstatsindex enabled before any pruning and wait for it to sync. Create a manual coinstatsindex lock and assert that both entries are listed. Remove the manual lock and verify that the internal entry remains unchanged, then repeat the removal and expect not-found. This checks both the all-lock listing contract and user/internal isolation.
[suggestion] · RPC fuzzing retains every distinct manual prune lock
Successful setprunelock add inputs accumulate variable-length ids in the static RPC fuzz fixture, increasing retained memory and later listprunelocks costs without a session-wide bound.
Location: src/test/fuzz/rpc.cpp:178 (head).
Details and suggested fix
The fixture survives across inputs, and neither the normal nor exception path removes newly created locks. Each distinct successful id therefore adds a retained map entry, and listing copies the entire accumulated map. The harness already carries state such as prioritisation deltas, but the new entries can retain directly generated strings of up to 4096 bytes rather than fixed-size txids. Exercise add/list/remove within a bounded input and clean up its generated user locks on scope exit, leaving internal locks untouched. Memory usage and exhaustion timing have not been measured.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Pruning separates the data needed for ongoing validation from the historical archive needed by other applications. Its storage target has always been conditional on retaining necessary recent data, rather than an unconditional disk-space ceiling.
The base deletes block and undo files while retaining chainstate and block-index information. Its pruning routines delete only eligible files. The new manual locks add retention constraints to that existing storage policy; they do not change consensus validation rules.
A node can continue validating while a wallet or index loses the historical data required to catch up. The original prune-lock proposal explicitly targeted unloaded Core wallets, external wallets, temporarily disabled indexes, and external indexing applications.
The base wallet-loading path refuses a rescan when required blocks are unavailable. The head exposes the existing retention mechanism to applications and operators, and its unloaded-wallet test demonstrates preserving the wallet's unscanned interval. Earlier wallet work also distinguished usable imports without rescanning from rescans requiring retained historical blocks.
The generic lock registry was introduced to let data consumers communicate their progress without making validation depend separately on every index implementation.
The base's BaseIndex::SetBestBlockIndex updates a named lock, and FlushStateToDisk combines lock heights before selecting files. #21726 explicitly motivated this arrangement by avoiding additional index dependencies and circular dependencies in validation. The manual RPCs reuse this consumer-to-storage coordination mechanism.
Operator control over application-created retention requests was deliberate: obsolete applications must not leave the user unable to reclaim storage.
The historical #19463 proposal expressly allowed users to delete application locks because the application might no longer be used. The head's add/update/remove interface gives operators that lifecycle control for manual locks. Its user-prefixed identifiers distinguish those requests from system-managed locks, so the historical statement should not be read as documenting unrestricted removal of internal locks in this implementation.
Prune-lock heights are not necessarily monotonic: reorganizations can move a consumer's required history backwards. Historical discussion also introduced a small retention buffer before the deepest lock to make the mechanism more robust.
Both base and head subtract a ten-block buffer and an additional boundary block when deriving the pruning limit. In #21726, moving locks backwards was defended as no inherently worse than creating a new lower lock; consumers still had to handle already-pruned data safely. This explains why a retention request is not a promise to restore missing history or tolerate arbitrarily deep reorganizations.
Source 1 · Source 2 · Source 3
The historical split between internal locks and externally managed locks was initially a scope decision, not a documented conclusion that external coordination was unnecessary forever.
#21726 focused on synchronizing internal indexes and explicitly omitted the broader proposal's RPCs, persistence, and bounded ranges. The #19463 author temporarily closed that effort in favor of #21726 while stating that its additional functionality could be added later. This is the historical background to the base having internal locks before the head adds a manual interface.
Source 1 · Source 2 · Source 3
Ralph's inferences
Manual retention makes an application's availability requirement explicit, but transfers responsibility for advancing or releasing that requirement to the application or operator. Storage use and rescan availability therefore remain competing objectives.
The pinned pruning path applies the most restrictive active lock to both automatic and manual deletion. A lagging manual lock can consequently retain files despite the configured storage target. This interpretation follows from the historical consumer-progress model and operator-cleanup motivation; it is not a historical guarantee about application behavior.
A startup-created lock provides a conservative handoff between node startup and an external application's later declaration of its actual progress.
The base already performs an initial prune after loading startup wallets. The head inserts height-zero user locks before that prune, allowing a later RPC to advance or remove them. Given the historical aim of protecting external and inactive consumers, this ordering can be understood as preserving data until those consumers participate, rather than relying on them to connect before startup maintenance. This is an inference from pinned code, not an independently documented historical explanation of the new option.
Unresolved disagreements
Historical participants differed over the relative value of retaining history in advance versus retrieving selected blocks when needed. One participant favored redownloading and questioned whether an unloaded-wallet lock effectively pauses pruning; the proposer replied that repeated downloads are undesirable and that locks could also prevent freshly downloaded blocks from being immediately pruned.
The head implements advance retention, not historical-data recovery. The inspected exchange establishes the bandwidth/storage/usability tension and acknowledges complementary uses, but does not resolve a general preference between those approaches. It should not be treated as an objection establishing a defect in the present behavior.