mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
bench: add WalletBalanceManySpent for high-history wallet scenario #34360
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!34360
Loading…
Reference in a new issue
No description provided.
Delete branch "wallet-balance-many-spent-bench-3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
To keep the setup time reasonable, the benchmark uses the fast “fake block” approach, similar to
wallet_create_tx.cpp.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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
cc @achow101 given this is inspired by #27865.
@w0xlt can you rebase this?
I might have gone a bit overboard again, I left comments documenting my review journey, please see the individual explanations - feel free to pick and choose between them.
For convenience here's my local patch against your rebased branch:
Local pending changes
We could use
NodeClockContexthere instead, like the adjacent wallet balance benchmark, so the mocked clock is restored automatically when setup leaves scope (see https://github.com/bitcoin/bitcoin/pull/34858/changes#diff-242a3d315a6189295f7169824284383659b1d83ac65241351a930348d5b8ee82L10-R39):cc: @maflcko
nit: these comments lock in the values of the configuration options above. Code comments are meant to add extra context that the code can't easily explain. Here, it's partially duplicating the code.
Please consider deduplicating the values from their meanings:
and
and
etc.
Not sure how to interpret this, why would we want to run a benchmark with
0?The description of the PR claims we have 50k total outputs, we could reserve and assert that for clarity:
these intertwined constant definitions kinda' break the abstraction for me: the point of defining them is that we shouldn't care about their exact value when we're using them.
If you agree, please consider extracting the constant initializations either at the beginning or as fields (and maybe use brace init to avoid narrowing and weird type conversions).
That would separate the concerns: when we're interested in the configuration of the benchmark (the values used) we have that concern in one dedicated place and when we're interested in the algorithm (where we want to avoid knowing the implementation details) we can just rely on the config names:
We could avoid copying the 50k COutput entries (and avoid resizing) before the spend phase by iterating the existing
AvailableCoinsresult directly:nit: this basically duplicates the logic of the previous loop - alternatively it may be simpler to understand it if we reused the logic:
For clarity on what the unnamed primitive arguments mean, please consider adding name hints:
or even better, we could extract these as suggested in https://github.com/bitcoin/bitcoin/pull/34360/changes#r3247900786
and use them as
It seems to me we could simplify this continuous-slice copy:
Similarly for
we can probably use
vector::insertfor that append instead of spelling out an equivalentpush_backloop in the helper:Why is this needed exactly? Wouldn't a
bench.warmup(1)achieve the same? That would also allow us to definebalinside:Though it kinda' begs the question: don't we want to measure the uncached state at all? Is caching referring to an internal state, i.e. the first iteration being different from the rest?
we could make the benchmark more stable and avoid:
by specifying the minimum iteration count, something like:
Is this really needed here? It walks mapWallet and invalidates per-transaction caches, while this confirmed-output balance path iterates wallet.GetTXOs(), checks spend status, and reads each remaining output value.
The benchmarks indicate the performance is also similar (except for the extra iteration):
WalletBalanceManySpentWalletBalanceManySpentThis would still pass if setup accidentally left more spendable wallet outputs than intended.
Since the benchmark claims only the configured remainder stays unspent, could we assert the exact trusted balance?
My understanding is that balance alone does not prove that spent wallet outputs remain in history, consider adding a sanity check here (should probably be done via a helper method to make it less noisy):
nit: we could initialize the fields so static analysis in my IDE stops complaining:
Just resolve if you don't think it's important.
The original code calls
ActiveTip()undercs_main, but then dereferences the returnedCBlockIndex*after the lock is released.That is probably harmless for these immutable-looking fields in this benchmark, but the helper only needs a snapshot, so it seems clearer to copy the hash/time/height while holding the lock and avoid carrying the tip pointer outside the protected region.
This also avoids the ternary, which my IDE parses poorly:
This may be slightly bigger unrelated change (generalizing wallet_create_tx.cpp to use our newly introduced methods), but maybe the
coinbase_outputsshould be exposed as a single param:add a helper delegating to this with the old signature:
which would enable us to call it from the benchmark's
generateFakeBlockand avoid a lot of duplication betweenwallet_create_tx.cppandwallet_bench_util.h.Do we need to reread the active tip here or could we do it in the previous locked scope instead?
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
Thanks. Done
@l0rinc Thanks for the thorough review. I split the changes into two commits to make them easier to review, and added you as a co-author on both since many of the improvements came from your suggestions.
I've re-run this benchmark to validate bitcoin/bitcoin#27865, which changes how wallet TXOs are retained for balance calculation.
Command used:
Results:
This is about a 2,981x speedup with #27865 for this workload.
The benchmark's purpose is to model a wallet with many spent TXOs and only a few unspent TXOs, then measure
GetBalance(). On current master, the balance path still has to deal with the large spent-output history.With #27865, the balance path only sees the relevant unspent outputs, which is the performance improvement this benchmark is intended to demonstrate.
@sedited Done.
Does
minEpochIterations(128)addresses benchmark stability better than the suggested 10?nit: Is this meant to support running the benchmark on top of #27865?
On this PR’s current base the
elsebranch should be dead code, so a short comment explaining the forward-compatibility case would help.ACK 5defb96252e0b955d1a3863f78a87ca064d9071a
Thanks for taking the suggestions. I see you've made it forward-compatible - I'm usually more strict about adding dead code, but in this case I personally don't mind. If you touch this again, either remove it and let the other PR extend the benchmark (it likely needs other changes anyway) or add a comment explaining it. I'm also fine with just adding a note to the PR's description.
🐙 This pull request conflicts with the target branch and needs rebase.
Ping @w0xlt for a rebase.
Rebased. Thanks @sedited
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/32194375855/job/95895267053LLM reason (✨ experimental): CI failed because IWYU reported/fixed noncompliant headers (#includes changes were needed), triggering a “Failure generated from IWYU” error.
Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Could turn into draft while CI is red?
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased.
No verified findings are available from this review.
Review coverage was incomplete.
Reviewed:
bc9a71bfc729· Full review report · Previous reportsI have changed my mind on this: since we don't know which direction follow-ups will take, could we rather simplify this to the assertions needed on the current base?
We can adapt them freely in a future PR if needed.
Related: Ralph's review also flags this branch. (cc: @maflcko / @willcl-ark how do we trigger @DrahtBot to update the reply?)
Simplify the output-state assertions
The summary is only updated when a comment is added or edited, see
github.com/maflcko/DrahtBot@7c658efafe/webhook_features/src/features/summary_comment.rs (L28-L32)Maybe there can be a manual one-time trigger for all pull requests, if you think an updated comment is important?
Wasn't there an option before to add a thumbs down emoji when we need an update?
No, there was only an option to react on the summary comment to have it act on the next update (
github.com/maflcko/DrahtBot@207fb31abd). I think it is enough to have the update path on comment creation or edits, but I can re-trigger it manually globally, if needed.