2 minor findings · 2 suggestions
Findings
[minor] · Snapshot activation can leave the ASSUMED blockfile cursor unset
If a block above the snapshot base was stored before activation and no later above-base block is written, background validation can abort when writing undo data; this narrow trigger is mainly RPC-driven or isolated.
Location: src/node/blockstorage.cpp:801 (head).
Details and suggested fix
ActivateSnapshot() sets m_snapshot_height but does not initialize the ASSUMED blockfile cursor. FindNextBlockPos() initializes that cursor lazily, while WriteBlockUndo() asserts that it exists. If a block above the base was stored before snapshot activation, it was written using the NORMAL cursor but is later treated as ASSUMED. When the base is linked, background validation can connect that block and abort in WriteBlockUndo() if no later above-base block has initialized the ASSUMED cursor.
One sequence already failed before this change: both the base and the block above it were stored before loadtxoutset(). The change also introduces a regression when the block above the base is stored before activation and the base arrives afterwards. Under the previous >= boundary, writing the base initialized the ASSUMED cursor; under the new > boundary, the base uses the NORMAL cursor. A restart rebuilds the cursors, and downloading a later above-base block over P2P also initializes the ASSUMED cursor, so no unauthenticated-peer path forcing the abort was established. Initialize the ASSUMED cursor in ActivateSnapshot() alongside m_snapshot_height. On regtest, the default -checkblockindex also asserts on the unlinked block in both revisions, so a regression test for this sequence needs -checkblockindex=0.
[minor] · verifychain reports success after stopping at the snapshot base
When level 3 or 4 verification reaches a snapshot base with block data, verifychain can return true without checking the requested depth below that base.
Location: src/validation.cpp:4710 (head).
Details and suggested fix
When the snapshot chainstate's level 3 or 4 verification walk reaches its base and the base has block data, the new break does not set skipped_no_block_data or skipped_l3_checks. VerifyDB() therefore returns SUCCESS, which verifychain reports as true, even though it did not check the requested depth below the base. For example, when the snapshot tip is the stored base, verifychain 4 0 returns true. Set skipped_no_block_data, or a dedicated flag, before breaking. Startup already accepts SKIPPED_MISSING_BLOCKS, and level 4 will still reconnect blocks above the base because pindex remains at the base.
Optional improvements
[suggestion] · The restart in the new test masks the missing-cursor failure
The test would still pass with the old >= boundary, so it does not cover the no-restart abort; the described trigger is not reached by the test as written.
Location: test/functional/feature_assumeutxo.py:242 (head).
Details and suggested fix
The test restarts node4 immediately after loadtxoutset(), before feeding any historical blocks. On restart, LoadBlockIndexDB() rebuilds the cursors from each file's nHeightLast. With the old >= rule, node4's file containing heights 0–199 and the base at 299 would initialize the ASSUMED cursor, so WriteBlockUndo() would find a cursor under either boundary rule.
The test covers the VerifyDB, m_blocks_unlinked, and candidate changes, but not the boundary change. On the base revision, startup fails at the VerifyDB error before reaching WriteBlockUndo(), so the claim that the test exercises both failures does not hold. The existing node1 case also misses the trigger because it writes above-base blocks before submitting the base, thereby initializing the ASSUMED cursor. Add a no-restart case on fresh node state: submit the base, call loadtxoutset(), feed blocks from START_HEIGHT+1 through SNAPSHOT_BASE_HEIGHT-1, and wait for background validation to complete. Keep the restart case as well.
[suggestion] · Loading the block index can duplicate an unlinked base entry
Direct insertion bypasses AddUnlinkedBlock()'s duplicate check if the index is loaded again in the same state; no current production path was identified that reloads it this way.
Location: src/node/blockstorage.cpp:500 (head).
Details and suggested fix
The new branch inserts directly into m_blocks_unlinked, while the adjacent branch uses AddUnlinkedBlock(), which skips an existing (pprev, block) pair. LoadBlockIndex() does not clear m_blocks_unlinked and can run more than once on the same BlockManager. If a second load finds the base stored but its parent unprocessed, it can add a duplicate. CheckBlockIndex asserts that there are no duplicates, and a duplicate can also let ReceivedBlockTransactions() re-add a candidate with a new nSequenceId. Use AddUnlinkedBlock(pindex) in this branch to retain its deduplication. The production reload in node/chainstate.cpp runs without a snapshot hash, so no current production path that creates the duplicate was identified.