Provider refusals
write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.
4 major findings · 3 minor findings · 4 suggestions
Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.
Findings
[major] · Newly owned conflicted outputs can make balance queries abort the node
An operator import or keypool refill can make getbalances abort the node by indexing a newly owned conflicted output; no production wallet history exhibiting this sequence was found.
Location: src/wallet/wallet.cpp:3826 (head).
Details and suggested fix
When an output is absent from both maps, RefreshTXOsFromTx chooses its container using only IsSpent(outpoint, 1). If an unlocked wallet imports ownership of another output of an already block-conflicted transaction, that output enters m_txos despite its negative depth. RefreshAllTXOs runs before the import rescan, and the conflicted transaction is neither in the active chain nor eligible for resubmission, so those paths do not repair it. The next GetBalance reaches Assert(tx_depth >= 0), which aborts the process. Base excluded such outputs from its balance buckets without asserting. Reloading repairs the partition through PruneSpentTXOs. Use the same creator-conflicted-or-confirmed-spent predicate for fresh insertion as for pruning, and cover importing an extra output of a conflicted transaction followed by getbalances.
[major] · Disconnected spenders leave their inputs hidden after conflict or abandonment
A disconnected spender blocks restoration of its own inputs, and later conflict or abandonment leaves now-unspent coins missing from balances and coin selection until the wallet is reloaded.
Location: src/wallet/wallet.cpp:3899 (head).
Details and suggested fix
blockDisconnected makes the spender inactive, then AddToWallet calls MaybeMarkTXOUsable for its inputs. That helper calls IsSpent with the default min_depth=0, which counts the inactive, non-abandoned spender itself. For example, if a confirmed transaction spends A and B and a reorg confirms a replacement spending only A, B stays in m_unusable_txos even after the original spender becomes block-conflicted. Abandoning a disconnected transaction outside the mempool likewise fails to restore its inputs because RecursiveUpdateTxState only repartitions its outputs. Both balance calculation and coin selection iterate only m_txos; inactive-spend nonmempool accounting is also omitted. Restore according to the partition invariant: no confirmed spender and no block-conflicted creator. Leave unconfirmed-spend filtering to HowSpent and IsSpent at use time, and test both recovery paths without reloading.
[major] · Migration can delete an outgoing transaction processed before its parent
With child-before-parent insertion order, migration can remove an outgoing transaction and count its spent input as available; no production wallet exhibiting this order was found.
Location: src/wallet/migration.cpp:212 (base).
Details and suggested fix
Consider a legacy wallet that records child C through a watched output, then discovers its spendable funding parent P through a later key-import rescan. C keeps its earlier insertion position. Base populated every locally owned output before checking relevance, but this change clears both TXO maps and indexes each transaction only after classifying it. When C has no main-wallet output, IsFromMe cannot find P's output and reports false. If the watch-only wallet claims C, migration removes C from the main wallet, including its mapTxSpends entries, so P's spent output appears unspent after the index rebuild. Coin selection can then choose an already-spent input, whose broadcast would fail. Without watch-only relevance, migration instead fails with the identification error. Build the complete owned-output index independently of m_from_me before classifying transactions, and test this reversed-insertion history.
[major] · Watch-only migration copies the main wallet's m_from_me classification
For shared transactions with different input ownership, migration makes the watch-only wallet return incorrect amount and fee values from gettransaction, including after reload.
Location: src/wallet/migration.cpp:253 (head).
Details and suggested fix
watchonly_from_me only controls whether to copy the transaction. The serialized copy retains the source wallet's m_from_me, which LoadToWallet uses and WriteFullTx persists. For a main-wallet input paying a watched address, the watch-only wallet therefore stores true despite owning no input. PushTxAmountAndFee reports the entire output value as a positive fee and subtracts it from the received amount. In the reverse ownership case, it omits the fee and reports the fee-inclusive debit as the amount. Reloading trusts the present field; a later transaction update or ownership refresh can correct it. Assign copy_wtx.m_from_me = watchonly_from_me before LoadToWallet, and check both wallets' amounts and fees after migration and reload.
[minor] · The m_from_me upgrade persists false for children visited before their parents
An old wallet whose child precedes its parent can persist m_from_me=false and misreport transaction amounts and fees; no production wallet exhibiting this order was found.
Location: src/wallet/walletdb.cpp:1090 (head).
Details and suggested fix
LoadToWallet skips output indexing for records missing m_from_me. The upgrade then computes IsFromMe, indexes outputs and writes metadata in one pass over wtxOrdered. A child recorded through its own owned output before a later import discovers its parent therefore cannot find that parent's output in GetTXO. The resulting false value is persisted and trusted on later loads, causing gettransaction to omit the fee and report the fee-inclusive debit as the amount. A transaction update or ownership refresh against a complete index can correct it. Reordering first is insufficient because ReorderTransactions uses receive time, not dependencies. Index all owned outputs first, then compute and persist classification in a second pass. Add a reversed-insertion dependent pair and check amounts and fees across reload.
[minor] · Transaction upgrades write records even after wallet loading detects corruption
LoadTxRecords can persist m_from_me computed from an incomplete index and reorder records before LoadWallet rejects the corrupted wallet.
Location: src/wallet/walletdb.cpp:1088 (head).
Details and suggested fix
LoadRecords continues after an unreadable transaction record and accumulates its error. If another record lacks m_from_me, the upgrade still rewrites all successfully loaded transactions, potentially classifying children without their unreadable parents. The relocated ReorderTransactions also writes whenever unordered records were found. Both operations now precede LoadWallet's aggregate error guard, which previously protected reordering and explicitly prohibits upgrades after corruption. A subsequent successful load can trust the incorrect present classifications. Defer these upgrade and reorder writes until after the aggregate LOAD_OK check so failures in transaction loading or earlier ownership-record loading cannot trigger them.
[minor] · CreateSyncedWallet callers leave a notification ownership cycle
The test helper now returns a registered wallet that strongly owns itself through its notification handler, so dropping the returned shared_ptr does not destroy it.
Location: src/wallet/test/util.cpp:26 (head).
Details and suggested fix
CreateNew calls AttachChain, which stores handleNotifications(walletInstance) in the wallet. The handler owns a NotificationsProxy, and that proxy holds a shared_ptr back to the wallet. ListCoinsTestingSetup only calls wallet.reset(), while the spend tests let their local pointers leave scope, leaving the wallet allocated and registered for callbacks. Base created an unregistered unique_ptr. Unload these wallets through TestUnloadWallet(std::move(wallet)), which drains notifications and resets the handler before releasing ownership. In the spend test that holds cs_wallet through the end of its body, release that lock before unloading.
Optional improvements
[suggestion] · Persisted m_from_me can retain stale ownership classification
Computing m_from_me in memory after indexing all outputs would avoid the full transaction-record upgrade and stale classifications left by ignored metadata-write failures.
Location: src/wallet/transaction.h:306 (head).
Details and suggested fix
RefreshAllTXOs changes m_from_me in memory before calling WriteTxMetadata and ignores the result. If that write fails, another refresh sees no value change and does not retry; reloading then trusts the old persisted value because the field is present. Prefer keeping this derived ownership value memory-only and computing it after the complete TXO index is available, while retaining cached access during normal operation. This requires traversing transaction inputs on each load, but removes the upgrade rewrite and the need to keep disk copies synchronized with ownership. If persistence is required for load performance, add a way to invalidate or recompute present values rather than trusting presence alone.
[suggestion] · CachedTxIsTrusted tests optional engagement instead of the cached value
!wtx->m_from_me skips the intended cached rejection and performs needless parent lookups, although the following input checks still reject transactions with unowned inputs.
Location: src/wallet/receive.cpp:213 (head).
Details and suggested fix
m_from_me is a std::optional<bool>, so an engaged false value makes !wtx->m_from_me false. With zero-confirmation change enabled, every mempool transaction therefore proceeds to the parent-input loop instead of using its cached classification to reject early. Read the contained value with !*wtx->m_from_me or .value(), asserting engagement if needed, to restore the intended early exit.
[suggestion] · ListCoinsTestingSetup::AddTx overwrites the notification result
The manual SetState after draining notifications repairs transaction and TXO state before the tests can check whether confirmation notifications updated them correctly.
Location: src/wallet/test/wallet_tests.cpp:501 (head).
Details and suggested fix
CreateSyncedWallet now registers the wallet for notifications, and CreateAndProcessBlock places this transaction at index 1 after the coinbase. Once the validation queue is drained, the transaction should already carry the tip's TxStateConfirmed. The subsequent manual SetState updates both the transaction and its TXOs, masking a missing confirmation-state update before the coin assertions run. Remove that assignment and instead assert the existing block hash, height and index, together with matching states on its owned TXOs.
[suggestion] · Migration writes each retained transaction's metadata twice
The new WriteTxMetadata inside the is_mine block duplicates the existing rewrite at the end of every retained transaction's loop iteration.
Location: src/wallet/migration.cpp:249 (head).
Details and suggested fix
After assigning m_from_me and refreshing outputs, the is_mine branch writes the transaction. The watch-only branch does not modify the source transaction and only skips the final write when !is_mine, so every retained transaction is serialized and written again at the bottom of the loop. Remove the first write and its comment; the existing final write persists the updated classification.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: The upgrade fixture never checks from-me accounting (earlier report)
- [suggestion]: TXO move helpers return unused and inconsistently ordered iterators (earlier report)
- [suggestion]: RefreshAllTXOs carries an unused caller-batch branch (earlier report)
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The predecessor TXO index deliberately included already-spent outputs. Its optimization was to avoid repeatedly inspecting unrelated transaction outputs, not to discard wallet history.
This distinguishes the accounting lookup from the balance and coin-selection iteration set. Separating confirmed-spent outputs can preserve the original purpose, but their exclusion from routine iteration does not establish that their ownership and value information is expendable.
Ownership-dependent output metadata must be refreshed after imports, independently of rescanning. In #27286, the author explained that key birthdays can prevent a rescan from revisiting every stored transaction, and acknowledged that some key-management operations can change ownership of existing outputs.
A persisted m_from_me and its WalletTXO copies remain derived ownership data, not immutable transaction facts. The head's RefreshAllTXOs recomputation and import-time invocation address a guarantee that already existed: an ownership upgrade must affect stored transactions even when their blocks are outside the requested rescan range.
Input-based 'from me' classification is distinct from provenance saying that this wallet created a transaction. The earlier fFromMe discussion contrasted such a creation flag with inspecting inputs and outputs, which also recognizes raw-transaction API activity. Later, #29179 explicitly documented that IsFromMe requires knowledge of parent outputs and that non-topological mempool notifications after a reorg can cause wallet transactions to be missed.
The proposed m_from_me caches whether any input belongs to the wallet, not whether CreateTransaction authored the transaction. Computing that value depends on available ownership information. It is also only a prerequisite for trusting unconfirmed change: the base additionally requires mempool membership and recursively trusted, wallet-owned inputs.
Source 1 · Source 2 · Source 3
Transactions without insertion-order positions are a historical compatibility case. In #4697, maintainers opposed removing support for old wallets; the discussion then favored persisting the repaired order so that an upgraded wallet would subsequently behave like a new wallet.
Missing nOrderPos cannot itself be treated as invalid transaction history. The base repairs positions using receive time and existing positions, and writes transaction metadata during that repair. Moving this operation therefore interacts with any newly serialized derived field, including m_from_me.
Source 1 · Source 2 · Source 3
Migration must preserve a transaction in both resulting wallets when it belongs to both the migrated wallet and the watch-only wallet. The historical migration change explicitly retained such shared transactions rather than assigning every transaction exclusively to one wallet.
Transaction identity and copied metadata can be shared while ownership differs between the resulting wallets. Consequently, 'from me' is relative to each resulting wallet's descriptors and known inputs. The base already rebuilds ownership information and independently checks relevance to both wallets; the head adds persisted m_from_me to this process.
Block-conflicted state is reversible and propagates through descendants. The historical wallet-conflicts test requires a child to inherit its parent's conflict state, both to return to inactive after the conflicting chain is reorged away, and the formerly conflicted transaction to remain capable of subsequent confirmation.
Outputs of conflicted transactions are unusable under the current chain, not permanently disposable. Moving them out of the primary iteration set must retain enough information to recover when conflicts disappear. The base already performs recursive conflict reversal on block disconnection; the head extends that transition to output state and container membership.
Ralph's inferences
The accounting guarantee is broader than spendability: owned prevouts must remain discoverable even after confirmation of their spender or conflict of their creator.
In both pinned versions, GetDebit obtains input values through GetTXO; IsFromMe also uses that lookup to recognize owned inputs. Thus the two head containers collectively serve historical accounting and ownership classification, while only the primary container serves routine balance and coin-selection iteration. Retaining lookup access through m_unusable_txos preserves this distinction.
Persisting m_from_me introduces two separate compatibility obligations: absence in an old record must remain distinguishable from a computed false value, and computation must use sufficient parent-output knowledge. Repaired display/insertion order is not itself a guarantee of dependency order.
The base accepts records without the appended field and builds owned-output entries without needing from-me classification. The head distinguishes absence with an optional value, defers those outputs, and upgrades through wtxOrdered before reordering. ReorderTransactions sorts by receive time and preserves or offsets existing positions; it is not a topological sort. The historical guarantees therefore constrain both the information available during the upgrade and the metadata written by reordering, rather than independently mandating this particular sequence.
Reverse block traversal expresses dependency-aware undo, but restoring an output to the primary set is not equivalent to declaring it unspent or trusted.
For an in-block parent and child, reverse traversal handles the spender before the transaction that created its input. The head also reverses conflicts recursively. However, MaybeMarkTXOUsable checks IsSpent, whose default policy still counts non-abandoned, non-conflicted unconfirmed spenders. Recovery must therefore preserve live-spender exclusions and synchronized transaction/output state, rather than blindly restoring every input touched by a disconnected transaction. Trust remains a separate mempool-and-ancestry decision.