Skip to content

rpc: fail scanblocks instead of silently skipping missing filters - #37016

Open
shivansh023023 wants to merge 1 commit into
bitcoin:masterfrom
shivansh023023:fix/scanblocks-lookup-error
Open

shivansh023023 wants to merge 1 commit into
bitcoin:masterfrom
shivansh023023:fix/scanblocks-lookup-error

Conversation

@shivansh023023

Copy link
Copy Markdown

Problem

In scanblocks (src/rpc/blockchain.cpp), when BlockFilterIndex::LookupFilterRange returns false, the chunk loop silently skips the failed range, advances start_index, and finishes with "completed": true and to_height set to stop_height.

This causes silent false negatives in two realistic scenarios:

  1. Unsynced index: A user enables -blockfilterindex=1 on an existing node and runs scanblocks start while the index is still catching up. Unindexed chunks are dropped without error, returning an empty or partial relevant_blocks list marked "completed": true.
  2. Missing/corrupt filter files: If a fltr*.dat file is missing or unreadable, scanblocks hides the read failure instead of reporting it (unlike getblockfilter, which throws an error).

Because scanblocks is used to discover wallet history from descriptors, silently returning "completed": true on missing filters can mislead callers into concluding no activity exists.

Solution

Mirror getblockfilter's error-handling pattern in scanblocks:

  • Call index->BlockUntilSyncedToCurrentChain() before acquiring cs_main (preserving the ability to scan already-indexed historical ranges while the index is still catching up).
  • In the chunk loop, if index->LookupFilterRange(...) returns false:
    • Throw RPC_MISC_ERROR ("Block filters are still in the process of being indexed.") if the index is not yet synced.
    • Throw RPC_INTERNAL_ERROR indicating a filter read failure / index corruption otherwise.

BlockFiltersScanReserver is already RAII-managed, so throwing out of the loop cleanly releases the active scan reservation.

Tests

  • Unit test (src/test/rpc_tests.cpp — scanblocks_unsynced_index): Registers an unstarted BlockFilterIndex, verifies scanblocks start throws RPC_MISC_ERROR with the expected message, confirms a second call is not blocked by a stale scan reservation, and checks scanblocks status returns null.
  • Functional test (test/functional/rpc_scanblocks.py): Stops the node, moves fltr00000.dat, restarts, verifies scanblocks start fails with -32603 (RPC_INTERNAL_ERROR), verifies scanblocks status returns None, then restores the file and confirms the scan succeeds again.
  • Both tests fail on master without the src/rpc/blockchain.cpp change and pass with the fix.

@DrahtBot

DrahtBot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36986 (rpc, wallet: Convert walletprocesspsbt to use options parameter by jeanpablojp)
  • #35837 (rpc: fail scanblocks when block filter range is unavailable by MicSm)
  • #35713 (Remove boost as a unit test runner by rustaceanrob)
  • #35229 (refactor: Use CBlockIndex parameters as reference by optout21)
  • #33741 (rpc: Optionally print feerates in sat/vb by polespinasa)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • src/test/rpc_tests.cpp: MakeIndex<BlockFilterIndex>(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true)

2026-11-30 05:45:20

@pinheadmz

Copy link
Copy Markdown
Member

Thanks for your submission! The description and code changes match a pattern we sometimes see with PRs that lean heavily on LLM coding assistants. Because the project has such limited human resources for code review, we require code generated by LLMs to be reviewed by the author who submits them first.

It would help to know why you decided to open this PR (did you encounter a bug? find an open issue in repo?), how you reviewed the generated code, what you personally understand about it, how you tested the code before and after the change, etc.

If you don't understand the changes you submitted, we should close this PR. There are many other more helpful ways to contribute to the project, and we look forward to working with you there!

Please also reconsider the value of the PR given how limited our resources are for code review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants