Provider refusals
write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.
3 major findings · 2 minor findings · 1 suggestion
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.
Findings
[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).
Details and suggested fix
The new throw occurs after the script/pubkey maps, descriptor cache, m_max_cached_index and range end have advanced, but before TopUpCallback publishes the scripts. Unwinding TopUp rolls back the database cache rows without restoring that live state. A same-size retry starts beyond the extension, so it publishes no missing scripts and rewrites no cache rows, yet persists the enlarged range. Addresses subsequently returned from the failed extension are not recognized by CWallet::IsMine, so payments can be missed until reload and rescan. For hardened-wildcard descriptors, the missing per-index cache rows instead make Load fail. Stage the extension and ownership publication until commit, or restore the live extension before throwing. Add a fault-injection test covering retry, ownership and reload. No production occurrence of this transient failure was identified.
[major] · Order-position write failure leaves a half-added transaction in mapWallet
An ORDERPOSNEXT write failure now leaves a new transaction in mapWallet without spend or history indexes, and retrying the same transaction does not repair those indexes.
Location: src/wallet/wallet.cpp:1043 (head).
Details and suggested fix
AddToWallet inserts the transaction before calling IncOrderPosNext. The new failure return therefore skips wtxOrdered.insert, AddToSpends and the transaction-record write, without removing the entry. A later call for the same txid takes the existing-entry path, which only calls CWalletTx::Update and never completes that initialization. The transaction remains absent from listtransactions, and its inputs are not tracked as spent by IsSpent. RPC callers can continue using this inconsistent wallet after receiving the database error. Erase the newly inserted entry and restore nOrderPosNext on this failure path, so a retry performs normal initialization. Add a one-shot write-failure test checking both indexes after retry. No production occurrence of this transient failure was identified.
[major] · Failed recursive state writes leave descendants unreachable on retry
After a metadata write failure, abandontransaction now skips descendants and input-cache invalidation, while a retry reports success without completing either.
Location: src/wallet/wallet.cpp:1368 (head).
Details and suggested fix
AbandonTransaction changes the root's state before WriteTxMetadata. The new throw leaves it abandoned in memory but exits before queuing descendants or calling MarkInputsDirty. RPC dispatch reports the exception without unloading the wallet. After storage recovers, retrying passes the depth and mempool checks, but the already-abandoned root returns UNCHANGED, so the RPC succeeds without visiting descendants. They continue reserving their other wallet inputs, and input balance caches remain stale. The unpersisted root was already possible at base, but base still completed the traversal and invalidation. Stage the recursive transition in a database transaction and publish the new states only after commit. Test a one-shot failure followed by retry with a parent and child. No production occurrence of this transient failure was identified.
[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).
Details and suggested fix
For a disconnected wallet coinbase with in-wallet descendants, CWalletTx::Update has already persisted the root as abandoned before this walk starts. If its redundant root write fails, the new return nullptr exits before collecting any descendants. Reload does not repair this: LoadToWallet propagates only block conflicts, and scanning the active chain cannot replay the disconnected coinbase. The descendants remain unabandoned and reserve their other wallet inputs until manually abandoned. Complete the walk and report persistence failures afterward, rather than returning before descendant discovery. This requires a deep reorg and a write failure after the earlier root write succeeded; no production occurrence was identified.
[minor] · Checkpoint write failure blocks otherwise viable wallet backups
backupwallet now 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).
Details and suggested fix
BackupWallet now returns before GetDatabase().Backup() when WriteBestBlock fails. This prevents copying a still-readable wallet from a source volume that cannot accept writes, such as a full disk, to a healthy destination. SQLite's backup operation reads the source and writes the destination, so the failed checkpoint update need not prevent the copy. Base still attempted it, and this PR treats a stale checkpoint as recoverable on unload. Log or return a warning and still attempt the backup. Restoring the older checkpoint may require an earlier rescan, including obtaining unavailable blocks on a pruned node.
Optional improvements
[suggestion] · The new export error is malformed and omits the transaction ID
The translatable WriteFullTx error says “Unable to write the a tx record” and does not identify which transaction failed.
Location: src/wallet/export.cpp:171 (head).
Details and suggested fix
Replace this with strprintf(_("Error: Unable to write tx %s to watchonly wallet"), txid.GetHex()). This fixes the wording before translation and identifies the failed transaction, as the adjacent LoadToWallet error already does.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Report a failed version write as a load failure
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Encryption has an explicit persistence-before-publication guarantee: live encryption state is published after transaction commit, and newly inserted descriptor keys are published only after their database writes succeed. This preserves keys on failure and permits retries.
The prerequisite encryption work explains why reporting an error is not, by itself, sufficient protection against memory/disk divergence. At the pinned base, descriptor encryption stages its key-map replacement in an on-commit callback. This is an established operation-specific guarantee, not evidence that arbitrary WalletBatch writes automatically undo live wallet mutations.
Address-request failure is expected not to alter the keypool. Historical descriptor-wallet work specifically corrected returning an index that had never been reserved, because the resulting rewind could give the user the same change address twice.
This directly constrains descriptor-index rollback: undoing an unsuccessful allocation must restore the allocation being attempted, not reclaim an earlier, potentially exposed address. The pinned head decrements the index when persisting a newly allocated destination fails, before returning that destination to the caller. The existing ReturnDestination path separately restricts reclamation to the most recent index.
The best-block locator is a restart checkpoint intended to track persisted wallet scan state. Its update schedule deliberately balances database writes against reload rescan cost: write when a relevant block changes the wallet, on disconnection, periodically every 144 blocks, and on unload.
This explains why a failed checkpoint write can be treated differently from a failed key or transaction write: an older checkpoint can cause previously processed blocks to be scanned again. It also limits that rationale to a conservative checkpoint; it does not justify a checkpoint advancing beyond wallet data that actually reached disk. The pinned reload path finds a fork from the stored locator and scans forward.
Ralph's inferences
Database transaction rollback and rollback of live wallet objects are separate responsibilities. WalletBatch invokes registered commit or abort listeners only after the corresponding database operation succeeds; it does not provide a general snapshot-and-restore mechanism for wallet memory.
This distinction governs descriptor top-up and transaction-state updates that mutate live structures before writing. Both the base and head top-up paths populate script/pubkey maps and descriptor caches before completing persistence. Returning an error or throwing stops further work, but does not itself establish restoration of those mutations. The encryption callback pattern demonstrates an explicit way this responsibility is handled for a particular operation.
Destructor-driven abort is a database-isolation backstop: an unfinished transaction must not remain available for a later operation to commit accidentally. SQLiteBatch::Close retries rollback and, if rollback fails, closes and reopens the connection to discard the unfinished transaction.
This is the concrete recovery mechanism behind RunWithinTxn's reliance on scope exit after an abort failure. It protects database transaction boundaries, not arbitrary wallet-memory consistency. Recovery also has limits: the pinned code rejects connection refresh for an in-memory database and propagates reopening failures.
Persistent transaction-state changes are accounting changes, not merely display metadata: they propagate through descendants and invalidate caches used to determine balances and spentness. Failure notification and restoration of earlier mutations are therefore distinct concerns.
The base RecursiveUpdateTxState changes a transaction, marks it dirty, persists metadata, visits descendants, and invalidates input caches. The head AddToWallet likewise changes live transaction structures before several checked writes. These paths support neither assuming automatic memory rollback after an error nor extending the recoverability of a stale scan checkpoint to every failed transaction-state write.
Two narrowly defined writes are treated as recoverable rather than as loss of the underlying wallet data: scan-checkpoint updates can be recovered by scanning again, and legacy encrypted-key checksum rewrites can be retried without requiring replacement key material.
The checksum rewrite runs after successful decryption of an existing encrypted key; the pinned head explicitly states that failure leaves no data missing from disk and the work can be repeated on a later load. Checkpoint recovery similarly reuses existing chain data, but is conditional on block availability: the reload path can fail when pruning or an assumed-valid chain leaves required blocks unavailable. Neither mechanism is a general recovery promise for missing private keys, address-book data, or unpersisted transaction metadata.