test: Wait for index sync in all tests #36618

Manually merged
maflcko merged 2 commits from 2610-test-index-wallet-sync into master 2026-11-02 11:52:29 +00:00 AGit
maflcko commented 2026-10-23 08:49:27 +00:00 (Migrated from github.com)

Fixes https://github.com/bitcoin/bitcoin/issues/36564 by adding the missing wait on the index sync.

Diff to reproduce:

diff --git a/src/util/thread.cpp b/src/util/thread.cpp
index 5b20e807b4..2e988c9eea 100644
--- a/src/util/thread.cpp
+++ b/src/util/thread.cpp
@@ -8,2 +8,3 @@
 #include <util/log.h>
+#include <util/time.h>
 #include <util/threadnames.h>
@@ -17,2 +18,3 @@ void util::TraceThread(std::string_view thread_name, std::function<void()> threa
     util::ThreadRename(std::string{thread_name});
+    UninterruptibleSleep(999ms);
     try {

Command to reproduce (run twice to create the cache the first time, and reproduce on the second):

./bld-cmake/test/functional/wallet_fast_rescan.py | grep WARNING

On failure, the log will say something like:

 - 2026-10-18T05:06:44.451973Z [http.01] [wallet/scan.cpp:142] [ShouldFetchBlock] [scan] Fast rescan: inspect block 200 [4c063a93914ec0cb1604297f2f601dab9b9342bf073e6b80e1c11efd71714e2e] (WARNING: block filter not found!)
Fixes https://github.com/bitcoin/bitcoin/issues/36564 by adding the missing wait on the index sync. Diff to reproduce: ```diff diff --git a/src/util/thread.cpp b/src/util/thread.cpp index 5b20e807b4..2e988c9eea 100644 --- a/src/util/thread.cpp +++ b/src/util/thread.cpp @@ -8,2 +8,3 @@ #include <util/log.h> +#include <util/time.h> #include <util/threadnames.h> @@ -17,2 +18,3 @@ void util::TraceThread(std::string_view thread_name, std::function<void()> threa util::ThreadRename(std::string{thread_name}); + UninterruptibleSleep(999ms); try { ``` Command to reproduce (run twice to create the cache the first time, and reproduce on the second): ``` ./bld-cmake/test/functional/wallet_fast_rescan.py | grep WARNING ``` On failure, the log will say something like: ``` - 2026-10-18T05:06:44.451973Z [http.01] [wallet/scan.cpp:142] [ShouldFetchBlock] [scan] Fast rescan: inspect block 200 [4c063a93914ec0cb1604297f2f601dab9b9342bf073e6b80e1c11efd71714e2e] (WARNING: block filter not found!)
DrahtBot commented 2026-10-23 08:49:39 +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 ViniciusCestarii, hebasto

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:

  • #36629 (Add output script index and corresponding script history RPC by andrewtoth)
  • #36292 (index: Delete old coinstats index directory on startup by fjahr)
  • #36257 (qa: assert_equals -> assert_true/assert_false by hodlinator)
  • #36002 (txindex: allow running in pruned mode by andrewtoth)
  • #33904 (rest: add interface for gettxspendingprevout rpc by kevkevinpal)

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/36618 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36618.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36618#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 | [ViniciusCestarii](https://github.com/bitcoin/bitcoin/pull/36618#pullrequestreview-5711794977), [hebasto](https://github.com/bitcoin/bitcoin/pull/36618#pullrequestreview-5735884572) | 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: * [#36629](https://github.com/bitcoin/bitcoin/pull/36629) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36629.svg"></sub> (Add output script index and corresponding script history RPC by andrewtoth) * [#36292](https://github.com/bitcoin/bitcoin/pull/36292) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36292.svg"></sub> (index: Delete old coinstats index directory on startup by fjahr) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equals -> assert_true/assert_false by hodlinator) * [#36002](https://github.com/bitcoin/bitcoin/pull/36002) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36002.svg"></sub> (txindex: allow running in pruned mode by andrewtoth) * [#33904](https://github.com/bitcoin/bitcoin/pull/33904) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33904.svg"></sub> (rest: add interface for gettxspendingprevout rpc by kevkevinpal) 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-->
First-time contributor

🟠 Minor · Startup index wait shortens the pruning test’s catch-up timeout

feature_index_prune.py:124 restarts the indexed nodes, and startup now waits for index sync inside wait_for_rpc_connection (test_node.py:385) using the default 60s timeout. Base allowed node 1's coinstatsindex 150s to catch up from height 754 to 1500, so a catch-up of 60–150s now fails at restart.

Location: test/functional/feature_index_prune.py:117 (head).

Review coverage was incomplete.


Reviewed: fa74dc72d942 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:242447a4cf2eea8cf36c662182c044a4a03c53913b7033d9c612118a365b2d2c:1e657457416e20a18d8d2d136919c48e28e1bfed7a76c26939ab1ca10a232c6a --> <!-- ralph-base:ab7e668cc6af5d716ad40166d1f88235a2f6d25d --> <!-- ralph-head:fa74dc72d942e1628cea3c143bb56eed1457bbce --> <!-- ralph-case:c5ac7a44f38a7875c6733dfb86b216539978efd5ca366fa7c31735f7520d773c --> **🟠 Minor · Startup index wait shortens the pruning test’s catch-up timeout** feature_index_prune.py:124 restarts the indexed nodes, and startup now waits for index sync inside wait_for_rpc_connection (test_node.py:385) using the default 60s timeout. Base allowed node 1's coinstatsindex 150s to catch up from height 754 to 1500, so a catch-up of 60–150s now fails at restart. Location: [`test/functional/feature_index_prune.py:117`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fa74dc72d942e1628cea3c143bb56eed1457bbce/test/functional/feature_index_prune.py#L117>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`fa74dc72d942`](<https://git.fish.foo/bitcoin/bitcoin/commit/fa74dc72d942e1628cea3c143bb56eed1457bbce>) · [Full review report](<https://review.fish.foo/traces/36618-fa74dc72d942e1628cea3c143bb56eed1457bbce-1910-5.html>) · [Previous reports](<https://review.fish.foo/traces/36618/>) [permalink](<https://review.fish.foo/traces/36618-fa74dc72d942e1628cea3c143bb56eed1457bbce-1910-5.html>)
maflcko commented 2026-10-23 13:11:25 +00:00 (Migrated from github.com)

It seems a bit tedious to find and fix all of those issues by hand. Also, the tests will become overly verbose with all the manual syncs.

The framework should do this by itself, so I pushed that refactor and removed all of the manual syncs in tests.

It seems a bit tedious to find and fix all of those issues by hand. Also, the tests will become overly verbose with all the manual syncs. The framework should do this by itself, so I pushed that refactor and removed all of the manual syncs in tests.
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-29 16:46:07 +00:00
ViniciusCestarii (Migrated from github.com) left a comment

Concept ACK, I like how cleaner it is. I also measured performance but saw no significant change.

Commented a test that loses coverage with these changes.

Concept ACK, I like how cleaner it is. I also measured performance but saw no significant change. Commented a test that loses coverage with these changes.
ViniciusCestarii (Migrated from github.com) commented 2026-10-29 16:31:45 +00:00

In "test: refactor: Wait for index sync by default" fa74dc72d9

This changes test behavior. It used to check for absolute height and missing index.

In "test: refactor: Wait for index sync by default" fa74dc72d942e1628cea3c143bb56eed1457bbce This changes test behavior. It used to check for absolute height and missing index.
maflcko (Migrated from github.com) reviewed 2026-10-30 10:13:34 +00:00
maflcko (Migrated from github.com) commented 2026-10-30 10:13:34 +00:00

I don't think it does change behavior. The implicit sync will use getblockcount as the absolute height, just like the test used the height before.

Also, the test calls RPCs to fetch the index data, so if an index was missing, the test would fail, just like before.

I don't think it does change behavior. The implicit sync will use `getblockcount` as the absolute height, just like the test used the height before. Also, the test calls RPCs to fetch the index data, so if an index was missing, the test would fail, just like before.
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-30 11:45:00 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-10-30 11:45:00 +00:00

thanks for explaining! Makes sense.

thanks for explaining! Makes sense.
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-30 11:49:18 +00:00
ViniciusCestarii (Migrated from github.com) left a comment
ACK fa74dc72d942e1628cea3c143bb56eed1457bbce
hebasto commented 2026-10-30 12:27:30 +00:00 (Migrated from github.com)

Diff to reproduce:...

I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine.

UPDATE. A bit unrelated to this PR, but that reproducer with a longer sleep triggered the following tests on my machine:

feature_anchors.py                                     | ✖ Failed  | 12 s
feature_config_args.py                                 | ✖ Failed  | 15 s
tool_utxo_to_sqlite.py                                 | ✖ Failed  | 3 s

UPDATE 2. Only tool_utxo_to_sqlite.py seems to have an issue, as others pass with the proper --timeout-factor.

UPDATE 3. A clanker's fix:

--- a/test/functional/tool_utxo_to_sqlite.py
+++ b/test/functional/tool_utxo_to_sqlite.py
@@ -119,6 +119,7 @@ class UtxoToSqliteTest(BitcoinTestFramework):
 
         self.log.info('Dump UTXO set via `dumptxoutset` RPC')
         input_filename = os.path.join(self.options.tmpdir, "utxos.dat")
+        self.wait_until(lambda: node.getindexinfo()['coinstatsindex']['synced'])
         node.dumptxoutset(input_filename, "latest")
 
         for i, (txid_format, spk_format) in enumerate(product(["hex", "raw", "rawle"], ["hex", "raw"])):
> Diff to reproduce:... I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine. UPDATE. A bit unrelated to this PR, but that reproducer with a longer sleep triggered the following tests on my machine: ``` feature_anchors.py | ✖ Failed | 12 s feature_config_args.py | ✖ Failed | 15 s tool_utxo_to_sqlite.py | ✖ Failed | 3 s ``` UPDATE 2. Only `tool_utxo_to_sqlite.py` seems to have an issue, as others pass with the proper `--timeout-factor`. UPDATE 3. A clanker's fix: ```diff --- a/test/functional/tool_utxo_to_sqlite.py +++ b/test/functional/tool_utxo_to_sqlite.py @@ -119,6 +119,7 @@ class UtxoToSqliteTest(BitcoinTestFramework): self.log.info('Dump UTXO set via `dumptxoutset` RPC') input_filename = os.path.join(self.options.tmpdir, "utxos.dat") + self.wait_until(lambda: node.getindexinfo()['coinstatsindex']['synced']) node.dumptxoutset(input_filename, "latest") for i, (txid_format, spk_format) in enumerate(product(["hex", "raw", "rawle"], ["hex", "raw"])): ```
maflcko commented 2026-10-30 18:08:14 +00:00 (Migrated from github.com)

I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine.

Sorry, I forgot to clarify this only reproduces when running the test stand-alone and on the second run, because it needs the cache.

> I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine. Sorry, I forgot to clarify this only reproduces when running the test stand-alone and on the second run, because it needs the cache.
maflcko commented 2026-10-30 18:14:22 +00:00 (Migrated from github.com)

UPDATE 3. A clanker's fix:

I don't understand. The pull request here is supposed to fix the all index sync test issue (and I've confirmed this locally for tool_utxo_to_sqlite.py as well). Can you try this again and confirm you tested this pull?

> UPDATE 3. A clanker's fix: I don't understand. The pull request here is supposed to fix the all index sync test issue (and I've confirmed this locally for tool_utxo_to_sqlite.py as well). Can you try this again and confirm you tested this pull?
hebasto commented 2026-10-31 15:38:54 +00:00 (Migrated from github.com)

I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine.

Sorry, I forgot to clarify this only reproduces when running the test stand-alone and on the second run, because it needs the cache.

I was able to reproduce the issue using a longer delay on another machine of mine, running Fedora 44.

UPDATE 3. A clanker's fix:

I don't understand. The pull request here is supposed to fix the all index sync test issue (and I've confirmed this locally for tool_utxo_to_sqlite.py as well). Can you try this again and confirm you tested this pull?

Yes, I can confirm that I have been testing this PR yesterday and today :)

It indeed fixes tool_utxo_to_sqlite.py as well. But the fix comes in the second commit. Its commit message reads "This refactor does not change any test behavior", but there is evidence that it is a fix rather than a pure refactor.

To summarise, the extra delay in src/util/thread.cpp reliably triggers failures in both wallet_fast_rescan.py and tool_utxo_to_sqlite.py. The second commit fixes all of them. So is the first commit needed at all?

> > I’m not sure this is the right reproducer, as all the tests pass on my Ubuntu 26.04 machine. > > Sorry, I forgot to clarify this only reproduces when running the test stand-alone and on the second run, because it needs the cache. I was able to reproduce the issue using a longer delay on another machine of mine, running Fedora 44. > > UPDATE 3. A clanker's fix: > > I don't understand. The pull request here is supposed to fix the all index sync test issue (and I've confirmed this locally for tool_utxo_to_sqlite.py as well). Can you try this again and confirm you tested this pull? Yes, I can confirm that I have been testing this PR yesterday and today :) It indeed fixes `tool_utxo_to_sqlite.py` as well. But the fix comes in the second commit. Its commit message reads "This refactor does not change any test behavior", but there is evidence that it is a fix rather than a pure refactor. To summarise, the extra delay in `src/util/thread.cpp` reliably triggers failures in both `wallet_fast_rescan.py` and `tool_utxo_to_sqlite.py`. The second commit fixes all of them. So is the first commit needed at all?
maflcko commented 2026-11-01 18:02:57 +00:00 (Migrated from github.com)

It indeed fixes tool_utxo_to_sqlite.py as well. But the fix comes in the second commit. Its commit message reads "This refactor does not change any test behavior", but there is evidence that it is a fix rather than a pure refactor.

I wasn't aware that other tests also need fixing and when I wrote this, it was meant as a hardening refactor. I don't think there is much value in spending too much time enumerating all tests that are fixed. This also fixes https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4424117298 and I am sure it fixes a bunch of others more.

Happy to squash or reword the commit msg, but the overall diff won't change, so I am not sure if this is worth the review churn.

> It indeed fixes `tool_utxo_to_sqlite.py` as well. But the fix comes in the second commit. Its commit message reads "This refactor does not change any test behavior", but there is evidence that it is a fix rather than a pure refactor. I wasn't aware that other tests also need fixing and when I wrote this, it was meant as a hardening refactor. I don't think there is much value in spending too much time enumerating all tests that are fixed. This also fixes https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4424117298 and I am sure it fixes a bunch of others more. Happy to squash or reword the commit msg, but the overall diff won't change, so I am not sure if this is worth the review churn.
hebasto (Migrated from github.com) approved these changes 2026-11-02 11:31:01 +00:00
hebasto (Migrated from github.com) left a comment

ACK fa74dc72d9, the changes are correct.

Happy to squash or reword the commit msg, but the overall diff won't change, so I am not sure if this is worth the review churn.

You are right about the overall diff. However, I'd be happy to re-ACK if you change your mind about the imprecise commit message.

ACK fa74dc72d942e1628cea3c143bb56eed1457bbce, the changes are correct. > Happy to squash or reword the commit msg, but the overall diff won't change, so I am not sure if this is worth the review churn. You are right about the overall diff. However, I'd be happy to re-ACK if you change your mind about the imprecise commit message.
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!36618
No description provided.