Review report

core: PR #35837

1 minor finding · 4 suggestions

Findings

Link

[minor] · A healthy index is reported as corrupt during assumeutxo validation

With an assumeutxo snapshot loaded, a scan extending beyond the background chain’s tip receives a corruption error, even though the index is still building.

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

Details and suggested fix

With an assumeutxo snapshot loaded, the filter index follows the validated background chainstate and ignores block-connected events from the snapshot chainstate. BlockUntilSyncedToCurrentChain() can therefore return true once the index reaches the background chain’s tip, while scanblocks takes its default stop block from the active snapshot chain. When the scan reaches a height beyond the background tip, LookupRange fails and the RPC reports index corruption. This can occur with the default scanblocks start [...] range. The scan is correctly refused, but a client that retries only on error code -1 may give up because it receives -32603 instead. The error continues until background validation reaches the snapshot block and the index catches up. The same classification occurs in getblockfilter and REST, but this error is new for scanblocks. Classify a failed lookup using the index’s actual coverage, such as whether end_range is an ancestor of the index’s best block from index->GetSummary(), and return the retryable “still being indexed” error when the requested range is not covered. A deterministic state for testing is available in feature_assumeutxo.py: n1 has -blockfilterindex=1, its background chain is at START_HEIGHT, and its snapshot chain is ahead. This is a static trace and has not been reproduced.


Optional improvements

Link

[suggestion] · Unsynced-index test coverage can skip the behavior it is meant to verify

If the rebuild finishes before the conditional checks, the test passes on unfixed code; it also does not require a successful prefix scan while the index is behind.

Location: test/functional/rpc_scanblocks.py:170 (head).

Details and suggested fix

All assertions about unsynced behavior are inside if not bfi()["synced"]:. Index synchronization starts in the init-load thread before start_node returns, so if the 3000-block rebuild finishes first, the test skips those assertions and reaches a final scan that also passes on the base code. The checks inside the branch are not sufficient either: the tip scan accepts a successful return, and the prefix loop retries the indexing error until sync completes, so it can finish without a successful genesis-only scan. Thus, an implementation that rejects every scan while unsynced could pass even though already-indexed ranges should remain usable. Hold indexing at a known height below the tip, using a test-only pause or a unit-level RPC fixture. While indexing is held, require an indexing error for the unavailable range and a successful scan of the indexed prefix. Then release indexing and retain the post-sync match check. This also avoids needing 3000 padding blocks.


Link

[suggestion] · A scan reads covered filters before failing on an unavailable range

During an index rebuild, a scan to the tip can read covered filters and then discard its results when it reaches an unavailable range.

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

Details and suggested fix

In the described scenario, the index is rebuilding and the caller scans to the tip. Although index_ready is false, the loop reads and matches each 10000-block chunk that the index covers. With filter_false_positives, it also reads full blocks for matches. The scan throws at the first chunk beyond the indexed height, discards relevant_blocks, and holds the single BlockFiltersScanReserver slot until then. Unless indexing finishes first, the caller gets the same retryable error it could have received immediately. One option is to check before the loop whether stop_block is covered by the index’s best block from index->GetSummary() and fail immediately when it is not. Another is to include the last fully scanned height in the error so callers can resume there. A pre-check can reject scans that the current code would complete if the index advances during the scan, such as when it is only a few blocks behind after a restart. Whether failing fast is worthwhile depends on how often these cases occur.


Link

[suggestion] · Indexing-error tests do not check the RPC error code

The test checks the indexing-error message but would pass if the RPC returned a different error code.

Location: test/functional/rpc_scanblocks.py:175 (head).

Details and suggested fix

Both exception handlers in the new test check only that the message contains “still in the process of being indexed.” The change concerns error classification: RPC_MISC_ERROR (-1) while the index is behind, and RPC_INTERNAL_ERROR (-32603) once it reports ready. Add assert_equal(e.error["code"], -1) to both handlers, retaining the existing retry behavior in the prefix loop.


Link

[suggestion] · The scanblocks error behavior change is not documented for callers

Callers that previously received completed: true during index sync now receive errors, but the change does not tell them to retry.

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

Details and suggested fix

scanblocks start previously returned completed: true when it could not read a filter range. It now throws RPC_MISC_ERROR (-1) while the index is behind and RPC_INTERNAL_ERROR (-32603) otherwise. doc/developer-notes.md calls for a release note when a change affects visible behavior, and comparable RPC changes that now raise errors include one. Add a short release note stating that scanblocks now errors instead of silently skipping ranges that are not yet indexed, listing both error codes and telling callers to retry once the index has synced.


Coverage details