mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
wallet: skip APS when no partial spend exists #34405
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!34405
Loading…
Reference in a new issue
No description provided.
Delete branch "aps-skip-no-partial-spend"
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?
Fixes #25150
APS (Avoid Partial Spends) runs a second coin selection pass that spends many
(possibly all) or none of the UTXOs sharing a scriptPubKey. The second pass runs
even when the first selection left no partial spend for it to avoid, and
aps_create_tx_internal then reports APS as used whenever the grouped result is
taken, overreporting how often a partial spend was avoided.
Detect partial spends by comparing selected vs available UTXO counts per
scriptPubKey, reusing the coins already fetched for selection and counting
manually selected inputs towards their scriptPubKey. Skip APS if none found.
Functional tests cover APS being skipped and a manually selected input making
the spend partial.
Supersedes #34362.
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
Reviewers, 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.
This condition can be grouped with the others in the line above, there's no need to separate it with it's own return statement.
The default for
wallet_nameis essentiallyself.default_wallet_name, so set it to that instead of usingNone.Done, combined.
selfisn't available at function definition time in Python. The=Nonewith internal check matches the pattern used elsewhere in the test framework (e.g.,extra_argsinadd_nodes()).🐙 This pull request conflicts with the target branch and needs rebase.
@8144225309 this has been in need of a rebase for a while. Are you still interested in working on this change?
Thank you for pinging me, resolving conflicts now.
Rebased onto master. The only conflict was CreatedTransactionResult moving from
FeeCalculation to FeeReason; no other code changed, and the rest of the src/ diff
is comments.
The new wallet_groups.py coverage is a separate commit; the tracepoint test changes
stay with the code commit. That test needs bcc and does not currently run in CI, so
both new scenarios assert on the debug log instead: APS skipped when nothing is
partially spent, and a manually selected input counted towards its scriptPubKey. The
tracepoint test also gains a case asserting use_aps with no change output.
range-diff
🔵 Suggestion · Preset-only selections trigger a redundant APS retry
When preset inputs cover the target, the grouped pass selects the same inputs but still reports APS as used, leaving the partial spend unchanged; this behavior also exists on the base branch.
Location:
src/wallet/spend.cpp:1255(head).🔵 Suggestion · Partial-spend counting adds overhead when the retry cannot use it
The wallet builds and discards a per-UTXO map on several paths where the APS retry is disabled; the resulting cost is unmeasured.
Location:
src/wallet/spend.cpp:1255(head).Reviewed:
559cd158c296· Full review report · Previous reportsconcept ACK
8a30292d59I am not really familiar with this part of the wallet codebase but it looks pretty good to me.
Left a few suggestions before ACKing it :)
in
e382330b92wallet: skip APS when no partial spend existsBy calling
available_coins.All()andpreset_inputs.All()(both areCoinsResult::All()) you are creating two new temporary vectors ofCOutput.You can just iterate the original vectors, with something like:
You can ignore the lamda, it is just a personal preference, it is fine with me to have two loops :)
in
8a30292d59test: add coverage for partial spend detectionI would probably assert also here the len of
vinsimilar to what you did in line 206in
8a30292test: add coverage for partial spend detectionThe test has a premise and is that the two UTXOs that the wallet has are owned by different scriptpubkey, maybe asserting it in the code would serve as documentation.
Took @polespinasa's suggestions: the partial spend check now iterates
CoinsResult::coinsinstead of copying throughAll(), and the no-partial-spend case asserts its premise and the input count. Also dropped the unused default on the newCreatedTransactionResultparameter, so callers must pass it. No rebase.Done, thanks. Used two loops.
Done.
Done.