Skip to content

Conversation

@w0xlt
Copy link
Contributor

@w0xlt w0xlt commented Jan 21, 2026

This PR introduces a new benchmark that measures GetBalance() performance on wallets with extensive transaction history where the majority of outputs have already been spent.

It was created to test #27865, which separates spent TXOs from spendable ones.
This pattern mirrors real-world usage in high-activity wallets such as Lightning nodes, exchanges, hot wallets, and payment processors.

Setup:

  • Creates 500 blocks × 100 coinbase outputs = 50,000 wallet TXOs
  • Matures all coinbases with COINBASE_MATURITY additional blocks
  • Spends 49,950 outputs in batched transactions (confirmed in blocks)
  • Consolidation outputs go to a burn script to avoid inflating wallet TXO count

To keep the setup time reasonable, the benchmark uses the fast “fake block” approach, similar to wallet_create_tx.cpp.

Add a benchmark that measures `GetBalance()` performance on wallets with
extensive transaction history where most outputs have been spent.

Scenario: 50,000 TXOs with 49,950 spent and 50 unspent.

This pattern is common in high-activity wallets (Lightning nodes, exchange
hot wallets, payment processors) and is the target scenario for optimizations
that separate spent TXOs from spendable ones.

Setup:
- Creates 500 blocks × 100 coinbase outputs = 50,000 wallet TXOs
- Matures all coinbases with COINBASE_MATURITY additional blocks
- Spends 49,950 outputs in batched transactions (confirmed in blocks)
- Consolidation outputs go to a burn script to avoid inflating wallet TXO count

Introduces `src/bench/wallet_bench_util.h` with utilities for wallet
benchmarks (TipBlock, GetTip, GenerateFakeBlock).
@DrahtBot DrahtBot added the Tests label Jan 21, 2026
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 21, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34360.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32430 (test: Add and use ElapseTime helper by maflcko)

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.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1) in src/bench/wallet_balance.cpp
  • GenerateFakeBlock(params, test_setup->m_node, wallet, burn_script, 1, 50 * COIN, block_txs) in src/bench/wallet_balance.cpp

2026-01-21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants