1 suggestion
Optional improvements
[suggestion] · scanblocks treats concurrent chain shortening as an internal bug
A concurrent authenticated invalidateblock can make scanblocks report a chain change as an internal bug rather than explain why the scan stopped.
Location: src/rpc/blockchain.cpp:2719 (head).
Details and suggested fix
scanblocks requires a filter index and saves stop_block once, but resolves each intermediate chunk end against the current active chain under a fresh cs_main lock. If invalidateblock shortens that chain below start_block + amount_per_chunk while this height remains below the saved stop height, CChain::operator[] returns null. The scan reservation does not exclude this operation, and InvalidateBlock releases cs_main between disconnects. In Release builds, the new check then returns an RPC error saying “Internal bug detected” and “Please report this issue”, without partial results. With ABORT_ON_FAILED_ASSUME, including Debug configurations, or fuzzing build mode, the check aborts instead. Ordinary reorgs generally keep cs_main locked through reconnection until the chain makes forward progress. The base revision already dereferenced this null in LookupRange, so the PR improves that path; this is a suggestion about the newly added failure handling, not a regression claim. Replace the check with if (!end_range) throw JSONRPCError(RPC_MISC_ERROR, "Active chain changed during scan"); before dereferencing end_range. This preserves the non-null reference contract while reporting the chain change explicitly.