1313#include < script/sign.h>
1414#include < script/signingprovider.h>
1515#include < sync.h>
16+ #include < util/threadpool.h>
1617#include < validation.h>
1718#include < wallet/test/util.h>
1819#include < wallet/receive.h>
@@ -26,7 +27,12 @@ static int SATS_PER_OUTPUT = 1;
2627static int FEE_SATS = 1000 ;
2728static size_t SP_RECIPIENT_GROUP_LIMIT = 1000 ;
2829
29- static void WalletSPScan (benchmark::Bench& bench, size_t num_txs, size_t outputs_per_tx, std::optional<size_t > n_payments = {})
30+ static void WalletSPScan (
31+ benchmark::Bench& bench,
32+ size_t num_txs,
33+ size_t outputs_per_tx,
34+ std::optional<size_t > n_payments = {},
35+ size_t n_workers = 1 )
3036{
3137 auto testsetup = TestChain100Setup ();
3238 auto & m_node = testsetup.m_node ;
@@ -67,7 +73,9 @@ static void WalletSPScan(benchmark::Bench& bench, size_t num_txs, size_t outputs
6773 CBlockIndex* currentTip = WITH_LOCK (Assert (m_node.chainman )->GetMutex (), return m_node.chainman ->ActiveChain ().Tip ());
6874 assert (nHeight == currentTip->nHeight );
6975
70- CWallet wallet (m_node.chain .get (), " " , CreateMockableWalletDatabase ());
76+ ThreadPool threadpool{" spbench" };
77+ CWallet wallet{m_node.chain .get (), " " , CreateMockableWalletDatabase (), &threadpool};
78+ if (n_workers > 1 ) threadpool.Start (n_workers - 1 );
7179 {
7280 LOCK (wallet.cs_wallet );
7381 LOCK (Assert (m_node.chainman )->GetMutex ());
@@ -129,8 +137,14 @@ static void WalletSPScan(benchmark::Bench& bench, size_t num_txs, size_t outputs
129137
130138 assert (GetBalance (wallet).m_mine_trusted == 0 );
131139 int expected_balance = SATS_PER_OUTPUT * num_sp_outputs * num_txs;
132-
133- bench.epochs (1 ).epochIterations (1 ).unit (" block" ).run ([&] {
140+ std::string name = strprintf (
141+ " WalletSPScan_%zuTx_%zuOutputs_%zuPayments_%zuWorkers" ,
142+ num_txs,
143+ outputs_per_tx,
144+ n_payments ? *n_payments : outputs_per_tx,
145+ n_workers
146+ );
147+ bench.epochs (1 ).epochIterations (1 ).unit (" block" ).run (name, [&] {
134148 WalletRescanReserver reserver (wallet);
135149 reserver.reserve ();
136150 auto result = wallet.ScanForWalletTransactions (
@@ -151,14 +165,15 @@ static void WalletSPScan(benchmark::Bench& bench, size_t num_txs, size_t outputs
151165 * Max Txs with a WitnessV0KeyHash input is 8245
152166 * Max Txs with a WitnessV1Taproot input is 8986
153167 */
154- static void WalletSPScanMaxTxOneOutput (benchmark::Bench& bench) { WalletSPScan (bench, 8986 , 1 ); }
155- static void WalletSPScanOneTxMaxOutputs (benchmark::Bench& bench) { WalletSPScan (bench, 1 , 23246 ); }
156- static void WalletSPScanAvgTxAvgOutputs (benchmark::Bench& bench) { WalletSPScan (bench, 3200 , 3 ); }
157- static void WalletSPScanNoPayments (benchmark::Bench& bench) { WalletSPScan (bench, 1 , 1000 , 0 ); }
158- static void WalletSPScanTenPayments (benchmark::Bench& bench) { WalletSPScan (bench, 1 , 1000 , 10 ); }
159- BENCHMARK (WalletSPScanMaxTxOneOutput);
160- BENCHMARK (WalletSPScanOneTxMaxOutputs);
161- BENCHMARK (WalletSPScanAvgTxAvgOutputs);
162- BENCHMARK (WalletSPScanNoPayments);
163- BENCHMARK (WalletSPScanTenPayments);
168+ static void WalletParallelSPScan (benchmark::Bench& bench) {
169+ std::vector<size_t > threads = {1 , 2 , 4 , 8 };
170+ for (size_t n_threads: threads) {
171+ WalletSPScan (bench, 8986 , 1 , {}, n_threads);
172+ WalletSPScan (bench, 1 , 23246 , {}, n_threads);
173+ WalletSPScan (bench, 3200 , 3 , {}, n_threads);
174+ WalletSPScan (bench, 1 , 1000 , 0 , n_threads);
175+ WalletSPScan (bench, 1 , 1000 , 10 , n_threads);
176+ }
177+ }
178+ BENCHMARK (WalletParallelSPScan);
164179} // namespace wallet
0 commit comments