test: speed up wallet unit test #36832

Open
ViniciusCestarii wants to merge 2 commits from speedup-wallet-unit-test into master AGit
ViniciusCestarii commented 2026-11-10 20:20:58 +00:00 (Migrated from github.com)

Deduplicates wallet creation code and avoid pre-deriving a large keypool (default 1000) by setting wallet keypool_size = 1

Speedup:

Suite Before After
coinselector_tests 8.26 s 3.35 s
wallet_tests 2.10 s 1.68 s
spend_tests 0.59 s 0.18 s
group_outputs_tests 0.33 s 0.12 s
Deduplicates wallet creation code and avoid pre-deriving a large keypool (default 1000) by setting wallet keypool_size = 1 Speedup: | Suite | Before | After | |---|---|---| | coinselector_tests | 8.26 s | 3.35 s | | wallet_tests | 2.10 s | 1.68 s | | spend_tests | 0.59 s | 0.18 s | | group_outputs_tests | 0.33 s | 0.12 s |
DrahtBot commented 2026-11-10 20:21:10 +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 Zippo76, davidgumberg

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:

  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

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/36832 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36832.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36832#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 | [Zippo76](https://github.com/bitcoin/bitcoin/pull/36832#pullrequestreview-5882041242), [davidgumberg](https://github.com/bitcoin/bitcoin/pull/36832#issuecomment-6839657637) | 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: * [#36946](https://github.com/bitcoin/bitcoin/pull/36946) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36946.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) * [#27865](https://github.com/bitcoin/bitcoin/pull/27865) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately by achow101) 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

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 5b70468637e0 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:f3e06854f254c480580a263b00f5c6aaa804717e751da362d6c3a17a8fae78d3:eaa37ea1cdada8fdd806ab11180fd9e0f01062422d9d8c5ea7dcfd80d5014b95 --> <!-- ralph-base:a06515e9fdf81a762804471733b1f43a13e1f10b --> <!-- ralph-head:5b70468637e00349ec9a7be35c84995f405a91e0 --> <!-- ralph-case:d5bddf9d2f364ed4e2ce821ae085dd3bab8e925f9d9dcbe16589b31ead7bb42b --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`5b70468637e0`](<https://git.fish.foo/bitcoin/bitcoin/commit/5b70468637e00349ec9a7be35c84995f405a91e0>) · [Review report](<https://review.fish.foo/report/36832-5b70468637e00349ec9a7be35c84995f405a91e0-2576-2.html>) · [Previous reports](<https://review.fish.foo/traces/36832/>) [permalink](<https://review.fish.foo/report/36832-5b70468637e00349ec9a7be35c84995f405a91e0-2576-2.html>)
maflcko (Migrated from github.com) reviewed 2026-11-10 20:35:57 +00:00
maflcko (Migrated from github.com) commented 2026-11-10 20:35:57 +00:00

concept ack. this follows the functional tests:

test/functional/test_framework/util.py:        f.write("keypool=1\n")
concept ack. this follows the functional tests: ``` test/functional/test_framework/util.py: f.write("keypool=1\n")
davidgumberg (Migrated from github.com) reviewed 2026-11-10 22:21:36 +00:00
davidgumberg (Migrated from github.com) commented 2026-11-10 22:21:36 +00:00

nit: Since the only "users" of wallet_name here and below set dummy values, maybe the name parameter can be dropped from NewWallet()?

nit: Since the only "users" of `wallet_name` here and below set dummy values, maybe the name parameter can be dropped from `NewWallet()`?
davidgumberg (Migrated from github.com) reviewed 2026-11-10 22:34:54 +00:00
davidgumberg (Migrated from github.com) commented 2026-11-10 22:34:54 +00:00

In https://github.com/bitcoin/bitcoin/pull/36832/changes/4ebe3d9597fa090438f95d33801428894ba69c9b (test: deduplicate wallet creation into NewWallet helper)

nanonit: If retouching this commit message should probably include refactor:

In https://github.com/bitcoin/bitcoin/pull/36832/changes/4ebe3d9597fa090438f95d33801428894ba69c9b (_test: deduplicate wallet creation into NewWallet helper_) nanonit: If retouching this commit message should probably include `refactor:`
davidgumberg (Migrated from github.com) reviewed 2026-11-10 22:36:20 +00:00
davidgumberg (Migrated from github.com) commented 2026-11-10 22:36:20 +00:00

Observation/question: Why were tests using CreateSyncedWallet() passing before this change?

Also, if you avoid refactoring this line, I think the interface for NewWallet is a little better taking the node argument since then you don't need to do the member access and pointer dereference at every call site, the same could apply to CreateSyncedWallet() whose callers are all also doing the same thing.

Observation/question: Why were tests using `CreateSyncedWallet()` passing before this change? Also, if you avoid refactoring this line, I think the interface for `NewWallet` is a little better taking the node argument since then you don't need to do the member access and pointer dereference at every call site, the same could apply to `CreateSyncedWallet()` whose callers are all also doing the same thing.
davidgumberg commented 2026-11-10 22:49:31 +00:00 (Migrated from github.com)

ACK aebed915d0

Reproduced the performence improvement in coinselector_tests using hyperfine, 6.952 s ± 0.050 s on master, 2.797 s ± 0.021 s on this branch.

ACK aebed915d0698dc875e100df06c7780360dc3374 Reproduced the performence improvement in coinselector_tests using hyperfine, `6.952 s ± 0.050 s` on master, `2.797 s ± 0.021 s` on this branch.
Zippo76 (Migrated from github.com) reviewed 2026-11-11 21:37:42 +00:00
Zippo76 (Migrated from github.com) left a comment

tACK aebed915d0

Tested on macOS 27.2 arm64 against master c68583ab5a. All 18 wallet unit test suites (83 test cases) pass on both master and this PR.

I reproduced the performance improvement in the four suites listed in the PR. Times below are in seconds, with five runs per suite on each revision:

Suite Master: median (min–max) PR: median (min–max) Time reduction
coinselector_tests 10.12 (9.95–11.15) 3.92 (3.85–3.94) 61%
wallet_tests 2.89 (2.83–3.13) 2.33 (2.30–2.40) 19%
spend_tests 0.74 (0.74–0.75) 0.24 (0.24–0.24) 68%
group_outputs_tests 0.38 (0.38–0.38) 0.13 (0.13–0.13) 66%
tACK aebed915d0 Tested on macOS 27.2 arm64 against master `c68583ab5a`. All 18 wallet unit test suites (83 test cases) pass on both master and this PR. I reproduced the performance improvement in the four suites listed in the PR. Times below are in seconds, with five runs per suite on each revision: | Suite | Master: median (min–max) | PR: median (min–max) | Time reduction | |-----------------------|-------------------------:|---------------------:|---------------:| | `coinselector_tests` | 10.12 (9.95–11.15) | 3.92 (3.85–3.94) | 61% | | `wallet_tests` | 2.89 (2.83–3.13) | 2.33 (2.30–2.40) | 19% | | `spend_tests` | 0.74 (0.74–0.75) | 0.24 (0.24–0.24) | 68% | | `group_outputs_tests` | 0.38 (0.38–0.38) | 0.13 (0.13–0.13) | 66% |
ViniciusCestarii commented 2026-11-12 12:30:23 +00:00 (Migrated from github.com)

Thanks for the reviews! Force-pushed 5b70468637 addressing @davidgumberg comments. I also dropped the cchain param of CreateSyncedWallet to simplify it since all callers just passed the active chain.

Thanks for the reviews! Force-pushed 5b70468637e00349ec9a7be35c84995f405a91e0 addressing @davidgumberg comments. I also dropped the `cchain` param of `CreateSyncedWallet` to simplify it since all callers just passed the active chain.
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-12 12:31:05 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-12 12:31:05 +00:00

Nice. Done on 5b70468637

Nice. Done on 5b70468637e00349ec9a7be35c84995f405a91e0
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-12 12:31:42 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-12 12:31:42 +00:00

nanonit taken haha

nanonit taken haha
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-12 12:43:09 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-12 12:43:09 +00:00

Why were tests using CreateSyncedWallet() passing before this change?

I'm not sure what you mean. It didn't change any behaviour because CreateSyncedWallet() used to create a wallet just like NewWallet() but now it reuses the NewWallet() to deduplicate code.

I think the interface for NewWallet is a little better taking the node argument

At first I thought passing chain makes more sense for a wallet function but with your comment I realized it doesn't matter much and the benefits of passing node context directly are better. Done on 5b70468637.

> Why were tests using `CreateSyncedWallet()` passing before this change? I'm not sure what you mean. It didn't change any behaviour because `CreateSyncedWallet()` used to create a wallet just like `NewWallet()` but now it reuses the `NewWallet()` to deduplicate code. > I think the interface for NewWallet is a little better taking the node argument At first I thought passing chain makes more sense for a wallet function but with your comment I realized it doesn't matter much and the benefits of passing node context directly are better. Done on 5b70468637e00349ec9a7be35c84995f405a91e0.
Zippo76 (Migrated from github.com) reviewed 2026-11-12 21:08:23 +00:00
Zippo76 (Migrated from github.com) left a comment

tACK 5b70468637

Retested on macOS 27.2.1 arm64 against master 9183edd25e. The update addresses davidgumberg's nits; the keypool remains at 1.

All 18 wallet unit test suites (83 test cases) pass on both revisions. The performance improvement remains: median time for coinselector_tests was 10.16 s on master versus 3.88 s with this PR.

tACK 5b70468637 Retested on macOS 27.2.1 arm64 against master `9183edd25e`. The update addresses davidgumberg's nits; the keypool remains at 1. All 18 wallet unit test suites (83 test cases) pass on both revisions. The performance improvement remains: median time for `coinselector_tests` was 10.16 s on master versus 3.88 s with this PR.
davidgumberg (Migrated from github.com) reviewed 2026-11-13 00:05:24 +00:00
davidgumberg (Migrated from github.com) commented 2026-11-13 00:05:24 +00:00

Right, but NewWallet() does more initialization stuff than just creating the CWallet object, it just seemed like a smell to me that those tests should pass without the wallet having the descriptor flag, and without SPKM's set up, but it's probably fine, I have not looked close.

Right, but `NewWallet()` does more initialization stuff than just creating the `CWallet` object, it just seemed like a smell to me that those tests should pass without the wallet having the descriptor flag, and without SPKM's set up, but it's probably fine, I have not looked close.
davidgumberg commented 2026-11-13 00:06:03 +00:00 (Migrated from github.com)
reACK https://github.com/bitcoin/bitcoin/commit/5b70468637e00349ec9a7be35c84995f405a91e0
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-13 12:24:02 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-13 12:24:02 +00:00

I understand what you mean now. It actually used to set those too but it is just in a lower block of code:

https://github.com/bitcoin/bitcoin/pull/36832/changes/e8f9a7c51a1e68af44123a9016edd2ead4356b3a#diff-de599d9a8f1ba87b441fa95ddb92737eef323ec968f0a9f3c38ec5a3b374045cL29-L33

-    {
-        LOCK(wallet->cs_wallet);
-        wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
-        wallet->SetupDescriptorScriptPubKeyMans();
-    }
I understand what you mean now. It actually used to set those too but it is just in a lower block of code: https://github.com/bitcoin/bitcoin/pull/36832/changes/e8f9a7c51a1e68af44123a9016edd2ead4356b3a#diff-de599d9a8f1ba87b441fa95ddb92737eef323ec968f0a9f3c38ec5a3b374045cL29-L33 ```diff - { - LOCK(wallet->cs_wallet); - wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); - wallet->SetupDescriptorScriptPubKeyMans(); - } ```
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!36832
No description provided.