#35151 wallet, follow-up: Refactor IsSpent to use HowSpent
https://github.com/bitcoin/bitcoin/pull/35151 · · +8/-24 in 2 files, 1 commits · labels: none
Goal
- Remove duplicated transaction spend-checking logic in wallet code
This PR refactors CWallet::IsSpent to delegate to CWallet::HowSpent instead of independently iterating over mapTxSpends. It adds an optional boolean parameter to HowSpent to preserve early-exit behavior when callers only need an existence check, and inlines IsSpent in wallet.h.
Problem: CWallet::IsSpent and CWallet::HowSpent duplicated logic for looking up spending transactions in mapTxSpends and checking whether spending transactions were abandoned or conflicted.
Category: Wallet (#79 of 84)
P4 · cleanup
- P4 because it is a minor internal cleanup deduplicating around twenty lines of code
- It does not fix any bugs, improve fund safety, or provide user-visible benefit
P4 because this is a minor internal code cleanup. It deduplicates ~20 lines between IsSpent and HowSpent without fixing a bug, enhancing fund safety, or offering any user-visible benefit.
Membership: Changes CWallet spend-checking methods in src/wallet/wallet.h and src/wallet/wallet.cpp.
Factors: security/stability 0, bug 0, performance 0, user value 0, leverage 0
Reviewability: Stale: Author silent 135 days
- Author silent for 135 days
The author has not had any activity on the pull request for 135 days, exceeding the 60-day project staleness threshold.
Author status: silent since 2026-05-05
Resolved concerns:
- luke-jr raised a Concept NACK noting that delegating to HowSpent performed extra checks and lost the early exit in the loop; author pushed an update adding an isSpent flag to HowSpent for early exit, which polespinasa reviewed and ACKed, and luke-jr did not reply further.
Agreement: Strong
- Concept NACK on original version due to extra checks and lost early exit (luke-jr)
- Author pushed an early-exit fix to address the concern with no follow-up from objector
- Approval of the refactor as a clean deduplication (polespinasa)
luke-jr Concept NACKed over efficiency; author pushed early-exit fix, polespinasa ACKed with rationale, no further objections
luke-jr objected to the initial version due to extra checks and lack of an early exit. The author implemented an early-exit parameter in HowSpent to address the concern. polespinasa ACKed the change as clean deduplication, and luke-jr did not follow up.
- luke-jr: 'Concept NACK. You've made it much less efficient. Not only does it perform more checks, it also doesn't exit the loop early.'
- musaHaruna pushed commit adding an early-exit flag to HowSpent to address the concern.
- polespinasa: 'ACK ac774b318440c7cc4804516b1f811005e25e8d45'
Review verdicts (DrahtBot): 1 -1
- ACK: polespinasa
- Concept NACK: luke-jr
Files
0 lines under test/bench/ci.
- src/wallet/wallet.cpp +4/-22
- src/wallet/wallet.h +4/-2
Card
This PR refactors CWallet::IsSpent to call CWallet::HowSpent with an early-exit flag, deduplicating the spend-checking loop in wallet.cpp. It addresses minor internal code duplication left over from PR 33671. An initial Concept NACK from luke-jr regarding efficiency was addressed by adding an early-exit flag, which polespinasa subsequently ACKed. The author has been inactive for over four months, rendering the pull request stale.