wallet: fix mixed-input transaction accounting in history RPCs

bitcoin/bitcoin: PR #34872

1 minor finding · 3 suggestions

Findings

Link

[minor] · listrawtransactions still promises fee-exclusive mixed-input amounts

For mixed inputs with an unknown wallet fee share, listrawtransactions now returns the wallet's net change without a fee, but its help and release note still promise a fee-exclusive amount.

Location: src/wallet/rpc/transactions.cpp:451 (head).

Details and suggested fix

ListRawTransaction also calls PushTxAmountAndFee, so the new fallback affects this RPC: amount becomes wallet_credit - wallet_debit, with no adjustment for the unknown fee share. Fully owned transactions and mixed inputs with known-zero foreign contributions still add back the attributable fee. Qualify the raw RPC's description, result help and release note accordingly, and include it among the affected RPCs in doc/release-notes-34872.md. Extend the mixed-input fixture with raw-history assertions for one entry per txid, the conservative net amount without fee, and the normal fee-exclusive amount for known-zero foreign inputs.


Optional improvements

Link

[suggestion] · Mixed-input history changes have no compatibility path

Although the old attribution was incorrect, removing vout and fee and changing send amounts can break existing RPC clients without the grace-period option recommended by the RPC guidelines.

Location: src/wallet/rpc/transactions.cpp:363 (head).

Details and suggested fix

An unattributable mixed-input send now represents the total wallet debit rather than an output, so clients reading entry["vout"] or indexing entries by (txid, vout, category) can fail. gettransaction also omits its previously returned top-level fee. Consider retaining the legacy response behind a -deprecatedrpc=<feature> option for one release, as described in doc/developer-notes.md:1409, while keeping the corrected accounting as the default. This would require preserving and testing the known-misleading attribution during the grace period. If this correction intentionally skips deprecation, make that exception explicit and provide client migration instructions alongside the existing release-note warning.


Link

[suggestion] · include_change help omits the aggregate mixed-input exception

Conservative mixed-input history now includes change as receive even with include_change=false, but the argument help does not explain this exception.

Location: src/wallet/receive.cpp:242 (head).

Details and suggested fix

CachedTxGetAmounts now checks include_change only when sent outputs are attributable. For conservative mixed-input transactions, it retains every wallet-owned output, including change. Thus listtransactions and default listsinceblock calls expose change as receive, whereas the base suppressed it for positive-debit mixed-input spends. This is deliberate and covered by the change-output fixture. Qualify the include_change help and release note to state that aggregate mixed-input history always includes wallet-owned outputs, including change, so consumers do not interpret the default as excluding these receives. Keep the total-debit aggregate semantics unchanged.


Link

[suggestion] · The sum-to-net guarantee overlooks block-conflicted transactions

The new sum-to-net guarantee overlooks the existing receive-depth filter: block-conflicted conservative mixed-input transactions retain the aggregate send but omit wallet credits from their entries.

Location: src/wallet/rpc/transactions.cpp:562 (head).

Details and suggested fix

A participant's confirmed double spend can mark the mixed-input transaction block-conflicted, including when it spends a foreign prevout tracked in mapTxSpends. AppendWalletTxEntries still emits the aggregate send, but its receive branch requires depth >= nMinDepth. That minimum is zero for listtransactions, gettransaction details and the listsinceblock transactions array. With wallet-owned outputs, these entries sum to -wallet_debit, while the top-level conservative gettransaction amount remains wallet_credit - wallet_debit. Qualify the help and release-note guarantee to exclude block-conflicted transactions. The listsinceblock removed array uses a negative minimum depth and does not have this same receive suppression.


Coverage details