rpc: fail scanblocks when block filter range is unavailable #35837

Open
MicSm wants to merge 1 commit from rpc/scanblocks-require-synced-index into master AGit
MicSm commented 2026-07-29 18:17:55 +00:00 (Migrated from github.com)

The issue

scanblocks reads block filters over a range via LookupFilterRange. When the
block filter index is behind the active chain (e.g. right after startup, while
it is still syncing in the background), the lookup for the not yet indexed range
fails. The old code ignored that failure, advanced start_index to the end of
the chunk, and kept going - so the scan skipped every unindexed block and still
returned "completed": true.

The result is a silent gap: a caller gets a relevant_blocks list that looks
fine but is missing any match in the unindexed range, with no way to
distinguish "no matches" from "range was never scanned".

Note that "completed" only means the scan was not aborted - it does not mean
every filter in the requested range was actually read.

Steps to reproduce

  1. Start a node with -blockfilterindex=1 and let it mine/receive some blocks.
  2. Stop the node, delete <datadir>/<chain>/indexes/blockfilter, restart with
    -blockfilterindex=1.
  3. Immediately (before the index finishes rebuilding) call
    scanblocks start '["addr(<addr>)"]'.

Before this change the call returns "completed": true with an empty/partial
relevant_blocks, silently skipping the range the index had not rebuilt yet.

How it is fixed and why

Mirror getblockfilter's error classification:

  • Call BlockUntilSyncedToCurrentChain() only to obtain an index_ready flag.
    Do not fail unconditionally when the index is still behind the tip - the
    requested range may already be available.
  • If LookupFilterRange fails and the index is not ready, throw the same
    "still in the process of being indexed" RPC_MISC_ERROR that
    getblockfilter uses.
  • If LookupFilterRange fails after the index is ready, throw
    RPC_INTERNAL_ERROR (unexpected / corruption), instead of skipping the chunk.

This closes the silent gap without rejecting scans whose range is already
covered while the index catches up to the tip.

The diff also reindents the match loop: inverting if (LookupFilterRange(...))
into an early throw removes one nesting level from the existing body. That
reindentation is a consequence of the bug fix, not a standalone style change.

Tests

  • test/functional/rpc_scanblocks.py - new test_scanblocks_unindexed_range
    covers the modified code: it pads the chain, wipes the filter index, restarts,
    and while the index is behind the tip asserts that a scan to the tip returns
    the indexing error, that a scan over an already-written prefix (genesis)
    still succeeds, and that after sync the match is found.
  • The existing run_test cases (which wait_until(... synced ...) before
    scanning) continue to exercise the normal synced path.

AI / tooling note

I found this regression while reviewing the RPC with an AI-assisted tool.
I reproduced the unsynced-index behavior myself, chose to mirror
getblockfilter's existing guard, and verified the fix with the
functional test above. This PR text and any review replies are my own.

### The issue `scanblocks` reads block filters over a range via `LookupFilterRange`. When the block filter index is behind the active chain (e.g. right after startup, while it is still syncing in the background), the lookup for the not yet indexed range fails. The old code ignored that failure, advanced `start_index` to the end of the chunk, and kept going - so the scan skipped every unindexed block and still returned `"completed": true`. The result is a silent gap: a caller gets a `relevant_blocks` list that looks fine but is missing any match in the unindexed range, with no way to distinguish "no matches" from "range was never scanned". Note that `"completed"` only means the scan was not aborted - it does not mean every filter in the requested range was actually read. ### Steps to reproduce 1. Start a node with `-blockfilterindex=1` and let it mine/receive some blocks. 2. Stop the node, delete `<datadir>/<chain>/indexes/blockfilter`, restart with `-blockfilterindex=1`. 3. Immediately (before the index finishes rebuilding) call `scanblocks start '["addr(<addr>)"]'`. Before this change the call returns `"completed": true` with an empty/partial `relevant_blocks`, silently skipping the range the index had not rebuilt yet. ### How it is fixed and why Mirror `getblockfilter`'s error classification: - Call `BlockUntilSyncedToCurrentChain()` only to obtain an `index_ready` flag. Do **not** fail unconditionally when the index is still behind the tip - the requested range may already be available. - If `LookupFilterRange` fails and the index is not ready, throw the same "still in the process of being indexed" `RPC_MISC_ERROR` that `getblockfilter` uses. - If `LookupFilterRange` fails after the index is ready, throw `RPC_INTERNAL_ERROR` (unexpected / corruption), instead of skipping the chunk. This closes the silent gap without rejecting scans whose range is already covered while the index catches up to the tip. The diff also reindents the match loop: inverting `if (LookupFilterRange(...))` into an early `throw` removes one nesting level from the existing body. That reindentation is a consequence of the bug fix, not a standalone style change. ### Tests - `test/functional/rpc_scanblocks.py` - new `test_scanblocks_unindexed_range` covers the modified code: it pads the chain, wipes the filter index, restarts, and while the index is behind the tip asserts that a scan to the tip returns the indexing error, that a scan over an already-written prefix (genesis) still succeeds, and that after sync the match is found. - The existing `run_test` cases (which `wait_until(... synced ...)` before scanning) continue to exercise the normal synced path. ### AI / tooling note I found this regression while reviewing the RPC with an AI-assisted tool. I reproduced the unsynced-index behavior myself, chose to mirror `getblockfilter`'s existing guard, and verified the fix with the functional test above. This PR text and any review replies are my own.
DrahtBot commented 2026-07-29 18:18:03 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK fjahr
Concept ACK maflcko

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37016 (rpc: fail scanblocks instead of silently skipping missing filters by shivansh023023)
  • #35229 (refactor: Use CBlockIndex parameters as reference by optout21)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35837 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35837.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35837#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [fjahr](https://github.com/bitcoin/bitcoin/pull/35837#pullrequestreview-5910906167) | | Concept ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/35837#issuecomment-5127611820) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37016](https://github.com/bitcoin/bitcoin/pull/37016) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37016.svg"></sub> (rpc: fail scanblocks instead of silently skipping missing filters by shivansh023023) * [#35229](https://github.com/bitcoin/bitcoin/pull/35229) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35229.svg"></sub> (refactor: Use CBlockIndex parameters as reference by optout21) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
maflcko commented 2026-07-30 06:52:40 +00:00 (Migrated from github.com)

I found this regression while reviewing the RPC with an AI-assisted tool I
maintain, Boffin 0.3.2.

Thx for following the projects AI policy, and Concept ACK. However, I think the link to the tool can be removed and this can just say "I found this regression while reviewing the RPC with an AI-assisted tool". The tool is "a layer for agents", but I am sure any vanilla agent will find the same issue with the same prompt. E.g:

LLM output
cdx -c model=gpt-5.4-mini exec 'Review the scanblocks RPC for correctness' 2>/dev/null 
Findings:

1. [`src/rpc/blockchain.cpp`](src\/rpc\/blockchain.cpp#L2683) silently ignores `LookupFilterRange()` failures. If the block filter DB read fails or the range is otherwise unreadable, the RPC just skips that chunk, keeps going, and can still return `completed: true` with missing `relevant_blocks`. That is a correctness bug, not just an error-path detail. It should surface the failure to the caller or at least mark the scan incomplete.

2. [`src/rpc/blockchain.cpp`](src\/rpc\/blockchain.cpp#L2664) has an abort race during startup. `g_scanfilter_should_abort_scan` is cleared only after the scan has already reserved the global slot and finished descriptor/index setup. If another thread issues `scanblocks("abort")` in that window, it can set the flag and then have it overwritten by the startup path, causing the scan to ignore a valid abort request. The reset needs to happen before any long setup, or the state transition needs to be synchronized.

No other correctness issue stood out in the range logic itself.
> I found this regression while reviewing the RPC with an AI-assisted tool I > maintain, [Boffin](https://github.com/MicSm/boffin) 0.3.2. Thx for following the projects AI policy, and Concept ACK. However, I think the link to the tool can be removed and this can just say "I found this regression while reviewing the RPC with an AI-assisted tool". The tool is "a layer for agents", but I am sure any vanilla agent will find the same issue with the same prompt. E.g: <details><summary>LLM output</summary> ``` cdx -c model=gpt-5.4-mini exec 'Review the scanblocks RPC for correctness' 2>/dev/null Findings: 1. [`src/rpc/blockchain.cpp`](src\/rpc\/blockchain.cpp#L2683) silently ignores `LookupFilterRange()` failures. If the block filter DB read fails or the range is otherwise unreadable, the RPC just skips that chunk, keeps going, and can still return `completed: true` with missing `relevant_blocks`. That is a correctness bug, not just an error-path detail. It should surface the failure to the caller or at least mark the scan incomplete. 2. [`src/rpc/blockchain.cpp`](src\/rpc\/blockchain.cpp#L2664) has an abort race during startup. `g_scanfilter_should_abort_scan` is cleared only after the scan has already reserved the global slot and finished descriptor/index setup. If another thread issues `scanblocks("abort")` in that window, it can set the flag and then have it overwritten by the startup path, causing the scan to ignore a valid abort request. The reset needs to happen before any long setup, or the state transition needs to be synchronized. No other correctness issue stood out in the range logic itself. ``` </details>
fjahr (Migrated from github.com) reviewed 2026-07-30 20:47:45 +00:00
fjahr (Migrated from github.com) left a comment

getblockfilter already guards against this state and returns an error;

What this is doing here is different from what getblockfilter does. There we don't fail unconditionally if the index isn't synced. We only fail if we the range isn't available. This makes sense because we may have the range available even if the index isn't synced to the tip yet. I don't see why we shouldn't be able to do it the same way here.

> getblockfilter already guards against this state and returns an error; What this is doing here is different from what `getblockfilter` does. There we don't fail unconditionally if the index isn't synced. We only fail if we the range isn't available. This makes sense because we may have the range available even if the index isn't synced to the tip yet. I don't see why we shouldn't be able to do it the same way here.
fjahr (Migrated from github.com) commented 2026-07-30 20:47:21 +00:00

This is incorrect, getblockfilter does not do this: github.com/bitcoin/bitcoin@67efced1fc/src/rpc/blockchain.cpp (L3008)

This is incorrect, `getblockfilter` does not do this: https://github.com/bitcoin/bitcoin/blob/67efced1fc83a0b7215cc1513e7c4754fee0f12f/src/rpc/blockchain.cpp#L3008
DrahtBot (Migrated from github.com) reviewed 2026-07-30 20:55:29 +00:00
DrahtBot (Migrated from github.com) commented 2026-07-30 20:55:29 +00:00

the ci fails here:

                               AssertionError: filter index synced too quickly to exercise the unsynced path
the ci fails here: AssertionError: filter index synced too quickly to exercise the unsynced path
MicSm commented 2026-08-04 16:29:33 +00:00 (Migrated from github.com)

getblockfilter already guards against this state and returns an error;

What this is doing here is different from what getblockfilter does. There we don't fail unconditionally if the index isn't synced. We only fail if we the range isn't available. This makes sense because we may have the range available even if the index isn't synced to the tip yet. I don't see why we shouldn't be able to do it the same way here.

You're right - thanks. getblockfilter does not fail merely because index is behind the tip, so it fails when the requested filter isn't available (and then classifies it still-indexing vs unexpected/corruption).

So, I updated to match this: BlockUntilSyncedToCurrentChain() is only used as an index_ready flag and a failed LookupFilterRange is classified the same way. A scan whose requested range is already available while the tip
is ahead, now succeeds.

> > getblockfilter already guards against this state and returns an error; > > What this is doing here is different from what `getblockfilter` does. There we don't fail unconditionally if the index isn't synced. We only fail if we the range isn't available. This makes sense because we may have the range available even if the index isn't synced to the tip yet. I don't see why we shouldn't be able to do it the same way here. You're right - thanks. `getblockfilter` does not fail merely because index is behind the tip, so it fails when the requested filter isn't available (and then classifies it still-indexing vs unexpected/corruption). So, I updated to match this: `BlockUntilSyncedToCurrentChain()` is only used as an `index_ready` flag and a failed `LookupFilterRange` is classified the same way. A scan whose requested range is already available while the tip is ahead, now succeeds.
MicSm commented 2026-08-05 15:56:19 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

done

> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes). done
fjahr (Migrated from github.com) reviewed 2026-09-17 23:07:53 +00:00
fjahr (Migrated from github.com) left a comment

Concept ACK on handling this but the test needs a lot of work

Concept ACK on handling this but the test needs a lot of work
fjahr (Migrated from github.com) commented 2026-09-17 22:45:50 +00:00

This status may be outdated at the end of a long scan.

This status may be outdated at the end of a long scan.
fjahr (Migrated from github.com) commented 2026-09-17 22:08:16 +00:00

This reference to the other RPC is unnecessary for readers to understand the code and it could get stale too easily, so it should be removed

This reference to the other RPC is unnecessary for readers to understand the code and it could get stale too easily, so it should be removed
fjahr (Migrated from github.com) commented 2026-09-17 22:47:42 +00:00

Why throw here instead of returning a partial result?

Why throw here instead of returning a partial result?
fjahr (Migrated from github.com) commented 2026-09-17 21:54:17 +00:00

We usually add the implementation of new test cases above run_test, not below.

We usually add the implementation of new test cases above `run_test`, not below.
fjahr (Migrated from github.com) commented 2026-09-17 21:50:03 +00:00

This is a bit unusual but ok for me. This is always used for checking "synced" so I would put this into the function. And I would prefer a bit more expessive name like index_synced or so.

This is a bit unusual but ok for me. This is always used for checking `"synced"` so I would put this into the function. And I would prefer a bit more expessive name like `index_synced` or so.
fjahr (Migrated from github.com) commented 2026-09-17 22:00:32 +00:00

No normal functional test should require mining this many blocks. And we don't leave the actual testing to chance. The test either needs to work deterministically or it is of no use for us, with maybe some very rare exceptions.

No normal functional test should require mining this many blocks. And we don't leave the actual testing to chance. The test either needs to work deterministically or it is of no use for us, with maybe some very rare exceptions.
fjahr (Migrated from github.com) commented 2026-09-17 22:29:27 +00:00

No need to re-apply the args here when they are unchanged from the test params.

No need to re-apply the args here when they are unchanged from the test params.
fjahr (Migrated from github.com) commented 2026-09-17 21:58:09 +00:00

This doesn't make sense, you are waiting for the index to be synced just to delete it without doing anything else.

This doesn't make sense, you are waiting for the index to be synced just to delete it without doing anything else.
fjahr (Migrated from github.com) commented 2026-09-17 22:43:44 +00:00

As mentioned above, skipping the actual testing under some race condition makes the test basically useless for our purposes. You should look for a more robust way of testing this or consider removing the test. It seems like the getblockfilter RPC doesn't have coverage for this. Maybe it's possible with a partial sync like we are using in feature_assumeutxo.py.

As mentioned above, skipping the actual testing under some race condition makes the test basically useless for our purposes. You should look for a more robust way of testing this or consider removing the test. It seems like the `getblockfilter` RPC doesn't have coverage for this. Maybe it's possible with a partial sync like we are using in `feature_assumeutxo.py`.
fjahr (Migrated from github.com) commented 2026-09-17 23:01:10 +00:00

tip will be used by default so the variable can be removed and the call here simplified.

`tip` will be used by default so the variable can be removed and the call here simplified.
fjahr (Migrated from github.com) commented 2026-09-17 22:38:44 +00:00

Bruteforcing this in a loop is really not necessary, we have wait_until etc. for this.

Bruteforcing this in a loop is really not necessary, we have `wait_until` etc. for this.
fjahr (Migrated from github.com) commented 2026-09-17 22:57:48 +00:00

I don't think the success case test needs to be repeated here at the end. Also you already do the same check in racy part above if the index is already synced.

I don't think the success case test needs to be repeated here at the end. Also you already do the same check in racy part above if the index is already synced.
First-time contributor

🟠 Minor · Index catch-up can be misreported as corruption

If indexing catches up between a failed range lookup and GetSummary(), scanblocks can return -32603 for a healthy index instead of the retryable indexing error.

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

🔵 Suggestion · Unavailable suffixes are detected only after scanning covered chunks

During an index rebuild or assumeutxo background validation, a scan can process many covered chunks before discovering an unavailable suffix and discarding its results.

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

🔵 Suggestion · Prefix and catch-up scans lack known-match assertions

The snapshot-node test checks only metadata for its successful prefix scan and never rescans that node after catch-up, leaving matching and successful retry unverified.

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

🔵 Suggestion · The new tests never exercise an unsynced index

Both added fixtures run with synced=true, leaving readable-prefix and unavailable-range behavior during an actual index rebuild untested.

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

🔵 Suggestion · The new scanblocks failure behavior has no release note

For unavailable filter ranges, scanblocks now raises -1 or -32603 instead of potentially returning completed=true, but no release note explains the changed RPC behavior or earlier missing matches.

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

🔵 Suggestion · The PR description disagrees with the implemented checks and tests

The description specifies an index_ready flag and a wipe-and-restart test, while the commit uses summary-plus-ancestry classification and tests assumeutxo and a deleted filter file.

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

Review coverage was incomplete.


Reviewed: 64eca3dd8c9d · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:965af1044d9e41839565702e4d9bd0a751eda81f6e8b6402747fa296ef84ebea:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:67d9d7fe439d5b7b7b6c11061b353d5bf2c7f083 --> <!-- ralph-head:64eca3dd8c9d9926fc108eaddd9ad1b3993056e6 --> <!-- ralph-case:16270ac2a2215b107f1a8a8ad269af5579181b47b8880ea22f114210c2d2f821 --> **🟠 Minor · Index catch-up can be misreported as corruption** If indexing catches up between a failed range lookup and GetSummary(), scanblocks can return -32603 for a healthy index instead of the retryable indexing error. Location: [`src/rpc/blockchain.cpp:2725`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/src/rpc/blockchain.cpp#L2725>) (head). **🔵 Suggestion · Unavailable suffixes are detected only after scanning covered chunks** During an index rebuild or assumeutxo background validation, a scan can process many covered chunks before discovering an unavailable suffix and discarding its results. Location: [`src/rpc/blockchain.cpp:2724`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/src/rpc/blockchain.cpp#L2724>) (head). **🔵 Suggestion · Prefix and catch-up scans lack known-match assertions** The snapshot-node test checks only metadata for its successful prefix scan and never rescans that node after catch-up, leaving matching and successful retry unverified. Location: [`test/functional/rpc_scanblocks.py:61`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/test/functional/rpc_scanblocks.py#L61>) (head). **🔵 Suggestion · The new tests never exercise an unsynced index** Both added fixtures run with synced=true, leaving readable-prefix and unavailable-range behavior during an actual index rebuild untested. Location: [`test/functional/rpc_scanblocks.py:57`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/test/functional/rpc_scanblocks.py#L57>) (head). **🔵 Suggestion · The new scanblocks failure behavior has no release note** For unavailable filter ranges, scanblocks now raises -1 or -32603 instead of potentially returning completed=true, but no release note explains the changed RPC behavior or earlier missing matches. Location: [`src/rpc/blockchain.cpp:2729`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/src/rpc/blockchain.cpp#L2729>) (head). **🔵 Suggestion · The PR description disagrees with the implemented checks and tests** The description specifies an index_ready flag and a wipe-and-restart test, while the commit uses summary-plus-ancestry classification and tests assumeutxo and a deleted filter file. Location: [`src/rpc/blockchain.cpp:2708`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6/src/rpc/blockchain.cpp#L2708>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`64eca3dd8c9d`](<https://git.fish.foo/bitcoin/bitcoin/commit/64eca3dd8c9d9926fc108eaddd9ad1b3993056e6>) · [Full review report](<https://review.fish.foo/traces/35837-64eca3dd8c9d9926fc108eaddd9ad1b3993056e6-2077-4.html>) · [Previous reports](<https://review.fish.foo/traces/35837/>) [permalink](<https://review.fish.foo/traces/35837-64eca3dd8c9d9926fc108eaddd9ad1b3993056e6-2077-4.html>)
sedited commented 2026-10-30 16:19:20 +00:00 (Migrated from github.com)

@MicSm are you still working on this? There has been pending review here for a while.

@MicSm are you still working on this? There has been pending review here for a while.
MicSm commented 2026-11-01 17:52:50 +00:00 (Migrated from github.com)

Concept ACK on handling this but the test needs a lot of work

yes, I see, working on it

> Concept ACK on handling this but the test needs a lot of work yes, I see, working on it
MicSm commented 2026-11-01 17:53:05 +00:00 (Migrated from github.com)

@MicSm are you still working on this? There has been pending review here for a while.

Sure

> @MicSm are you still working on this? There has been pending review here for a while. Sure
MicSm (Migrated from github.com) reviewed 2026-11-03 17:17:01 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:17:01 +00:00

That's already done. The helper is gone in the new version, see the test. The test does not poll for "synced" anymore: since #36618, start_node() and sync_all() already wait for the index to reach the tip. The only check of the index state that is left is a direct assert_equal on getindexinfo.

That's already done. The helper is gone in the new version, see the test. The test does not poll for "synced" anymore: since #36618, start_node() and sync_all() already wait for the index to reach the tip. The only check of the index state that is left is a direct assert_equal on getindexinfo.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:18:00 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:18:00 +00:00

Sure, both new test cases (test_unindexed_range and test_unreadable_range) are now above run_test, check it please.

Sure, both new test cases (test_unindexed_range and test_unreadable_range) are now above run_test, check it please.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:19:16 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:19:16 +00:00

Agreed, that was pointless, so the new version does not delete the index at all. For the "not indexed yet" case, node2 loads an assumeutxo snapshot, so the index cannot get past the cached chain until the node has a peer. For the "cannot read" case, only the filter file is deleted and the index database is kept, so the node starts with a synced index and the lookup fails every time.

Agreed, that was pointless, so the new version does not delete the index at all. For the "not indexed yet" case, node2 loads an assumeutxo snapshot, so the index cannot get past the cached chain until the node has a peer. For the "cannot read" case, only the filter file is deleted and the index database is kept, so the node starts with a synced index and the lookup fails every time.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:20:50 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:20:50 +00:00

I agree, the new test does not depend on timing anymore, it mines 100 blocks, which is the minimum needed to build the regtest snapshot chain (its hash at height 299 is hardcoded in the chainparams). It is the same recipe as in tool_bitcoin_chainstate.py. The second case does not mine any blocks. Both cases give the same result on every run.

I agree, the new test does not depend on timing anymore, it mines 100 blocks, which is the minimum needed to build the regtest snapshot chain (its hash at height 299 is hardcoded in the chainparams). It is the same recipe as in tool_bitcoin_chainstate.py. The second case does not mine any blocks. Both cases give the same result on every run.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:21:48 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:21:48 +00:00

Yes, I removed it and the comment now only describes the condition in the line below it and does not mention the other RPC.

Yes, I removed it and the comment now only describes the condition in the line below it and does not mention the other RPC.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:27:52 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:27:52 +00:00

Thanks, this was the right hint and the new test does exactly that: node2 loads the regtest snapshot while it has no peers, so its filter index stays at height 199 while the active tip is at 299. A scan to the tip fails with "still being indexed", and a scan up to height 199 succeeds. No timing is involved.

This also showed a problem in my previous version: in this state the index reports "synced", so the old check returned "index corruption" instead of "still being indexed". That is why the error is now chosen by checking if the best block of the index covers the requested range.

Side note: while testing this, I found an pre-existing bug in getblockfilter. In the same state it also returns the wrong error ("index corruption" for a block above the snapshot). It is not related to this change, so I think it belongs in a separate PR. Anyone who wants to pick it up is welcome.

Thanks, this was the right hint and the new test does exactly that: node2 loads the regtest snapshot while it has no peers, so its filter index stays at height 199 while the active tip is at 299. A scan to the tip fails with "still being indexed", and a scan up to height 199 succeeds. No timing is involved. This also showed a problem in my previous version: in this state the index reports "synced", so the old check returned "index corruption" instead of "still being indexed". That is why the error is now chosen by checking if the best block of the index covers the requested range. Side note: while testing this, I found an pre-existing bug in getblockfilter. In the same state it also returns the wrong error ("index corruption" for a block above the snapshot). It is not related to this change, so I think it belongs in a separate PR. Anyone who wants to pick it up is welcome.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:29:06 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:29:06 +00:00

Agreed. The flag is gone. The state of the index is now read at the moment the lookup fails, with GetSummary(), and the error is chosen by checking if the best block of the index covers the chunk that failed. So the check always uses the current state, also at the end of a long scan.

The call to BlockUntilSyncedToCurrentChain() before the loop is still there, but only so that a synced index finishes processing the blocks that were just connected.
Its return value is not used anymore.

Agreed. The flag is gone. The state of the index is now read at the moment the lookup fails, with GetSummary(), and the error is chosen by checking if the best block of the index covers the chunk that failed. So the check always uses the current state, also at the end of a long scan. The call to BlockUntilSyncedToCurrentChain() before the loop is still there, but only so that a synced index finishes processing the blocks that were just connected. Its return value is not used anymore.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:30:58 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:30:58 +00:00

I thought about it and chose the error for these reasons:

  1. "completed" is documented as "true if the scan was not aborted". A caller that never calls abort has no reason to check it. That's exactly why the silent gap was not noticed before. A partial result with completed=false would put the same callers in the same trap.

  2. A partial result cannot say why it stopped. We would need a new field for that, and that is an API change with release notes.

  3. The result would often be empty anyway. The lookup works in chunks of 10000 blocks, and in the assumeutxo case the first chunk already fails.

  4. A caller that only wants the part that is already indexed can scan up to best_block_height from getindexinfo.

An error also matches what getblockfilter does for a missing filter.
If you still prefer a partial result, I can change it, but then I think it should be a separate change with its own field.

I thought about it and chose the error for these reasons: 1. "completed" is documented as "true if the scan was not aborted". A caller that never calls abort has no reason to check it. That's exactly why the silent gap was not noticed before. A partial result with completed=false would put the same callers in the same trap. 2. A partial result cannot say why it stopped. We would need a new field for that, and that is an API change with release notes. 3. The result would often be empty anyway. The lookup works in chunks of 10000 blocks, and in the assumeutxo case the first chunk already fails. 4. A caller that only wants the part that is already indexed can scan up to best_block_height from getindexinfo. An error also matches what getblockfilter does for a missing filter. If you still prefer a partial result, I can change it, but then I think it should be a separate change with its own field.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:31:50 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:31:50 +00:00

I removed it, the success case after the sync is already covered by the existing checks in run_test.

I removed it, the success case after the sync is already covered by the existing checks in run_test.
MicSm (Migrated from github.com) reviewed 2026-11-03 17:32:23 +00:00
MicSm (Migrated from github.com) commented 2026-11-03 17:32:23 +00:00

Done. The variable is gone. The scan to the tip is called without heights, and the only explicit limit left is passed as stop_height=START_HEIGHT.

Done. The variable is gone. The scan to the tip is called without heights, and the only explicit limit left is passed as stop_height=START_HEIGHT.
fjahr (Migrated from github.com) reviewed 2026-11-15 13:58:50 +00:00
fjahr (Migrated from github.com) left a comment

Code review ACK 64eca3dd8c

The RPC code is fine, some comments in the tests aren't ideal IMO but I wouldn't consider it striclty a blocker.

The CI failure seems unrelated, would be good to rerun it so other reviewers are not turned away.

Code review ACK 64eca3dd8c9d9926fc108eaddd9ad1b3993056e6 The RPC code is fine, some comments in the tests aren't ideal IMO but I wouldn't consider it striclty a blocker. The CI failure seems unrelated, would be good to rerun it so other reviewers are not turned away.
fjahr (Migrated from github.com) commented 2026-11-15 13:24:18 +00:00

nit: That's always the case, the comment doesn't seem necessary to spell out

nit: That's always the case, the comment doesn't seem necessary to spell out
fjahr (Migrated from github.com) commented 2026-11-15 13:26:47 +00:00

I would prefer if in setup_network we don't leak reasoning for doing something in a specific test. A simple "Keep node2 disconnected" above the connect_nodes call seem enough here. Such comments are hard to maintain otherwise.

I would prefer if in `setup_network` we don't leak reasoning for doing something in a specific test. A simple "Keep node2 disconnected" above the `connect_nodes` call seem enough here. Such comments are hard to maintain otherwise.
fjahr (Migrated from github.com) commented 2026-11-15 13:16:28 +00:00

The sync_all doesn't seem necessary, the only reason this is needed at all is because the later mining ops in the test do sync_all and would fail if the nodes are not connected. But here this just blocks the test briefly for no reason. The comment could be updated to reflect the reasoning too.

The `sync_all` doesn't seem necessary, the only reason this is needed at all is because the later mining ops in the test do `sync_all` and would fail if the nodes are not connected. But here this just blocks the test briefly for no reason. The comment could be updated to reflect the reasoning too.
maflcko (Migrated from github.com) reviewed 2026-11-16 10:08:55 +00:00
maflcko (Migrated from github.com) commented 2026-11-16 10:08:55 +00:00

I wonder if this should come with a test at all? It seems there are already a few nits/confusions and this will be hard to maintain in the future, given the complexity and the coupling with assumeutxo just to test this race.

It should be sufficient to drop this test somewhere in a hidden comment, so that reviewers can use it if they want, but there is no further maintenance cost in case down the line?

I wonder if this should come with a test at all? It seems there are already a few nits/confusions and this will be hard to maintain in the future, given the complexity and the coupling with assumeutxo just to test this race. It should be sufficient to drop this test somewhere in a hidden comment, so that reviewers can use it if they want, but there is no further maintenance cost in case down the line?
fanquake (Migrated from github.com) reviewed 2026-11-16 10:59:09 +00:00
fanquake (Migrated from github.com) commented 2026-11-16 10:59:09 +00:00

and the coupling with assumeutxo just to test this race.

I also think that if something like #36598 is gathering conceptual agreement, we shouldn't rush to introduce more assumeutxo-related code.

> and the coupling with assumeutxo just to test this race. I also think that if something like #36598 is gathering conceptual agreement, we shouldn't rush to introduce more assumeutxo-related code.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35837
No description provided.