test: speed up functional tests by removing avoidable waits #36440

Manually merged
ViniciusCestarii merged 2 commits from speedup-p2p-tests into master 2026-10-13 00:36:34 +00:00 AGit
ViniciusCestarii commented 2026-10-05 20:54:50 +00:00 (Migrated from github.com)

Reduce functional test runtime:

  • set noban_tx_relay = True for tests that can benefit from it.
  • wake P2PInterface.wait_until as soon as a message is delivered or the connection state changes, instead of polling every 50ms.

Tested on my x86-64 machine:

Wall time (-j=18): 110.8s to 99.1s (-11%)
Accumulated: 1715s to 1411s (-17.5%)

Tests that were most affected:

test before after
feature_maxuploadtarget 57.9s 6.2s
wallet_conflicts 49.2s 7.0s
p2p_sendheaders 31.1s 6.8s
p2p_compactblocks 11.1s 1.7s
wallet_orphanedreward 9.3s 5.2s
wallet_importprunedfunds 4.9s 2.9s
Reduce functional test runtime: - set noban_tx_relay = True for tests that can benefit from it. - wake P2PInterface.wait_until as soon as a message is delivered or the connection state changes, instead of polling every 50ms. Tested on my x86-64 machine: Wall time (-j=18): 110.8s to 99.1s (-11%) Accumulated: 1715s to 1411s (-17.5%) Tests that were most affected: | test | before | after | |---|---|---| | feature_maxuploadtarget | 57.9s | 6.2s | | wallet_conflicts | 49.2s | 7.0s | | p2p_sendheaders | 31.1s | 6.8s | | p2p_compactblocks | 11.1s | 1.7s | | wallet_orphanedreward | 9.3s | 5.2s | | wallet_importprunedfunds | 4.9s | 2.9s |
DrahtBot commented 2026-10-05 20:54:59 +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 maflcko, w0xlt
Concept ACK sedited
Stale ACK aaron-leeb, StephenChi-hi, willcl-ark

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:

  • #36333 (wallet: Delete removeprunedfunds and delete transaction delete code by davidgumberg)
  • #36114 (wallet: harden external signer psbt processing, revamp mock by Sjors)

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/36440 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36440.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36440#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 | [maflcko](https://github.com/bitcoin/bitcoin/pull/36440#issuecomment-6126182744), [w0xlt](https://github.com/bitcoin/bitcoin/pull/36440#pullrequestreview-5496839063) | | Concept ACK | [sedited](https://github.com/bitcoin/bitcoin/pull/36440#issuecomment-6062239978) | | Stale ACK | [aaron-leeb](https://github.com/bitcoin/bitcoin/pull/36440#issuecomment-6027174987), [StephenChi-hi](https://github.com/bitcoin/bitcoin/pull/36440#issuecomment-6040953756), [willcl-ark](https://github.com/bitcoin/bitcoin/pull/36440#pullrequestreview-5457419857) | 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: * [#36333](https://github.com/bitcoin/bitcoin/pull/36333) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36333.svg"></sub> (wallet: Delete `removeprunedfunds` and delete transaction delete code by davidgumberg) * [#36114](https://github.com/bitcoin/bitcoin/pull/36114) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36114.svg"></sub> (wallet: harden external signer psbt processing, revamp mock by Sjors) 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

Base: f739c7876b81304bdc72e7eaa307702da269ac31
Head: 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef

No verified findings are available from this review.

Review coverage was incomplete. concurrency: The framework implementation that consumes noban_tx_relay was not inspected, so its exact permission changes and their effect on the added wallet tests remain unresolved. design: The bodies of the six changed wallet tests (wallet_change_address.py, wallet_conflicts.py, wallet_exported_watchonly.py, wallet_importprunedfunds.py, wallet_orphanedreward.py, and wallet_signer.py) were not available to inspect. Checking whether any of them assert transaction-relay or timing behavior could change the assessment of enabling noban_tx_relay, which the framework says not to use for those tests.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `f739c7876b81304bdc72e7eaa307702da269ac31` Head: `8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef` No verified findings are available from this review. Review coverage was incomplete. concurrency: The framework implementation that consumes `noban_tx_relay` was not inspected, so its exact permission changes and their effect on the added wallet tests remain unresolved. design: The bodies of the six changed wallet tests (wallet_change_address.py, wallet_conflicts.py, wallet_exported_watchonly.py, wallet_importprunedfunds.py, wallet_orphanedreward.py, and wallet_signer.py) were not available to inspect. Checking whether any of them assert transaction-relay or timing behavior could change the assessment of enabling noban_tx_relay, which the framework says not to use for those tests. [Full review report](<https://review.fish.foo/traces/36440-8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef-605-3.html>)
w0xlt commented 2026-10-06 18:25:00 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
w0xlt (Migrated from github.com) reviewed 2026-10-06 20:06:57 +00:00
w0xlt (Migrated from github.com) left a comment
ACK 9d7c76d671cdc4e690a176b773d8a9860c37db94
aaron-leeb commented 2026-10-06 23:14:56 +00:00 (Migrated from github.com)

tACK 9d7c76d

I ran the functional test suite locally on x86-64 machine w/ 16 cores and noted similar performance improvements:

Accumulated:

  • Before: 2369 s
  • After: 2081 s ( -12%)

Runtime:

  • Before: 120 s
  • After: 111 s (-7.5%)
tACK [9d7c76d](https://github.com/bitcoin/bitcoin/pull/36440/commits/9d7c76d671cdc4e690a176b773d8a9860c37db94) I ran the functional test suite locally on x86-64 machine w/ 16 cores and noted similar performance improvements: Accumulated: - Before: 2369 s - After: 2081 s ( -12%) Runtime: - Before: 120 s - After: 111 s (-7.5%)
StephenChi-hi commented 2026-10-07 15:20:55 +00:00 (Migrated from github.com)

tACK 9d7c76d671

I also tested this locally and confirmed the performance improvements. and some of the most affected tests, for example the wallet_conflicts.py:
Before:
wallet_conflicts.py | ✓ Passed | 44 s

After:
wallet_conflicts.py | ✓ Passed | 9 s

tACK 9d7c76d671 I also tested this locally and confirmed the performance improvements. and some of the most affected tests, for example the wallet_conflicts.py: Before: wallet_conflicts.py | ✓ Passed | 44 s After: wallet_conflicts.py | ✓ Passed | 9 s
willcl-ark (Migrated from github.com) approved these changes 2026-10-08 13:35:06 +00:00
willcl-ark (Migrated from github.com) left a comment

tACK 9d7c76d671

tACK 9d7c76d671cdc4e690a176b773d8a9860c37db94
sedited commented 2026-10-08 14:35:50 +00:00 (Migrated from github.com)

Concept ACK

I think wallet_change_address.py would be a good addition too (goes from 9s to 1.9s on my machine).

Concept ACK I think `wallet_change_address.py` would be a good addition too (goes from 9s to 1.9s on my machine).
ViniciusCestarii commented 2026-10-08 17:12:44 +00:00 (Migrated from github.com)

Thanks for the reviews!

I think wallet_change_address.py would be a good addition too (goes from 9s to 1.9s on my machine).

True! Looking again, I found some others tests that can benefit from noban_tx_relay = True. There may be even more but checking for it is kinda nuanced and some tests don't benefit much.

Force-pushed 8dc80cafa2 adding self.noban_tx_relay = True in wallet_exported_watchonly.py, wallet_signer.py and wallet_change_address.py.

wallet_exported_watchonly.py 7.52s -> 2.68s
wallet_signer.py 7.98s -> 2.94s
wallet_change_address.py 11.30s -> 2.29s

Thanks for the reviews! > I think `wallet_change_address.py` would be a good addition too (goes from 9s to 1.9s on my machine). True! Looking again, I found some others tests that can benefit from noban_tx_relay = True. There may be even more but checking for it is kinda nuanced and some tests don't benefit much. Force-pushed 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef adding self.noban_tx_relay = True in wallet_exported_watchonly.py, wallet_signer.py and wallet_change_address.py. wallet_exported_watchonly.py 7.52s -> 2.68s wallet_signer.py 7.98s -> 2.94s wallet_change_address.py 11.30s -> 2.29s
maflcko (Migrated from github.com) reviewed 2026-10-08 19:24:08 +00:00
maflcko (Migrated from github.com) left a comment

lgtm, but I left a nit

lgtm, but I left a nit
maflcko (Migrated from github.com) commented 2026-10-08 19:23:21 +00:00

lgtm, but there could be a risk that someone sets a larger explicit interval to ensure something is only checked so often and that for the time in between "nothing" happens.

I don't think there is such a case in the codebase for a lock, but it would be good to be able to make this reviewable with git grep.

Can you make all check_interval kwargs? Possibly also timeout:

-    def wait_until(self, test_function, timeout=60, check_interval=0.05):
+    def wait_until(self, test_function, *, timeout=60, check_interval=0.05):

(edit: An alternative would be to only run this when the check_interval is the default, but up to you. This is just a nit)

lgtm, but there could be a risk that someone sets a larger explicit interval to ensure something is only checked so often and that for the time in between "nothing" happens. I don't think there is such a case in the codebase for a lock, but it would be good to be able to make this reviewable with `git grep`. Can you make all `check_interval` kwargs? Possibly also `timeout`: ```diff - def wait_until(self, test_function, timeout=60, check_interval=0.05): + def wait_until(self, test_function, *, timeout=60, check_interval=0.05): ``` (edit: An alternative would be to only run this when the check_interval is the default, but up to you. This is just a nit)
ViniciusCestarii (Migrated from github.com) reviewed 2026-10-09 13:50:26 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-10-09 13:50:26 +00:00

Thanks! The only caller that can reach the Condition path is P2PInterface.wait_until, which already takes check_interval as keyword-only, so git grep check_interval= already covers it. Making TestNode.wait_until and BitcoinTestFramework.wait_until keyword-only seems like a good consistency change, but it's unrelated to this PR since those never pass a lock.

Grepping check_interval=, the only tests setting an explicit interval are p2p_ping_ibd.py and interface_http.py, both relying on it for stateful checks. They go through BitcoinTestFramework.wait_until, so they aren't affected.

Also, my take is that wait_until takes a predicate, which should only describe a state, so evaluating it earlier on a notification should still be correct. Using stateful checks seems like a misuse of wait_until to me. So I'd prefer to leave this as is.

Thanks! The only caller that can reach the Condition path is `P2PInterface.wait_until`, which already takes check_interval as keyword-only, so `git grep check_interval=` already covers it. Making `TestNode.wait_until` and `BitcoinTestFramework.wait_until` keyword-only seems like a good consistency change, but it's unrelated to this PR since those never pass a lock. Grepping check_interval=, the only tests setting an explicit interval are `p2p_ping_ibd.py` and `interface_http.py`, both relying on it for stateful checks. They go through `BitcoinTestFramework.wait_until`, so they aren't affected. Also, my take is that `wait_until` takes a predicate, which should only describe a state, so evaluating it earlier on a notification should still be correct. Using stateful checks seems like a misuse of `wait_until` to me. So I'd prefer to leave this as is.
maflcko (Migrated from github.com) reviewed 2026-10-12 14:21:55 +00:00
maflcko (Migrated from github.com) commented 2026-10-12 14:21:55 +00:00

Also, my take is that wait_until takes a predicate, which should only describe a state, so evaluating it earlier on a notification should still be correct. Using stateful checks seems like a misuse of wait_until to me.

It is used twice in:

test/functional/interface_http.py:            self.wait_until(progress_stalled, check_interval=5)
test/functional/interface_http.py:        self.wait_until(progress_stalled, check_interval=5)

but maybe they should be re-written to use ensure_for.

> Also, my take is that `wait_until` takes a predicate, which should only describe a state, so evaluating it earlier on a notification should still be correct. Using stateful checks seems like a misuse of `wait_until` to me. It is used twice in: ```py test/functional/interface_http.py: self.wait_until(progress_stalled, check_interval=5) test/functional/interface_http.py: self.wait_until(progress_stalled, check_interval=5) ``` but maybe they should be re-written to use `ensure_for`.
maflcko commented 2026-10-12 14:21:58 +00:00 (Migrated from github.com)

review ACK 8dc80cafa2 🏏

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef 🏏
yIXD2z6tQ1/5SlEdBHIRIoo1xZ4sNYkuatpfYbydd9viQFehP9L7Reh4+xUoo0ijjQaqyURfe04VenTjN8eLAQ==
review ACK 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef 🏏 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef 🏏 yIXD2z6tQ1/5SlEdBHIRIoo1xZ4sNYkuatpfYbydd9viQFehP9L7Reh4+xUoo0ijjQaqyURfe04VenTjN8eLAQ== ``` </details>
w0xlt (Migrated from github.com) reviewed 2026-10-12 22:55:23 +00:00
w0xlt (Migrated from github.com) left a comment
ACK 8dc80cafa2ee5932c9ff499c02d6ab8e3cf2f5ef
ViniciusCestarii commented 2026-10-14 04:56:01 +00:00 (Migrated from github.com)

I also plan on reordering the tests in test_runner.py so running in parallel will have a smaller wall time after https://github.com/bitcoin/bitcoin/pull/36439 is merged too.

I also plan on reordering the tests in `test_runner.py` so running in parallel will have a smaller wall time after https://github.com/bitcoin/bitcoin/pull/36439 is merged too.
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!36440
No description provided.