1 major finding · 3 minor findings · 2 suggestions
Findings
[major] · Startup pruning can run before the configured prune lock is registered
With automatic pruning, a restart can delete blocks at or above -prunelockheight before the startup lock is registered, forcing affected wallet rescans to wait for those blocks to be re-downloaded.
Location: src/init.cpp:2132 (head).
Details and suggested fix
AppInitMain calls PruneAndFlush() before registering the user:init lock, and the initload thread can also prune during that interval. The prune limit uses only locks already in m_prune_locks, so startup pruning ignores -prunelockheight. With automatic pruning (-prune>=550), when block usage plus the buffer reaches the target, pruning can delete eligible files at or above the requested height if they are more than 288 blocks below the tip. On a restart with the same option, this can remove blocks that a previous startup or RPC lock protected. An unloaded wallet that needs those blocks then fails to load with “last wallet synchronisation goes beyond pruned data” until the blocks are re-downloaded. When the option has no value, the tip height is also read after initload may have connected more blocks. Resolve the height and register the lock immediately after index Init(), before step 10, where index prune locks are installed. Add a restart test with an automatic target already exceeded and verify that the protected blocks remain readable.
[minor] · A reorg lowers a future-height prune lock to the fork point
A reorg can activate a lock set above the tip immediately, capping pruning near the fork point and retaining blocks beyond the prune target until the user resets the lock.
Location: src/rpc/blockchain.cpp:974 (head).
Details and suggested fix
setprunelock accepts heights above the tip, and its help says the lock takes effect once the chain reaches that height. However, DisconnectTip() lowers every prune lock above the disconnected block's parent to the parent's height. Reconnecting blocks does not restore the requested height. For example, a lock at 1,000,000 with a tip at 900,000 becomes 899,999 after a stale tip is replaced or invalidateblock is called. Pruning is then capped near height 899,988, so new blocks are retained and disk use can exceed the -prune target until the user notices the changed height in listprunelocks and resets the lock. A future height passed to -prunelockheight behaves the same way. The move-back behavior already existed for index locks, which never sit above the tip; this change also puts user locks above the tip into the map. In DisconnectTip(), skip locks above the disconnected block's height so only locks at that height move back. Add a reorg test for this behavior.
[minor] · -noprunelockheight creates a tip lock instead of disabling the option
Using -noprunelockheight to override a config-file entry adds a lock at the tip when pruning is enabled, but aborts startup when pruning is disabled.
Location: src/init.cpp:1040 (head).
Details and suggested fix
-prunelockheight allows negation, so -noprunelockheight is accepted and stored as false. IsArgSet() still returns true, and GetIntArg() converts the value to 0, so both new checks treat the option as set. Without -prune, startup fails with “-prunelockheight is only possible in prune mode.” With -prune, the zero-height branch creates user:init at the tip. A user passing -noprunelockheight to override a prunelockheight= entry in bitcoin.conf therefore gets a lock that retains new blocks and can push disk use beyond the prune target until the lock is removed with setprunelock. Treat IsArgNegated("-prunelockheight") as unset in both checks.
[minor] · Out-of-range -prunelockheight values narrow to unrelated heights
The startup value is narrowed to int before validation, so out-of-range input can select an unrelated lock height or bypass the negative-value check.
Location: src/init.cpp:2133 (head).
Details and suggested fix
GetIntArg() returns int64_t, but the result is assigned to int lock_height before validation. Values outside the int range wrap: -prunelockheight=4294967296 becomes 0 and selects the tip, while 4294967297 becomes 1 and effectively stops pruning. -4294967295 also becomes 1 and passes the negative-value check. The setprunelock RPC does not have this issue because getInt<int>() rejects out-of-range values. Read the setting as int64_t and reject values below 0 or above std::numeric_limits<int>::max() with InitError before converting. Parsing with ToIntegral<int> would also reject non-numeric input, which currently becomes 0 and selects the tip. This requires an out-of-range operator-supplied value, so it is unlikely in practice, but the result is a lock at an unrelated height without an error.
Optional improvements
[suggestion] · Listed prune-lock IDs do not round-trip through setprunelock
Clients must strip an internal prefix to remove listed locks, and IDs beginning with user: can cause a client to remove a different lock.
Location: src/rpc/blockchain.cpp:1002 (head).
Details and suggested fix
setprunelock always prepends user: to the caller's ID, while listprunelocks returns the stored key unchanged. A lock added as foo is listed as user:foo; passing that ID to setprunelock "user:foo" remove looks up user:user:foo and fails. Using it with add instead creates a second lock and leaves the original in place. The release note also lists the startup lock as user:init but says to remove it as init. Because IDs beginning with user: are accepted, foo and user:foo can both exist, and passing the listed ID of the first can remove the second. Unlike setban and listbanned, where a listed address can be passed directly back, these prune-lock IDs require transformation. In setprunelock, store an ID that already starts with user: as-is rather than prefixing it again. Listed user IDs will then round-trip, double-prefix collisions will be avoided, and internal locks such as index names and dumptxoutset-rollback will remain unreachable.
[suggestion] · Omitting the setprunelock height disables pruning, unlike the startup option
The RPC treats an omitted height as 0 and stops automatic pruning, while -prunelockheight treats 0 as the current tip; the RPC help does not explain the disk-use consequence.
Location: src/rpc/blockchain.cpp:979 (head).
Details and suggested fix
The setprunelock height argument defaults to 0 and is described as “only required for ‘add’.” Calling setprunelock foo add without a height therefore creates a lock at height 0. FlushStateToDisk converts that to a pruning limit of 1, which stops automatic pruning while the lock exists. By contrast, an omitted or zero -prunelockheight locks at the current tip. The RPC help also omits the warning in the startup-option help that a lock can push disk use beyond the -prune target. The functional test relies on the RPC default to disable pruning, so this appears intentional, but callers familiar with one interface can get the opposite behavior from the other. Require a height for add to remove the ambiguity, and add the prune-target warning to the RPC help.