mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:11:37 +00:00
wallet: drop spent parents redundant cache invalidation and notification #35786
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!35786
Loading…
Reference in a new issue
No description provided.
Delete branch "2026_wallet_drop_redundant_dirty_cache"
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?
When a transaction spends outputs owned by the wallet, the wallet invalidates
the cached amounts of the transactions those outputs came from, and
CommitTransactionalso notifies them. Neither is needed.Both date back to pre-#27286, when a
CWalletTxalso cached the availableamount. Now the balance is read live from
m_txosandmapTxSpends, andCWalletTxcache only its own, tx specific, incoming and outgoing amounts,and whether the tx is from the wallet. None of this changes after one of its
outputs is spent. So the cache invalidation recomputes the same values, and
the notification makes the GUI refresh a status that has not changed.
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:
WalletBatchwrite failures by achow101)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.
Concept ACK
Checked https://github.com/bitcoin/bitcoin/pull/27286.
After the above PR, the per-transaction caches (
m_amounts,m_cached_from_me) reflect the transaction's own incoming/outgoing amounts — none of these change when a child tx spends one of the parent's outputs. SoMarkInputsDirtyis forcing a recompute that produces the same result, and theCommitTransactionnotification loop is asking the GUI to repaint a row that looks identical. Both are dead work; removing them is correct.Left some comments and nits (none blocking).
minor nit:
bool is_from_me;(I understand that perhaps it could be mirroringCachedTxIsFromMeinspend.cpp-bool tx_from_me)minor nit: perhaps
CheckValuesUnchangedorAssertValuesUnchangedmake the intent immediately clear at the call site...typo nit (the body in 59da62d2e28d5986d9445e583663e63c9eed4911 is correct):
nit: in fb9c53c515cabbb89ff2429a2c7cd3f9f7da2823, the comment "Only importing a descriptor could make values change" applies to
m_cached_from_metoo? If so, perhaps could extend it to cover both.Option A — extend the block comment to cover both fields, drop the separate one:
Option B — keep the separate comment but cross-reference:
Option A seems cleaner.
MarkInputsDirtywas actually a slightly misleading name (it marks the parent transactions dirty, not the inputs themselves), so removing it entirely is the best outcome.any parent tx that is wallet-relevant would be its own
desc_txand getMarkDirty()in its own iteration, is that the reasoning? (apart fromAddWalletDescriptorcallsCWallet::MarkDirty()at the end regardless)?The change values also have the same behaviour. We could probably move the "Only importing a descriptor could make values change" at the top, just below "Memory only" or.. encapsulate all values in a struct. But still, seems a tiny nit we could leave it as is too.
Not sure I understand the comment. Resetting a transaction's cache when no new descriptor has been imported results on the exact same values being re-computed again.
I don't think this add much value, the intent should be clear enough as is now. But could change it if you are strong on it.
Not sure. Everything is tx based, it is inside the TxValues struct.
done, pushed
ACK 0ec1a08131.
I agree
MarkInputsDirtyis no longer needed. As explained in the description, since https://github.com/bitcoin/bitcoin/pull/27286CWalletTxno longer saves on cache the amount aviable to spend since this was moved tom_txosandmapTxSpends. Now, theCWalletTxit only save them_amountswhich saves the fixed incoming and outgoing amounts, and them_cached_from_mewhich saves whether the tx originated from the wallet.In bdf7c84eda, the tests checks, through various paths, that the cached values are not changed. The first test checks the
CommitTransactionandAddToWalletpath by commiting a transaction that spends from a coin owned by the wallet, and theRecursiveUpdateTxStatepath by usingAbandonTransactionon a spending transaction. The other test, chechs theSyncTransactionpath by usingtransactionAddedToMempoolwith a spending transaction.Concept ACK
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
9a075fca12I never preferred reading those mark dirty calls, used to break my flow.
Good that they can be removed now.
ACK
9a075fca12Confirmed only the typo fix and a rebase since my last review — nothing else changed.
🐙 This pull request conflicts with the target branch and needs rebase.
This invalidation is still needed in a narrow case. A transaction pays 1 BTC to each of two wallet addresses, but the wallet hasn’t derived one address yet, so it recognizes and caches only 1 BTC.
A later spend can expand the keypool and make the wallet recognize the second payment. Without this invalidation,
gettransactionstill reports 1 BTC, even though details shows both payments.The test below passes on master (
51ddab532c) and fails on4591142a8f: the parent’s amount remains 1 BTC when 2 BTC is expected.It’s a very narrow edge case, but it may still be worth addressing.
diff
Concept ACK
The test proves that they are not required post-#27286
The same output is persisted across memory and wallet reload, even with these excluded
This appears to be outside the confines of the PR description as pointed out by @w0xlt because of the keypool logic. Commenting it out in my master branch removes the invalidation logic, which leads to the unexpected behavior. Probably it should be retained for recomputations
1 minor finding
🟠 Minor
Keypool top-up can leave a parent’s cached credit stale
Location:
src/wallet/wallet.cpp:1418(base).gettransactioncan omit an output the wallet has since recognized as its own; balances and coin selection are unaffected, and the production impact is unconfirmed.Details and suggested fix
A keypool top-up can add scripts to the wallet’s cached set, changing whether an output belongs to the wallet.
TopUpCallbackupdates the script cache but does not invalidate cached transaction amounts. If a parent’s credit was cached before a spend triggers a top-up, that credit can remain stale until the parent is re-added or the wallet reloads.gettransactioncan then report anamountthat omits the output while itsdetailslist it. Balances and coin selection are unaffected because they readm_txos, which this path does not refresh. In avoid-reuse wallets,MarkDestinationsDirtymay still clear the parent’s cache. Mark wallet transactions with outputs to newly added scripts dirty inTopUpCallback; the comment should also say cached values can change when the wallet’s script set changes, not only on descriptor import. No current production flow that pays a not-yet-derived wallet script was identified, so the frequency of this behavior in production is unconfirmed.Previous reports
Previous reports of the same concern:
4591142a8fc876d280e0a0a6a61ee3c497010a65. Last checked at4591142a8fc876d280e0a0a6a61ee3c497010a65.4591142a8fc876d280e0a0a6a61ee3c497010a65. Last checked at4591142a8fc876d280e0a0a6a61ee3c497010a65.Review coverage was incomplete.
Reviewed:
4591142a8fc8· Full review report · Previous reports