Repository navigation
test: speed up wallet unit test - #36832
ViniciusCestarii wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
| std::unique_ptr<CWallet> NewWallet(interfaces::Chain& chain, const std::string& wallet_name) | ||
| { | ||
| std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(&chain, wallet_name, CreateMockableWalletDatabase()); | ||
| wallet->m_keypool_size = 1; // Avoid pre-deriving a large keypool |
There was a problem hiding this comment.
concept ack. this follows the functional tests:
test/functional/test_framework/util.py: f.write("keypool=1\n")
| std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key) | ||
| { | ||
| auto wallet = std::make_unique<CWallet>(&chain, "", CreateMockableWalletDatabase()); | ||
| auto wallet = NewWallet(chain); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 5b70468.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I understand what you mean now. It actually used to set those too but it is just in a lower block of code:
e8f9a7c#diff-de599d9a8f1ba87b441fa95ddb92737eef323ec968f0a9f3c38ec5a3b374045cL29-L33
- {
- LOCK(wallet->cs_wallet);
- wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
- wallet->SetupDescriptorScriptPubKeyMans();
- }|
ACK aebed91 Reproduced the performence improvement in coinselector_tests using hyperfine, |
Zippo76
left a comment
There was a problem hiding this comment.
tACK aebed91
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% |
… simplify CreateSyncedWallet
aebed91 to
5b70468
Compare
|
Thanks for the reviews! Force-pushed 5b70468 addressing @davidgumberg comments. I also dropped the |
Zippo76
left a comment
There was a problem hiding this comment.
tACK 5b70468
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.
|
reACK 5b70468 |

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