mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:08:38 +00:00
wallet, follow-up: Refactor IsSpent to use HowSpent #35151
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!35151
Loading…
Reference in a new issue
No description provided.
Delete branch "wallet-use-howspent-for-isspent"
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?
Follow-up to #33671
This PR refactors
CWallet::IsSpentto reuse the logic already implemented inCWallet::HowSpent.Instead of manually iterating over mapTxSpends and checking transaction states, IsSpent now simply returns:
return HowSpent(outpoint) != SpendType::UNSPENT;Also move
CWallet::IsSpentfrom wallet.cpp to wallet.h as a small inline helper, since it is a one-line wrapper around HowSpent.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.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/24890514354/job/72881342200LLM reason (✨ experimental): CI failed the
trailing_whitespacelint check due to trailing whitespace insrc/wallet/wallet.cpp.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.
concept ACK
The refactor is nice and clean.
I think it is worth adding in the commit message that this refactor has a super super small performance downgrade, but we can take it as it is negligible. Now we don't early exit if we found any condition that tells us that a coin is spent.
Given that it is a one-line function I think is fine to remove it from wallet.cpp and add the logic in wallet.h
I don't think the changes inside HowSpent are necessary. It can distract from what is really being changed.
What if I move the change to a separate commit and update everything appropriately?
Would that work?
It's just the changes are not necessary for the PR. To simplify
IsSpent()you don't need to touchHowSpent().I don't agree with them anyway. I am not a super fan of using
autoit makes code less readable as you don't know what you are using. But that's a personal opinion.Yeah. Also not a big fan of using
auto.I will address all the suggestion in the next push.
Thank you for the review.
Force pushed 8722fad
Updated the commit message as suggested.
Move
CWallet::IsSpentfrom wallet.cpp to wallet.hThere's an extra space here, that breaks the lint.
I think you can do a one line to occupy less space, similar to
SteadyClock::duration ScanningDuration():🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/24896525104/job/72902929770LLM reason (✨ experimental): CI failed because the
trailing_whitespacelint check detected trailing whitespace insrc/wallet/wallet.h(line 569).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.
Fixed. Thank you!
Concept NACK. You've made it much less efficient. Not only does it perform more checks, it also doesn't exit the loop early.
I don't think the extra checks is a performance decrease. If I am not mistaken
isConfirmed()andInMempool()only read a value already loaded inCWalletTx.I am not sure how bad it would be to ignore the early exit. But anyway it's easily solvable by adding a bool arg saying if we are checking for the exact
HowSpentor only ifIsSpent.🚧 At least one of the CI tasks failed.
Task
tidy: https://github.com/bitcoin/bitcoin/actions/runs/25172360438/job/73795063472LLM reason (✨ experimental): CI failed due to a clang-tidy error (
readability-avoid-const-params-in-decls) inwallet/wallet.hwhere parameterisSpentis const-qualified in the declaration.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.
Added commit 775964e as suggested by @polespinasa to address the early-exit concern raised in review.
HowSpentnow takes an optionalisSpentflag, allowing it to return early when used by IsSpent, restoring the previous early-exit behavior while still keeping the refactor.Thank you so much @polespinasa for the reviews and suggestions.
I will keep the changes like this to see what other reviewers thinks about it.
Great!
The commits can be squashed into one single commit. Each commit should be good for himself and the first one is a behavior change so it needs the changes in the second :)
Squashed. Thanks.
ACK
ac774b3184I am not sure about the bool variable name
isSpent. It does not self-explain what it does. But anything likeonly_check_if_spentmight be too much.The comment later in the code makes it clear and because the code function is not large I think this is not a big problem.
No verified findings are available from this review.
Review coverage was incomplete.
Reviewed:
ac774b318440· Full review report · Previous reportspermalink
Concept ACK
Not strictly a pure refactor: previously a spend counted only if the spending tx was not abandoned, block-conflicted or mempool-conflicted; now a confirmed or in-mempool spending tx counts first. These only differ for a confirmed/ in-mempool tx with non-empty
mempool_conflicts, which I don't think can happen in practice (RBF and TRUC sibling eviction both look fine), but it'd be good to mention in the commit message, or add a small unit test checkingIsSpent()andHowSpent() != SpendType::UNSPENTagree across tx states.nit: per developer-notes, function args should be snake_case. Also, since with this flag set
HowSpentreturns as soon as any spend is found (e.g.MEMPOOLeven if a later spend isCONFIRMED), the returnedSpendTypeis only meaningful as spent/unspent. Maybe a name that reflects that and a short doc comment, e.g.:Alternatively keep the public
HowSpent(outpoint)as-is and move the flagged version into a private helper.