Review report

core: PR #34534

1 major finding · 2 suggestions

Findings

Link

[major] · Startup pruning ignores -prunelockheight

With automatic pruning, a restart can delete blocks that -prunelockheight is meant to protect before the startup lock is registered.

Location: src/init.cpp:2132 (head).

Details and suggested fix

During startup, PruneAndFlush() runs before the user:init lock is registered. The prune therefore ignores -prunelockheight and can delete block files at or above the requested height, provided they are more than 288 blocks below the tip. For example, if a lock previously kept storage above the automatic-pruning target, restarting with the same options can prune those files before restoring the lock. An unloaded wallet that needs the blocks will fail to load until they are re-downloaded. Register the startup lock before the initial prune and before the initload thread starts. Add a restart test with automatic pruning over target that verifies protected blocks remain readable; the current init tests use -prune=1, where automatic pruning does not run.


Optional improvements

Link

[suggestion] · Listed prune-lock IDs do not round-trip through setprunelock

Clients must strip the user: prefix when removing a listed lock, and IDs that already start with that prefix can cause removal of a different lock.

Location: src/rpc/blockchain.cpp:951 (head).

Details and suggested fix

setprunelock prepends user: to the supplied ID, while listprunelocks returns the stored key unchanged. Thus, a lock created as foo is listed as user:foo, but passing that listed ID back to remove it looks up user:user:foo and fails. Since IDs beginning with user: are accepted, foo and user:foo can coexist; removing the listed ID of the first can then remove the second instead. The release note also says to remove the startup lock using init, even though it is listed as user:init. Use IDs already beginning with user: as stored keys rather than prefixing them again, so listed user IDs round-trip and internal locks remain unreachable.


Link

[suggestion] · A reorg lowers a future-height prune lock below its requested height

Although the RPC help says a lock above the tip takes effect when the chain reaches that height, a tip reorg can lower it immediately and cause pruning to stop well below the target.

Location: src/rpc/blockchain.cpp:974 (head).

Details and suggested fix

setprunelock accepts heights above the tip and says they take effect once the chain reaches that height. On a tip reorg, however, DisconnectTip() lowers any lock above the disconnected block's parent to the parent's height, and reconnecting blocks do not restore the requested height. For example, a lock at 1,000,000 with a tip at 900,000 becomes 899,999 after one stale tip is replaced. Pruning then stops around height 899,988 until the user notices the change in listprunelocks and updates the lock, allowing disk use to exceed the -prune target before the requested height is reached. Reject heights above the tip or document that reorgs can lower them, and add a reorg test for the chosen behavior.


Coverage details