mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
wallet: Handle or explicitly ignore WalletBatch write failures #35998
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!35998
Loading…
Reference in a new issue
No description provided.
Delete branch "walletdb-nodiscard"
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?
A common theme in the wallet is that many database write failures are ignored, when they should probably be handled, or at least documented that a failure is being ignored. This PR marks all database functions in
WalletBatchas[[nodiscard]]so that a compiler will tell us if a return value is implicitly ignored. All of the calls to those functions are updated to either deal with failure, or explicitly ignore it with a rationale.Based on #35752 which handles failures for the encryption functions.
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.
LLM Linter (✨ experimental)
Possible typos and grammar issues:
src/wallet/export.cpp:Unable to write the a tx record→Unable to write the tx record[the wording is grammatically broken]2026-11-24 20:36:55
Concept ACK, thanks for taking over.
Please see the latest push in https://github.com/bitcoin/bitcoin/pull/35752#issuecomment-5320733236, feel free to adjust it any way you like.
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32908277972/job/97996971269LLM reason (✨ experimental): CI failed because the fuzz target
rpccrashed with exit code3221225477(Windows access violation / segfault).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 f8b9da8007ad6468618fc8e4235508a5b7038386 because it enforces the handling of database errors, thereby ensuring consistency between in-memory behaviour and databases behaviour.
Concept ACK
Left some comments.
The throw propagates out of
TopUpbeforeTxnCommit, so the cache items roll back whilem_max_cached_indexand the new range end stay in memory. The retry then derives nothing andWriteDescriptorsucceeds, persisting a range wider than the cache behind it. Reopening that wallet stops withUnable to expand wallet descriptor from cacheand returnsError loading <file>: Wallet corrupted; before this change, it reopens fine.It depends on the descriptor. I hit it with
wpkh(<xprv>/0h/*h), which needs a cached xpub per index; a plainwpkh(<xprv>/0h/0/*)reopens with no error.Worth rolling the in-memory side back when the write fails?
All three of these go unnoticed by the suite as it stands, and
FaultInjectingDatabasecovers each of them with a single injected failure. TheTopUpWithDBone also needs a file-backed variant, since the in-memory database dies with the wallet and the effect only shows on reload.The
emplace()intomapWallethappens beforeIncOrderPosNext(), so this return leaves the entry behind with nonOrderPos, nowtxOrderedslot and noAddToSpends, and every later call with the same txid then takes the!fInsertedNewpath and reports success without repairing it. WithCommitTransaction'supdate_wtx, thetxrecord still reaches disk whilewtxOrderedstays empty. Before this change, the first call returns the wtx and writes thetxrecord.A stale locator only costs a rescan on the next load, but here it cancels the backup before
Backup()is reached. With the best block write failing,BackupWalletreturns false and no copy is taken; before this change,Backup()still runs. This is the copy you most want when the database starts refusing writes. Would logging and carrying on make sense here?On a genuinely full disk, with just enough room left for the database to open, this reports
Error loading <file>: Wallet corruptedwhile nothing is corrupt.With that swap, loading still fails, but it is reported only as
Error loading <file>. I seeEraseMasterKeybelow already returnsCORRUPT, so this may well be deliberate.No. If a write fails, it is possible that the database is already corrupted, and we do not want to be making a backup that may not be usable.
This is ok, a failure here results in an exception higher up in the call stack which will result in a crash. Database write failures are supposed to be catastrophic, they are not expected to happen.
What retry?
Write failures are supposed to be catastrophic and an indicator that corruption has likely happened.
it is not necessary to leave review comments describing what is happening in the code.
Failure to write is always corruption, regardless of how that may come about. We don't know why the write failed, it could be for reasons other than a disk being full.
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/34902498233/job/104171483904LLM reason (✨ experimental): IWYU failed because it detected/introduced required
#includefixes (e.g., insrc/interfaces/wallet.h), causing the CI step to exit non-zero.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.
🐙 This pull request conflicts with the target branch and needs rebase.
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🔴 Major · Failed top-ups leave address ownership and descriptor caches out of sync
After a descriptor write fails during range extension, later address requests can return scripts missing from
CWallet::IsMine, and hardened-wildcard descriptors can become unloadable after a successful retry.Location:
src/wallet/scriptpubkeyman.cpp:1176(head).🔴 Major · Order-position write failure leaves a half-added transaction in
mapWalletAn
ORDERPOSNEXTwrite failure now leaves a new transaction inmapWalletwithout spend or history indexes, and retrying the same transaction does not repair those indexes.Location:
src/wallet/wallet.cpp:1043(head).🔴 Major · Failed recursive state writes leave descendants unreachable on retry
After a metadata write failure,
abandontransactionnow skips descendants and input-cache invalidation, while a retry reports success without completing either.Location:
src/wallet/wallet.cpp:1368(head).🟠 Minor · The inactive-coinbase walk can leave descendants unabandoned across reload
During a deep reorg, failure of the coinbase's redundant metadata write can skip descendant abandonment, leaving their other wallet inputs reserved even after reload.
Location:
src/wallet/wallet.cpp:1082(head).🟠 Minor · Checkpoint write failure blocks otherwise viable wallet backups
backupwalletnow refuses to copy a readable wallet when its checkpoint update fails, although an older locator can be recovered by rescanning if the required blocks are available.Location:
src/wallet/wallet.cpp:3122(head).🔵 Suggestion · The new export error is malformed and omits the transaction ID
The translatable
WriteFullTxerror says “Unable to write the a tx record” and does not identify which transaction failed.Location:
src/wallet/export.cpp:171(head).Reviewed:
c145c2ca757e· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
Makes a lot of sense to work with the
all-or-nothinglogic here. A purpose or name failure (less tragic) means that the more tragic ones (WriteAddressReceiveRequestandWriteAddressPreviouslySpentmay also fail.Frankly, a mild issue like @jeanpablojp's disk full/permissions read-write restrictions reporting
BErrors::CORRUPTmay misguide the user giving then unnecessary tensions. For the others, this may fly, for loading the database IMHO, a log might probably help instead of locking them out with the error...Wallet corrupted🐙 This pull request conflicts with the target branch and needs rebase.