wallet: fix mixed-input transaction accounting in history RPCs #34872

Open
w0xlt wants to merge 16 commits from wallet-mixed-input-history-only into master AGit
w0xlt commented 2026-03-19 22:47:16 +00:00 (Migrated from github.com)

When a wallet owns only some inputs of a transaction, such as in CoinJoins, payjoins, or other collaborative transactions, wallet history RPCs currently apply normal send accounting.

That works when all inputs are wallet-owned, but breaks for mixed-input transactions.

Example:

Inputs:

1.00 BTC wallet-owned
2.00 BTC foreign

Outputs:

0.80 BTC wallet-owned
2.19 BTC non-wallet

The wallet can safely know:

wallet_debit  = 1.00
wallet_credit = 0.80
wallet_net    = -0.20

But it cannot reliably know, from wallet history alone, the foreign input value, the total fee, the wallet's fee share, or which non-wallet output should be attributed as the user's payment. This is especially important after restore, rescan, or descriptor import, where any local transaction-intent metadata may be missing.

This PR adds a conservative fallback for that no-metadata case:

  • classify wallet transactions as having no wallet inputs, partial wallet inputs, or all wallet inputs
  • keep existing send/fee accounting when all inputs are wallet-owned
  • also keep normal per-output send/fee accounting for mixed-input transactions when every non-wallet input has a known zero value
  • otherwise report a single unattributed aggregate send entry with no address, no vout, and no fee, carrying the negative total of wallet-owned inputs spent
  • report wallet-owned outputs as receive entries, so the transaction's entries sum to the wallet's net change
  • expose involves_mixed_inputs, wallet_debit, and wallet_credit
  • document that vout and fee are optional when attribution is unavailable

This does not try to fully solve collaborative transaction attribution. A richer layer with foreign-output / fee-share / intent metadata would still be useful for wallet-created transactions. This PR only makes the fallback honest when that metadata is unavailable.

Addresses #14136

When a wallet owns only some inputs of a transaction, such as in CoinJoins, payjoins, or other collaborative transactions, wallet history RPCs currently apply normal send accounting. That works when all inputs are wallet-owned, but breaks for mixed-input transactions. Example: Inputs: ``` 1.00 BTC wallet-owned 2.00 BTC foreign ``` Outputs: ``` 0.80 BTC wallet-owned 2.19 BTC non-wallet ``` The wallet can safely know: ``` wallet_debit = 1.00 wallet_credit = 0.80 wallet_net = -0.20 ``` But it cannot reliably know, from wallet history alone, the foreign input value, the total fee, the wallet's fee share, or which non-wallet output should be attributed as the user's payment. This is especially important after restore, rescan, or descriptor import, where any local transaction-intent metadata may be missing. This PR adds a conservative fallback for that no-metadata case: - classify wallet transactions as having no wallet inputs, partial wallet inputs, or all wallet inputs - keep existing send/fee accounting when all inputs are wallet-owned - also keep normal per-output send/fee accounting for mixed-input transactions when every non-wallet input has a known zero value - otherwise report a single unattributed aggregate `send` entry with no address, no `vout`, and no fee, carrying the negative total of wallet-owned inputs spent - report wallet-owned outputs as `receive` entries, so the transaction's entries sum to the wallet's net change - expose `involves_mixed_inputs`, `wallet_debit`, and `wallet_credit` - document that `vout` and `fee` are optional when attribution is unavailable This does not try to fully solve collaborative transaction attribution. A richer layer with foreign-output / fee-share / intent metadata would still be useful for wallet-created transactions. This PR only makes the fallback honest when that metadata is unavailable. Addresses #14136
DrahtBot commented 2026-03-19 22:47:38 +00:00 (Migrated from github.com)

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.

Type Reviewers
Concept NACK achow101
Concept ACK rkrux, arejula27
Stale ACK Bicaru20

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:

  • #37018 (descriptor: fix InferScript creates invalid descriptors for invalid pubkeys by Eunovo)
  • #36819 ([RFC] enable clang-tidy optin.performance.Padding by fanquake)
  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)
  • #35786 (wallet: drop spent parents redundant cache invalidation and notification by furszy)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #27865 (wallet: Track no-longer-spendable TXOs separately 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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/34872 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/34872.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/34872#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept NACK | [achow101](https://github.com/bitcoin/bitcoin/pull/34872#issuecomment-4491965088) | | Concept ACK | [rkrux](https://github.com/bitcoin/bitcoin/pull/34872#issuecomment-4509144362), [arejula27](https://github.com/bitcoin/bitcoin/pull/34872#pullrequestreview-5327697507) | | Stale ACK | [Bicaru20](https://github.com/bitcoin/bitcoin/pull/34872#pullrequestreview-5353349228) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37018](https://github.com/bitcoin/bitcoin/pull/37018) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37018.svg"></sub> (descriptor: fix `InferScript` creates invalid descriptors for invalid pubkeys by Eunovo) * [#36819](https://github.com/bitcoin/bitcoin/pull/36819) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36819.svg"></sub> ([RFC] enable `clang-tidy` `optin.performance.Padding` by fanquake) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equal -> assert_true/assert_false by hodlinator) * [#35786](https://github.com/bitcoin/bitcoin/pull/35786) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35786.svg"></sub> (wallet: drop spent parents redundant cache invalidation and notification by furszy) * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) * [#27865](https://github.com/bitcoin/bitcoin/pull/27865) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
luke-jr commented 2026-03-20 14:56:51 +00:00 (Migrated from github.com)

This won't show even the true send anymore... not sure that's a good idea.

See #25991 for what is needed to fix this properly.

This won't show even the true send anymore... not sure that's a good idea. See #25991 for what is needed to fix this properly.
w0xlt commented 2026-03-22 05:40:35 +00:00 (Migrated from github.com)

The goal here, in this PR, is a smaller immediate fix: for mixed-input transactions, the history RPCs should stop reporting send entries and full fees when the wallet cannot attribute them objectively.

#25991 is an interesting direction, but as written it depends on manually providing additional wallet-local per-output metadata.
Without that metadata, we still need a safe fallback, and that is what this PR provides.

The goal here, in this PR, is a smaller immediate fix: for mixed-input transactions, the history RPCs should stop reporting send entries and full fees when the wallet cannot attribute them objectively. #25991 is an interesting direction, but as written it depends on manually providing additional wallet-local per-output metadata. Without that metadata, we still need a safe fallback, and that is what this PR provides.
rkrux (Migrated from github.com) reviewed 2026-03-23 12:24:37 +00:00
rkrux (Migrated from github.com) left a comment

As I read the related issue #14136, it's unfortunate that the RPC shows incorrect information in the result - glad that this PR tries to address it.

However, I'm leaning towards a NACK because this PR removes the send category details of such transactions altogether, which is not correct. The wallet does participate (though partially) in sending funds within these transactions and not showing those can be problematic as well.

From https://github.com/bitcoin/bitcoin/pull/34872#issue-4104631274

Fixes this by introducing CachedTxIsFromMeForAccounting,

I am also not in favour of having two different views of CachedTxIsFromMe - one without accounting and one with. Having two views is also a sign that there is mismatch between what the wallet shows to the user and what the wallet does for the user.

From https://github.com/bitcoin/bitcoin/pull/34872#issuecomment-4105597428:

Without that metadata, we still need a safe fallback, and that is what this PR provides.

Due to the above reasons, I don't believe this is a safe fallback, and it only replaces one issue by another.

From https://github.com/bitcoin/bitcoin/pull/34872#issue-4104631274

This is because the accounting code treats any nDebit > 0 (i.e. any wallet-owned input) as a full wallet spend.

It appears that this assumption made by the wallet doesn't hold true anymore and maybe it needs to be reworked for this issue to be completely fixed.

As I read the related issue #14136, it's unfortunate that the RPC shows incorrect information in the result - glad that this PR tries to address it. However, I'm leaning towards a NACK because this PR removes the `send` category details of such transactions altogether, which is not correct. The wallet does participate (though partially) in sending funds within these transactions and not showing those can be problematic as well. From https://github.com/bitcoin/bitcoin/pull/34872#issue-4104631274 > Fixes this by introducing CachedTxIsFromMeForAccounting, I am also not in favour of having two different views of CachedTxIsFromMe - one without accounting and one with. Having two views is also a sign that there is mismatch between what the wallet shows to the user and what the wallet does for the user. From https://github.com/bitcoin/bitcoin/pull/34872#issuecomment-4105597428: > Without that metadata, we still need a safe fallback, and that is what this PR provides. Due to the above reasons, I don't believe this is a safe fallback, and it only replaces one issue by another. From https://github.com/bitcoin/bitcoin/pull/34872#issue-4104631274 > This is because the accounting code treats any nDebit > 0 (i.e. any wallet-owned input) as a full wallet spend. It appears that this assumption made by the wallet doesn't hold true anymore and maybe it needs to be reworked for this issue to be completely fixed.
w0xlt commented 2026-03-23 20:15:23 +00:00 (Migrated from github.com)

@rkrux Thanks for the review. I agree this isn’t a complete solution for mixed-input accounting.

The goal here is narrower: to prevent history RPCs from reporting send entries and full fees that the wallet cannot objectively attribute from the transaction alone.

So I see this as an improvement over the current behavior.

A complete solution likely requires additional attribution metadata. However, that’s tricky - even if we add something like #25991, or a more automated way to set it, the metadata would not survive an importdescriptors restore, since there’s currently no way to import it.

In those cases, we would still need a conservative fallback for history RPCs when attribution is unavailable.

Do you see another way to address this without relying on additional metadata?

@rkrux Thanks for the review. I agree this isn’t a complete solution for mixed-input accounting. The goal here is narrower: to prevent history RPCs from reporting send entries and full fees that the wallet cannot objectively attribute from the transaction alone. So I see this as an improvement over the current behavior. A complete solution likely requires additional attribution metadata. However, that’s tricky - even if we add something like #25991, or a more automated way to set it, the metadata would not survive an `importdescriptors` restore, since there’s currently no way to import it. In those cases, we would still need a conservative fallback for history RPCs when attribution is unavailable. Do you see another way to address this without relying on additional metadata?
achow101 commented 2026-05-19 20:55:14 +00:00 (Migrated from github.com)

NACK

I think it's even more misleading to not show any send entries at all for transactions where we participate in the inputs.

NACK I think it's even more misleading to not show any send entries at all for transactions where we participate in the inputs.
murchandamus commented 2026-05-19 21:56:54 +00:00 (Migrated from github.com)

At first glance, I would expect our wallet to be able to recognize which inputs are ours, and I’m astonished that it would just assume that all of the inputs must be ours when it recognizes one. Would it perhaps be possible to recognize such transactions as “multi user transactions” and only apply the inputs that came from our wallet as debits? If our wallet’s balance is decreased by the transaction, we might recognize any outputs from the transaction to our wallet as change output, whereas if the wallet’s balance is increased by the transaction (e.g., a Payjoin that paid us), we would treat the output as an incoming payment. The transaction should then be labeled as having us paid the amount that our wallet balance increased.

At first glance, I would expect our wallet to be able to recognize which inputs are ours, and I’m astonished that it would just assume that all of the inputs must be ours when it recognizes one. Would it perhaps be possible to recognize such transactions as “multi user transactions” and only apply the inputs that came from our wallet as debits? If our wallet’s balance is decreased by the transaction, we might recognize any outputs from the transaction to our wallet as change output, whereas if the wallet’s balance is increased by the transaction (e.g., a Payjoin that paid us), we would treat the output as an incoming payment. The transaction should then be labeled as having us paid the amount that our wallet balance increased.
achow101 commented 2026-05-19 22:23:28 +00:00 (Migrated from github.com)

it would just assume that all of the inputs must be ours when it recognizes one

That's not really what it is doing. It is correctly treating transactions that have any inputs belonging to the wallet as that transaction belonging to the wallet. The "assumption" comes from CachedTxGetDebit only retrieving the total amount of our inputs, which only works when all of the inputs of the transaction belong to the wallet.

But without storing more information, there is nothing that we can do to fix that. It shouldn't be astonishing that we are unable to calculate fees when the wallet does not know how much value the inputs that it doesn't know about are providing to the transaction.

The transaction should then be labeled as having us paid the amount that our wallet balance increased.

This isn't about annotating Bitcoin transactions, it's about annotating logical financial transactions and trying to determine what they are from a single Bitcoin transaction. Because a Bitcoin transaction can have multiple outputs, it can have multiple logical transactions, and the wallet tries to display these as such. For example, a multi party transaction could conceivably contain an output created by someone else in that transaction which pays us, while the same transaction simultaneously has an output that we create paying someone else. These should show as two entries in listtransactions - one showing a receive and one showing the send. The issue is with annotating the rest of the outputs (we don't store the logical transactions, so how do we know that the remaining outputs are not sends initiated by the user), and showing the correct amount for the fee (we don't know about the inputs that aren't ours, thus we cannot accurately calculate the fees).

The solution presented in this PR is to omit all of that logical transaction information entirely for multi party transactions, which I disagree with.

> it would just assume that all of the inputs must be ours when it recognizes one That's not really what it is doing. It is correctly treating transactions that have any inputs belonging to the wallet as that transaction belonging to the wallet. The "assumption" comes from `CachedTxGetDebit` only retrieving the total amount of our inputs, which only works when all of the inputs of the transaction belong to the wallet. But without storing more information, there is nothing that we can do to fix that. It shouldn't be astonishing that we are unable to calculate fees when the wallet does not know how much value the inputs that it doesn't know about are providing to the transaction. > The transaction should then be labeled as having us paid the amount that our wallet balance increased. This isn't about annotating Bitcoin transactions, it's about annotating logical financial transactions and trying to determine what they are from a single Bitcoin transaction. Because a Bitcoin transaction can have multiple outputs, it can have multiple logical transactions, and the wallet tries to display these as such. For example, a multi party transaction could conceivably contain an output created by someone else in that transaction which pays us, while the same transaction simultaneously has an output that we create paying someone else. These should show as two entries in `listtransactions` - one showing a receive and one showing the send. The issue is with annotating the rest of the outputs (we don't store the logical transactions, so how do we know that the remaining outputs are not sends initiated by the user), and showing the correct amount for the fee (we don't know about the inputs that aren't ours, thus we cannot accurately calculate the fees). The solution presented in this PR is to omit all of that logical transaction information entirely for multi party transactions, which I disagree with.
w0xlt commented 2026-05-20 13:41:34 +00:00 (Migrated from github.com)

@achow101 @murchandamus Thanks for the feedback.

I pushed a new proposal that addresses it.

As I understand it, a complete solution has two layers:

  1. A conservative fallback for mixed-input transactions when the wallet has no extra attribution metadata.


2. A richer metadata layer, e.g. foreign-output / ownership / fee-share marks, for wallet-created collaborative transactions.

The idea here to solve the layer 1 only.
Layer 2 is still useful, but it cannot replace the fallback. If a wallet is restored from descriptors, rescanned, or imported without the original local metadata, the wallet still needs a reliable way to report history without inventing send outputs or fees.

@achow101 @murchandamus Thanks for the feedback. I pushed a new proposal that addresses it. As I understand it, a complete solution has two layers: 1. A conservative fallback for mixed-input transactions when the wallet has no extra attribution metadata. 
2. A richer metadata layer, e.g. foreign-output / ownership / fee-share marks, for wallet-created collaborative transactions. The idea here to solve the layer 1 only. Layer 2 is still useful, but it cannot replace the fallback. If a wallet is restored from descriptors, rescanned, or imported without the original local metadata, the wallet still needs a reliable way to report history without inventing send outputs or fees.
w0xlt commented 2026-05-20 13:47:34 +00:00 (Migrated from github.com)

The new proposal:



In master, wallet history accounting effectively does this when any input is ours:

wallet_debit = sum(wallet-owned inputs)
fee = wallet_debit - total_outputs
send entries = all non-change outputs

That works only when all inputs are wallet-owned.

Example:

Inputs:

    1.00 BTC mine
    2.00 BTC foreign

Outputs:

    0.80 BTC mine
    2.19 BTC foreign

Master can calculate wallet_debit = 1.00, but it does not know/store the foreign input value reliably in wallet history. So subtracting all outputs from only wallet-owned inputs gives wrong accounting:

fee = 1.00 - 2.99 = -1.99

It can also report foreign outputs as wallet send entries, even though the wallet cannot know from the transaction alone whether those outputs are wallet's payment, another participant’s change, or something else.

This new push changes the previous fallback model to:

wallet_debit  = sum(wallet-owned inputs)
wallet_credit = sum(wallet-owned outputs)
amount        = wallet_credit - wallet_debit

For the same example:

wallet_debit  = 1.00
wallet_credit = 0.80
amount        = -0.20
fee_known     = false
category      = mixed

So the wallet reports the part it can prove: “the wallet balance went down by 0.20 BTC.” It does not guess the fee share or recipient attribution.


The new proposal:

 In master, wallet history accounting effectively does this when any input is ours: ``` wallet_debit = sum(wallet-owned inputs) fee = wallet_debit - total_outputs send entries = all non-change outputs ``` That works only when all inputs are wallet-owned. Example: Inputs: ``` 1.00 BTC mine 2.00 BTC foreign ``` Outputs: ``` 0.80 BTC mine 2.19 BTC foreign ``` Master can calculate `wallet_debit = 1.00`, but it does not know/store the foreign input value reliably in wallet history. So subtracting all outputs from only wallet-owned inputs gives wrong accounting: `fee = 1.00 - 2.99 = -1.99` It can also report foreign outputs as wallet send entries, even though the wallet cannot know from the transaction alone whether those outputs are wallet's payment, another participant’s change, or something else. This new push changes the previous fallback model to: ``` wallet_debit = sum(wallet-owned inputs) wallet_credit = sum(wallet-owned outputs) amount = wallet_credit - wallet_debit ``` For the same example: ``` wallet_debit = 1.00 wallet_credit = 0.80 amount = -0.20 fee_known = false category = mixed ``` So the wallet reports the part it can prove: “the wallet balance went down by 0.20 BTC.” It does not guess the fee share or recipient attribution.

w0xlt commented 2026-05-20 13:49:28 +00:00 (Migrated from github.com)

Moving this to draft for further discussion.

Moving this to draft for further discussion.
w0xlt commented 2026-05-20 14:02:12 +00:00 (Migrated from github.com)

PR description updated.

PR description updated.
rkrux commented 2026-05-20 14:50:28 +00:00 (Migrated from github.com)

Do you see another way to address this without relying on additional metadata?

Sorry, I had forgotten about this PR. I would prefer a basic conservative solution first without relying on additional metadata by letting the wallet return correct information (as much as it can) while not showing incorrect responses based on any missing transaction data.

Based on a cursory glance, the new proposal seems to be in this^ direction, will review.

> Do you see another way to address this without relying on additional metadata? Sorry, I had forgotten about this PR. I would prefer a basic conservative solution first without relying on additional metadata by letting the wallet return correct information (as much as it can) while not showing incorrect responses based on any missing transaction data. Based on a cursory glance, the new proposal seems to be in this^ direction, will review.
w0xlt commented 2026-05-20 17:13:30 +00:00 (Migrated from github.com)

CI error unrelated

CI error unrelated
rkrux commented 2026-05-21 14:16:30 +00:00 (Migrated from github.com)

Concept ACK 29fcb54dac4a8f4b45573ba20b97874eec81be9d

The new approach lgtm, will review when taken out of draft.

Concept ACK 29fcb54dac4a8f4b45573ba20b97874eec81be9d The new approach lgtm, will review when taken out of draft.
w0xlt commented 2026-05-21 17:07:05 +00:00 (Migrated from github.com)

Done.

Done.
w0xlt commented 2026-06-19 00:27:53 +00:00 (Migrated from github.com)

PR description updated.

PR description updated.
w0xlt commented 2026-07-07 20:07:29 +00:00 (Migrated from github.com)

Split the PR into more commits based on offline feedback

Split the PR into more commits based on offline feedback
maflcko (Migrated from github.com) reviewed 2026-07-08 05:38:22 +00:00
maflcko (Migrated from github.com) commented 2026-07-08 05:38:22 +00:00

What is this sync needed for on block events? Also, the called_by_framework in the prior line doesn't make sense?

What is this sync needed for on block events? Also, the `called_by_framework` in the prior line doesn't make sense?
w0xlt (Migrated from github.com) reviewed 2026-07-08 08:33:44 +00:00
w0xlt (Migrated from github.com) commented 2026-07-08 08:33:44 +00:00

Fixed. Thanks.

Fixed. Thanks.
murchandamus (Migrated from github.com) reviewed 2026-07-15 22:19:51 +00:00
murchandamus (Migrated from github.com) left a comment

Thanks for working on this. This sounds like a great improvement regarding multi-user transaction accounting. I have a few questions and I especially found the use of "attributable" somewhat confusing at times.

Thanks for working on this. This sounds like a great improvement regarding multi-user transaction accounting. I have a few questions and I especially found the use of "attributable" somewhat confusing at times.
murchandamus (Migrated from github.com) commented 2026-06-30 20:13:27 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):
I’m not sure how safety is an issue here. How about "reported correctly", "with improved attribution", "in more detail", or similar?

  broken down in more detail by the `gettransaction`, `listtransactions`, and
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): I’m not sure how safety is an issue here. How about "reported correctly", "with improved attribution", "in more detail", or similar? ```suggestion broken down in more detail by the `gettransaction`, `listtransactions`, and ```
murchandamus (Migrated from github.com) commented 2026-07-15 22:01:42 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

  and considered all non-wallet outputs to be wallet sends (see issue #14136).
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): ```suggestion and considered all non-wallet outputs to be wallet sends (see issue #14136). ```
murchandamus (Migrated from github.com) commented 2026-07-15 22:06:31 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

The "known zero value" keeps throwing me for a loop. Transactions can only spend TXOs that are in our UTXO set when we first see them. Therefore, we should always know every spent TXO’s value when we first validate a transaction. Shouldn’t it therefore also be available when we store a transaction in the wallet? If not, the wallet should learn it at the time a block is processed, and the value should be in the revert data?

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): The "**known** zero value" keeps throwing me for a loop. Transactions can only spend TXOs that are in our UTXO set when we first see them. Therefore, we should always know every spent TXO’s value when we first validate a transaction. Shouldn’t it therefore also be available when we store a transaction in the wallet? If not, the wallet should learn it at the time a block is processed, and the value should be in the revert data?
murchandamus (Migrated from github.com) commented 2026-07-15 22:08:51 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

I think my issue with "attribute" might be that the verb always needs a target for the attribution that I was missing. Maybe it makes sense when we describe it as the wallet being able to attribute it to itself?

  pay-to-anchor output), the wallet can still attribute the full fee and all
  sent outputs to itself, so these transactions continue to be reported with the usual
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): I think my issue with "attribute" might be that the verb always needs a target for the attribution that I was missing. Maybe it makes sense when we describe it as the wallet being able to attribute it **to itself**? ```suggestion pay-to-anchor output), the wallet can still attribute the full fee and all sent outputs to itself, so these transactions continue to be reported with the usual ```
murchandamus (Migrated from github.com) commented 2026-07-15 22:09:47 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

  per-output `send`/`receive` entries. Otherwise the wallet cannot compute its share of the
  foreign outputs and the fee, so it reports a single unattributed
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): ```suggestion per-output `send`/`receive` entries. Otherwise the wallet cannot compute its share of the foreign outputs and the fee, so it reports a single unattributed ```
murchandamus (Migrated from github.com) commented 2026-07-15 22:10:52 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

Maybe:

  foreign outputs or its fee share, so it reports the negative total of the wallet-owned inputs
  as the `send` amount
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): Maybe: ```suggestion foreign outputs or its fee share, so it reports the negative total of the wallet-owned inputs as the `send` amount ```
murchandamus (Migrated from github.com) commented 2026-07-15 22:16:46 +00:00

In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d):

The fee can always be determined per Σ(inputs)−Σ(outputs), rather we cannot determine our share of the fee.

  output. The `fee` field is likewise omitted when the wallet cannot determine its share of
  the fee. (#34872)
In "doc: add mixed-input history RPC release note" (eba63bfe77c148a447f44ba0703cb211c7a3213d): The fee can always be determined per `Σ(inputs)−Σ(outputs)`, rather we cannot determine our share of the fee. ```suggestion output. The `fee` field is likewise omitted when the wallet cannot determine its share of the fee. (#34872) ```
murchandamus (Migrated from github.com) commented 2026-06-23 21:15:25 +00:00

How would this resolve if there were a P2A input?

How would this resolve if there were a P2A input?
Lines 209-214
murchandamus (Migrated from github.com) commented 2026-07-15 21:56:25 +00:00

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9):
This explanation is excellent. "not computable" might be a better expression for the above cases where I found "attributable" to be insufficiently clear.

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9): This explanation is excellent. "not computable" might be a better expression for the above cases where I found "attributable" to be insufficiently clear.
murchandamus (Migrated from github.com) commented 2026-07-15 21:57:21 +00:00

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9):
Do you mean "every spent input with nonzero value"? Or perhaps "the total input value was contributed by our wallet"?

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9): Do you mean "every spent input **with nonzero** value"? Or perhaps "the total input value was contributed by our wallet"?
murchandamus (Migrated from github.com) commented 2026-07-15 21:18:34 +00:00

In "wallet,rpc: rename transaction entry helper" (40d2e72f16c099a15688fa0cc26b7f0bf258636c):
I’m not sure I understand the motivation for this rename. This RPC would print transactions to the terminal based on the given criteria, right? What is it appending to?

Could you please add a short explanation to the commit message why this RPC was renamed?

In "wallet,rpc: rename transaction entry helper" (40d2e72f16c099a15688fa0cc26b7f0bf258636c): I’m not sure I understand the motivation for this rename. This RPC would print transactions to the terminal based on the given criteria, right? What is it appending to? Could you please add a short explanation to the commit message why this RPC was renamed?
murchandamus (Migrated from github.com) commented 2026-07-15 21:21:32 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):
What do you mean with "unattributable outputs"? Do you perhaps mean that no outputs go to our wallet, i.e., that credit is zero?

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): What do you mean with "unattributable outputs"? Do you perhaps mean that no outputs go to our wallet, i.e., that `credit` is zero?
murchandamus (Migrated from github.com) commented 2026-07-15 21:25:53 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):
Even if there are mixed inputs, either the debit or credit could have a greater magnitude. Could you perhaps add an explanation in the commit message why a transaction that overall reduces the balance in the wallet would not be categorized as a send, and a transaction that overall increases the balance in the wallet as a receive?
I assume it is because it would be hard to distinguish e.g., a Payjoin in which we get paid and the sender gets a change output from a Payjoin transaction in which we get paid by a sender and also pay another receiver, but it would be good to document the rationale somewhere.

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): Even if there are mixed inputs, either the `debit` or `credit` could have a greater magnitude. Could you perhaps add an explanation in the commit message why a transaction that overall reduces the balance in the wallet would not be categorized as a _send_, and a transaction that overall increases the balance in the wallet as a _receive_? I assume it is because it would be hard to distinguish e.g., a Payjoin in which we get paid and the sender gets a change output from a Payjoin transaction in which we get paid by a sender and also pay another receiver, but it would be good to document the rationale somewhere.
murchandamus (Migrated from github.com) commented 2026-07-15 21:27:03 +00:00

I still think that there might be a special case here, in which there are mixed inputs, but all outputs go to our wallet, in which we might want to categorize it as a receive?

I still think that there might be a special case here, in which there are mixed inputs, but all outputs go to our wallet, in which we might want to categorize it as a _receive_?
murchandamus (Migrated from github.com) commented 2026-07-15 21:33:21 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):
I find this description confusing. What is "unattributed" about the "aggregate send entry"?

Perhaps: "

-                so it reports a single unattributed aggregate send entry (marked with involves_mixed_inputs and \n"
-                "without address, vout, or fee) carrying the negative total of wallet-owned inputs spent. Wallet-owned outputs \n"
+                so it reports the sum of the wallet-owned inputs as a single aggregate send entry (marked with involves_mixed_inputs and \n"
+                "without address, vout, or fee). Wallet-owned outputs \n"
In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): I find this description confusing. What is "unattributed" about the "aggregate send entry"? Perhaps: " ```diff - so it reports a single unattributed aggregate send entry (marked with involves_mixed_inputs and \n" - "without address, vout, or fee) carrying the negative total of wallet-owned inputs spent. Wallet-owned outputs \n" + so it reports the sum of the wallet-owned inputs as a single aggregate send entry (marked with involves_mixed_inputs and \n" + "without address, vout, or fee). Wallet-owned outputs \n" ```
murchandamus (Migrated from github.com) commented 2026-07-15 21:49:39 +00:00

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9):

The "known" seems obsolete, as we always know the value of spent TXOs.

-"all non-wallet inputs have known zero value. Otherwise the wallet cannot attribute the foreign outputs or its \n"
+"all non-wallet inputs have zero value. Otherwise the wallet cannot attribute the foreign outputs or its \n"
In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9): The "known" seems obsolete, as we always know the value of spent TXOs. ```diff -"all non-wallet inputs have known zero value. Otherwise the wallet cannot attribute the foreign outputs or its \n" +"all non-wallet inputs have zero value. Otherwise the wallet cannot attribute the foreign outputs or its \n"
murchandamus (Migrated from github.com) commented 2026-07-15 21:35:52 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):

The "cannot be attributed" here also confuses me. FWIU at this point in the review, when no outputs go to ourselves, or all outputs go ourselves, we consider it "attributable", but if there are both foreign-owned inputs and foreign-owned outputs, we call it "not attributable". If that’s the correct understanding, perhaps we can find a more speaking description of that?

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): The "cannot be attributed" here also confuses me. FWIU at this point in the review, when no outputs go to ourselves, or all outputs go ourselves, we consider it "attributable", but if there are both foreign-owned inputs and foreign-owned outputs, we call it "not attributable". If that’s the correct understanding, perhaps we can find a more speaking description of that?
murchandamus (Migrated from github.com) commented 2026-07-15 21:38:00 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):
Also here: "cannot attribute" needs more context.

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): Also here: "cannot attribute" needs more context.
murchandamus (Migrated from github.com) commented 2026-07-15 21:49:55 +00:00

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9):

"known" seems to be extraneous as above.

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9): "known" seems to be extraneous as above.
murchandamus (Migrated from github.com) commented 2026-07-15 21:54:39 +00:00

In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9):
If someone only saw this RPC description, "only available when known" would be confusing. How about something along the lines of:

-{RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the wallet-attributable fee in " + CURRENCY_UNIT + ". This is negative and only available when known."},
+{RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the wallet-attributable fee in " + CURRENCY_UNIT + ". The fee is negative and will only be reported for the 'send' category. The fee cannot be calculated for transactions with multiple senders."},
In "wallet,rpc: attribute zero-value foreign mixed inputs" (056ccd7bab93110d65b5c028f1502238c3a587b9): If someone only saw this RPC description, "only available when known" would be confusing. How about something along the lines of: ```diff -{RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the wallet-attributable fee in " + CURRENCY_UNIT + ". This is negative and only available when known."}, +{RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the wallet-attributable fee in " + CURRENCY_UNIT + ". The fee is negative and will only be reported for the 'send' category. The fee cannot be calculated for transactions with multiple senders."}, ```
murchandamus (Migrated from github.com) commented 2026-07-15 21:40:24 +00:00

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed):
I’m confused by this line. If all of credit, debit, and fee are stored as positive numbers, then surely it should be credit - debit - fee. If fee and debit are stored as negative numbers, it should be credit + debit + fee. If fee is stored as a negative number and debit is stored as a positive number, what are we even doing here? 😅

In "wallet,rpc: report unattributable mixed-input history conservatively" (0d3f1141ef76ef3cbd527f5f1a96518a252f2aed): I’m confused by this line. If all of `credit`, `debit`, and `fee` are stored as positive numbers, then surely it should be `credit - debit - fee`. If `fee` and `debit` are stored as negative numbers, it should be `credit + debit + fee`. If `fee` is stored as a negative number and `debit` is stored as a positive number, what are we even doing here? 😅
murchandamus (Migrated from github.com) commented 2026-07-15 21:13:21 +00:00

In "wallet: cache transaction input ownership" (3d1134d11fbcbbe4e62a00be06f04648e1bf5e90):

I’d be curious how an anyone-can-spend output such as a P2A output is categorized by InputIsMine(…), and it might also be a good addition to this test.

In "wallet: cache transaction input ownership" (3d1134d11fbcbbe4e62a00be06f04648e1bf5e90): I’d be curious how an anyone-can-spend output such as a P2A output is categorized by `InputIsMine(…)`, and it might also be a good addition to this test.
DrahtBot commented 2026-08-04 22:57:37 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sedited commented 2026-09-09 09:49:39 +00:00 (Migrated from github.com)

@w0xlt can you rebase and respond to murch's review comments?

@w0xlt can you rebase and respond to murch's review comments?
w0xlt (Migrated from github.com) reviewed 2026-09-21 23:22:09 +00:00
w0xlt (Migrated from github.com) commented 2026-09-21 23:22:09 +00:00

This behavior predates the PR. InputIsMine() checks whether the spent output belongs to the wallet. Being anyone-can-spend does not automatically imply ownership:

  const CWalletTx* prev = wallet.GetWalletTx(txin.prevout.hash);
  if (prev && txin.prevout.n < prev->GetTx()->vout.size()) {
      return wallet.IsMine(prev->GetTx()->vout[txin.prevout.n]);
  }
  return false;

Added a P2A case with its parent stored in the wallet, checking InputIsMine() == false, NONE for P2A alone, and PARTIAL alongside a wallet-owned input.

This behavior predates the PR. `InputIsMine()` checks whether the spent output belongs to the wallet. Being anyone-can-spend does not automatically imply ownership: ```c++ const CWalletTx* prev = wallet.GetWalletTx(txin.prevout.hash); if (prev && txin.prevout.n < prev->GetTx()->vout.size()) { return wallet.IsMine(prev->GetTx()->vout[txin.prevout.n]); } return false; ``` Added a P2A case with its parent stored in the wallet, checking `InputIsMine() == false`, `NONE` for P2A alone, and `PARTIAL` alongside a wallet-owned input.
w0xlt (Migrated from github.com) reviewed 2026-09-22 01:12:35 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 01:12:35 +00:00

Added the rationale to the commit message.
This internal helper appends entries for one wallet transaction to the caller's result container.

Could you please add a short explanation to the commit message why this RPC was renamed?

The public RPC names remain unchanged.

Added the rationale to the commit message. This internal helper appends entries for one wallet transaction to the caller's result container. > Could you please add a short explanation to the commit message why this RPC was renamed? The public RPC names remain unchanged.
w0xlt (Migrated from github.com) reviewed 2026-09-22 01:19:25 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 01:19:25 +00:00

I meant that we cannot determine the wallet’s contribution to individual outputs or the fee.
This does not imply zero credit: wallet-owned outputs are still reported as receives.
Clarified the comment.

I meant that we cannot determine the wallet’s contribution to individual outputs or the fee. This does not imply zero credit: wallet-owned outputs are still reported as receives. Clarified the comment.
w0xlt (Migrated from github.com) reviewed 2026-09-22 02:56:36 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 02:56:36 +00:00

Added the rationale to the commit message: receives preserve each output’s details; the send records wallet inputs used. Added tests where all outputs belong to the wallet, before and after confirmation.

Added the rationale to the commit message: receives preserve each output’s details; the send records wallet inputs used. Added tests where all outputs belong to the wallet, before and after confirmation.
w0xlt (Migrated from github.com) reviewed 2026-09-22 03:35:22 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 03:35:22 +00:00

On master, the code uses opposite fee formulas:

  • CachedTxGetAmounts(): wallet input value − total output value.
  • gettransaction: total output value − wallet input value.

For transactions funded entirely by the wallet, these represent the same fee with opposite signs.

The new helper uses the first convention and tells all three history RPCs whether the wallet’s fee share is known.

Changing the sign is an implementation choice arising from that consolidation, rather than a requirement of mixed-input accounting itself.

Regarding the question above:

  • accounting.debit sums the full value of the wallet’s spent inputs.
  • accounting.credit sums the wallet-owned outputs, including change.

accounting.credit - accounting.debit already includes the fee. gettransaction adds the known fee back so amount excludes it, and reports fee separately as negative.

On master, the code uses opposite fee formulas: - `CachedTxGetAmounts()`: wallet input value − total output value. - `gettransaction`: total output value − wallet input value. For transactions funded entirely by the wallet, these represent the same fee with opposite signs. The new helper uses the first convention and tells all three history RPCs whether the wallet’s fee share is known. Changing the sign is an implementation choice arising from that consolidation, rather than a requirement of mixed-input accounting itself. Regarding the question above: - `accounting.debit` sums the full value of the wallet’s spent inputs. - `accounting.credit` sums the wallet-owned outputs, including change. `accounting.credit - accounting.debit` already includes the fee. `gettransaction` adds the known fee back so amount excludes it, and reports fee separately as negative.
w0xlt (Migrated from github.com) reviewed 2026-09-22 03:51:11 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 03:51:11 +00:00

Added a code comment explaining why the fee is added back.

Added a code comment explaining why the fee is added back.
w0xlt (Migrated from github.com) reviewed 2026-09-22 04:06:14 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 04:06:14 +00:00

Taken, thanks.

Taken, thanks.
w0xlt (Migrated from github.com) reviewed 2026-09-22 04:41:48 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 04:41:48 +00:00

Updated the help text. With mixed inputs, we report one send entry for all wallet inputs, regardless of who owns the outputs.

If every non-wallet input is known to have zero value, we use master’s existing per-output format: a separate send entry for each non-change output.

Updated the help text. With mixed inputs, we report one send entry for all wallet inputs, regardless of who owns the outputs. If every non-wallet input is known to have zero value, we use master’s existing per-output format: a separate send entry for each non-change output.
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:02:36 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 05:02:36 +00:00

Clarified in both RPC descriptions that the wallet cannot determine how much of each output or the fee was paid from its inputs.

Clarified in both RPC descriptions that the wallet cannot determine how much of each output or the fee was paid from its inputs.
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:12:47 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 05:12:47 +00:00

The wallet may not have the parent transaction needed to check a non-wallet input’s value. Clarified the wording.

The wallet may not have the parent transaction needed to check a non-wallet input’s value. Clarified the wording.
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:13:22 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 05:13:22 +00:00

Applied the same clarification as above here.

Applied the same clarification as above here.
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:26:41 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 05:26:41 +00:00

Clarified that the fee is reported when all inputs belong to the wallet, or when the transaction has mixed inputs and the wallet can verify that every non-wallet input has zero value. Otherwise, the fee field is omitted.

Clarified that the fee is reported when all inputs belong to the wallet, or when the transaction has mixed inputs and the wallet can verify that every non-wallet input has zero value. Otherwise, the fee field is omitted.
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:43:30 +00:00
Lines 209-214
w0xlt (Migrated from github.com) commented 2026-09-22 05:43:30 +00:00

Clarified the RPC descriptions and removed the remaining “unattributed” wording from the help text. Thanks!

Clarified the RPC descriptions and removed the remaining “unattributed” wording from the help text. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 05:51:54 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 05:51:54 +00:00

Updated the comment to say that the wallet contributes the total input value. Thanks!

Updated the comment to say that the wallet contributes the total input value. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:01:38 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:01:38 +00:00

Changed to “reported more accurately”. Thanks!

Changed to “reported more accurately”. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:07:57 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:07:57 +00:00

Applied your suggestion. Thanks!

Applied your suggestion. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:24:39 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:24:39 +00:00

Yes, it makes sense. The node knows these values during validation, and block undo data contains them. To verify that every non-wallet input has zero value, the wallet currently uses only parent transactions stored in the wallet. If a parent is missing, it cannot verify that input’s value. Learning and retaining those values could be a follow-up improvement.

Updated the release note to say “the wallet can verify”.

Yes, it makes sense. The node knows these values during validation, and block undo data contains them. To verify that every non-wallet input has zero value, the wallet currently uses only parent transactions stored in the wallet. If a parent is missing, it cannot verify that input’s value. Learning and retaining those values could be a follow-up improvement. Updated the release note to say “the wallet can verify”.
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:31:15 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:31:15 +00:00

Added “to itself”, as suggested. Thanks!

Added “to itself”, as suggested. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:39:03 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:39:03 +00:00

Applied your suggestion. Thanks!

Applied your suggestion. Thanks!
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:44:30 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:44:30 +00:00

Done. Thanks.

Done. Thanks.
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:50:52 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:50:52 +00:00

Done. Thanks.

Done. Thanks.
w0xlt (Migrated from github.com) reviewed 2026-09-22 06:59:00 +00:00
w0xlt (Migrated from github.com) commented 2026-09-22 06:59:00 +00:00

The P2A case is covered now. If the wallet can verify that all non-wallet inputs have zero value, we use master’s existing per-output format, including the fee.
There’s a test for this before and after confirmation.

The P2A case is covered now. If the wallet can verify that all non-wallet inputs have zero value, we use master’s existing per-output format, including the fee. There’s a test for this before and after confirmation.
w0xlt commented 2026-09-22 07:08:25 +00:00 (Migrated from github.com)

@sedited Rebased and all comments addressed.

@sedited Rebased and all comments addressed.
DrahtBot commented 2026-09-22 23:13:31 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
arejula27 (Migrated from github.com) reviewed 2026-09-26 22:17:13 +00:00
arejula27 (Migrated from github.com) left a comment

Concept ACK.

I agree it is better to omit information than to show information that is wrong.

I think the issue is that the history RPCs show two different things in the same list: the UTXO history and the balance history (how much the wallet balance changed, and whether we paid someone). This is hard because they are different paradigms: for simple transactions it works well, but for complex ones (like the ones this PR aims to fix) it breaks.

Using the net change as the amount was already discussed earlier in this thread. What I would suggest discussing is keeping it but splitting both views inside the entry: a single entry per mixed transaction whose amount is the net change (credit - debit), and a subfield with the wallet UTXOs the transaction spent and created, so no per output information is lost. Something like this (only to illustrate the idea, not a concrete proposal for the field names or layout):

{
  "category": "receive",
  "amount": 1.99,
  // "fee" omitted: we cannot know it
  "involves_mixed_inputs": true,
  "utxos": {
    "spent":   [{"txid": "...", "vout": 0, "amount": 1.00}],
    "created": [{"vout": 0, "address": "...", "amount": 1.50},
                {"vout": 1, "address": "...", "amount": 1.49}]
  }
}

For reference, I asked an LLM (Claude Opus) to look at how other wallets handle transactions with foreign inputs: BDK, Electrum, Electron Cash, BlueWallet, Sparrow, Wasabi, Dojo, CLN, LND and the Core GUI. All of them use the net change as the amount of the transaction, and those that cannot compute the fee (BDK, Electrum, Sparrow, Wasabi) leave it out, as this PR does.

I reviewed this PR as part of the Spanish PR Review Club and wanted to share my view. I know the output format has already been discussed at length, so if that is decided and the PR is now at the code review stage, feel free to ignore this suggestion.

Concept ACK. I agree it is better to omit information than to show information that is wrong. I think the issue is that the history RPCs show two different things in the same list: the UTXO history and the balance history (how much the wallet balance changed, and whether we paid someone). This is hard because they are different paradigms: for simple transactions it works well, but for complex ones (like the ones this PR aims to fix) it breaks. Using the net change as the amount was already discussed earlier in this thread. What I would suggest discussing is keeping it but splitting both views inside the entry: a single entry per mixed transaction whose `amount` is the net change (`credit - debit`), and a subfield with the wallet UTXOs the transaction spent and created, so no per output information is lost. Something like this (only to illustrate the idea, not a concrete proposal for the field names or layout): ```jsonc { "category": "receive", "amount": 1.99, // "fee" omitted: we cannot know it "involves_mixed_inputs": true, "utxos": { "spent": [{"txid": "...", "vout": 0, "amount": 1.00}], "created": [{"vout": 0, "address": "...", "amount": 1.50}, {"vout": 1, "address": "...", "amount": 1.49}] } } ``` For reference, I asked an LLM (Claude Opus) to look at how other wallets handle transactions with foreign inputs: BDK, Electrum, Electron Cash, BlueWallet, Sparrow, Wasabi, Dojo, CLN, LND and the Core GUI. All of them use the net change as the amount of the transaction, and those that cannot compute the fee (BDK, Electrum, Sparrow, Wasabi) leave it out, as this PR does. I reviewed this PR as part of the Spanish PR Review Club and wanted to share my view. I know the output format has already been discussed at length, so if that is decided and the PR is now at the code review stage, feel free to ignore this suggestion.
Bicaru20 (Migrated from github.com) reviewed 2026-09-29 14:35:04 +00:00
Bicaru20 (Migrated from github.com) left a comment

ACK 66763e7068

I think this is the rigth approach so history RPC never show information the wallet cannot actually know. This way the wallet will be more honest and less confusing when showing the histroy through RPCs and the user will be able to see when the wallet do not have enough information instead of seeing wrong data.

I tested the code in regtest and everything seems to work the way it is supposed to. I just left a comment about a possible small optimitation.

ACK 66763e7068e0264fef85c259b677e319c90f2201 I think this is the rigth approach so history RPC never show information the wallet cannot actually know. This way the wallet will be more honest and less confusing when showing the histroy through RPCs and the user will be able to see when the wallet do not have enough information instead of seeing wrong data. I tested the code in regtest and everything seems to work the way it is supposed to. I just left a comment about a possible small optimitation.
Bicaru20 (Migrated from github.com) commented 2026-09-29 13:34:51 +00:00

In a625026843 I think here we could avoid calling CachedTxGetHistoryAccounting since we already do that in CachedTxGetAmounts. For instance, we could modify CachedTxGetAmounts to return the accounting struct. Sth like this:

--- a/src/wallet/receive.cpp
+++ b/src/wallet/receive.cpp
@@ -214,7 +214,7 @@ WalletTxHistoryAccounting CachedTxGetHistoryAccounting(const CWallet& wallet, co
     return {input_ownership, debit, credit, fee};
 }
 
-void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
+WalletTxHistoryAccounting CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
                   std::list<COutputEntry>& listReceived,
                   std::list<COutputEntry>& listSent, CAmount& nFee,
                   bool include_change)
@@ -267,7 +267,7 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
         if (ismine)
             listReceived.push_back(output);
     }
-
+    return accounting;
 }
 
 bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx)
diff --git a/src/wallet/receive.h b/src/wallet/receive.h
index 2328235e4e..e2139327d5 100644
--- a/src/wallet/receive.h
+++ b/src/wallet/receive.h
@@ -46,7 +46,7 @@ struct WalletTxHistoryAccounting
 };
 WalletTxHistoryAccounting CachedTxGetHistoryAccounting(const CWallet& wallet, const CWalletTx& wtx)
     EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
-void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
+WalletTxHistoryAccounting CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
                         std::list<COutputEntry>& listReceived,
                         std::list<COutputEntry>& listSent,
                         CAmount& nFee,
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index 6f7e9270a2..08c98a3db6 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -356,10 +356,9 @@ static void AppendWalletTxEntries(const CWallet& wallet, const CWalletTx& wtx, i
     std::list<COutputEntry> listReceived;
     std::list<COutputEntry> listSent;
 
-    const WalletTxHistoryAccounting accounting{CachedTxGetHistoryAccounting(wallet, wtx)};
+    const WalletTxHistoryAccounting accounting{CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, include_change)};
     const bool is_mixed_input{IsMixedInput(accounting)};
     const bool needs_unattributed_aggregate_send{NeedsUnattributedAggregateSend(accounting)};
-    CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, include_change);

In a6250268436f7af45fd5bdab7384eb3ad75a3786 I think here we could avoid calling `CachedTxGetHistoryAccounting` since we already do that in `CachedTxGetAmounts`. For instance, we could modify `CachedTxGetAmounts` to return the `accounting` struct. Sth like this: ```diff --- a/src/wallet/receive.cpp +++ b/src/wallet/receive.cpp @@ -214,7 +214,7 @@ WalletTxHistoryAccounting CachedTxGetHistoryAccounting(const CWallet& wallet, co return {input_ownership, debit, credit, fee}; } -void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, +WalletTxHistoryAccounting CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, std::list<COutputEntry>& listReceived, std::list<COutputEntry>& listSent, CAmount& nFee, bool include_change) @@ -267,7 +267,7 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, if (ismine) listReceived.push_back(output); } - + return accounting; } bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx) diff --git a/src/wallet/receive.h b/src/wallet/receive.h index 2328235e4e..e2139327d5 100644 --- a/src/wallet/receive.h +++ b/src/wallet/receive.h @@ -46,7 +46,7 @@ struct WalletTxHistoryAccounting }; WalletTxHistoryAccounting CachedTxGetHistoryAccounting(const CWallet& wallet, const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); -void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, +WalletTxHistoryAccounting CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, std::list<COutputEntry>& listReceived, std::list<COutputEntry>& listSent, CAmount& nFee, diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 6f7e9270a2..08c98a3db6 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -356,10 +356,9 @@ static void AppendWalletTxEntries(const CWallet& wallet, const CWalletTx& wtx, i std::list<COutputEntry> listReceived; std::list<COutputEntry> listSent; - const WalletTxHistoryAccounting accounting{CachedTxGetHistoryAccounting(wallet, wtx)}; + const WalletTxHistoryAccounting accounting{CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, include_change)}; const bool is_mixed_input{IsMixedInput(accounting)}; const bool needs_unattributed_aggregate_send{NeedsUnattributedAggregateSend(accounting)}; - CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, include_change); ```
First-time contributor

🟠 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).

🔵 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).

🔵 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).

🔵 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).

Review coverage was incomplete.


Reviewed: e9b990c4ff21 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:7eebed8027c96ac27bcd79eeb7a88e35799cd96eb8fbacf34d3257986a959f64:cdc1bd61213c9363d5bb4c7b7ee073ccfd6fecdafbb2c4c18d9d9e031a6afcf8 --> <!-- ralph-base:c68583ab5a886b6add45a8607d762b71678c748c --> <!-- ralph-head:e9b990c4ff21aaddc3b37421fe0db1c36032cb27 --> <!-- ralph-case:242eb6671c45833f73c8c3bc52420abfc4c24efc00104f13a7b521d34f1c0d5c --> **🟠 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e9b990c4ff21aaddc3b37421fe0db1c36032cb27/src/wallet/rpc/transactions.cpp#L451>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e9b990c4ff21aaddc3b37421fe0db1c36032cb27/src/wallet/rpc/transactions.cpp#L363>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e9b990c4ff21aaddc3b37421fe0db1c36032cb27/src/wallet/receive.cpp#L242>) (head). **🔵 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e9b990c4ff21aaddc3b37421fe0db1c36032cb27/src/wallet/rpc/transactions.cpp#L562>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`e9b990c4ff21`](<https://git.fish.foo/bitcoin/bitcoin/commit/e9b990c4ff21aaddc3b37421fe0db1c36032cb27>) · [Review report](<https://review.fish.foo/report/34872-e9b990c4ff21aaddc3b37421fe0db1c36032cb27-2545-3.html>) · [Previous reports](<https://review.fish.foo/traces/34872/>) [permalink](<https://review.fish.foo/report/34872-e9b990c4ff21aaddc3b37421fe0db1c36032cb27-2545-3.html>)
w0xlt commented 2026-10-06 21:39:55 +00:00 (Migrated from github.com)

@arejula27 Thanks for the review and the suggestion! I like the idea of showing the net change alongside the wallet’s spent and created outputs.

This PR already has quite a bit of complexity, so I’d prefer to explore that format in a follow-up. That would give the interface and compatibility questions their own discussion while keeping this PR focused on fixing the incorrect accounting.

Would you be interested in opening a draft PR on top of this one? I’d concept ACK that direction and be happy to help review it.

@arejula27 Thanks for the review and the suggestion! I like the idea of showing the net change alongside the wallet’s spent and created outputs. This PR already has quite a bit of complexity, so I’d prefer to explore that format in a follow-up. That would give the interface and compatibility questions their own discussion while keeping this PR focused on fixing the incorrect accounting. Would you be interested in opening a draft PR on top of this one? I’d concept ACK that direction and be happy to help review it.
w0xlt (Migrated from github.com) reviewed 2026-10-06 21:44:19 +00:00
w0xlt (Migrated from github.com) commented 2026-10-06 21:44:19 +00:00

Thanks. Done. Added you as co-author.

Thanks. Done. Added you as co-author.
arejula27 commented 2026-10-06 22:03:17 +00:00 (Migrated from github.com)

Thanks! Yes, I'd be happy to open a draft PR on top of this one, i will try to do it this week :D

For another follow-up (or in that one but i think it fit betters on its own) I'd also like to propose moving the classification logic into the wallet so the GUI can share it. Today TransactionRecord::decomposeTransaction redoes the same split, so the two implementations can diverge. Exposing the result through interfaces::WalletTx would let the RPCs and the GUI use the same logic. What do you think?

Thanks! Yes, I'd be happy to open a draft PR on top of this one, i will try to do it this week :D For another follow-up (or in that one but i think it fit betters on its own) I'd also like to propose moving the classification logic into the wallet so the GUI can share it. Today `TransactionRecord::decomposeTransaction` redoes the same split, so the two implementations can diverge. Exposing the result through interfaces::WalletTx would let the RPCs and the GUI use the same logic. What do you think?
w0xlt commented 2026-10-07 00:52:44 +00:00 (Migrated from github.com)

Thanks! Looking forward to the draft.

I agree that sharing the classification with the GUI would be useful, and I’d support keeping that as its own follow-up.

There’s already a starting point in this PR: CachedTxGetHistoryAccounting computes input ownership, debit, credit, and an optional attributable fee in the wallet. Exposing those facts through interfaces::WalletTx could let the GUI use the same accounting rules as the RPCs, while leaving presentation decisions with each caller.

One useful test case would be a transaction where we spend 1 BTC and the only foreign input is known to be worth 0 BTC. That foreign input adds no money, so all the funds still come from our wallet. This PR recognizes that and can report the outputs and fee normally.

The GUI on master currently puts this transaction into its generic “Other” handling because one input isn’t ours. Sharing the wallet’s accounting result would let it recognize that all the funds still came from our wallet.

I’d concept ACK that direction too, and would be happy to help review both drafts.

Thanks! Looking forward to the draft. I agree that sharing the classification with the GUI would be useful, and I’d support keeping that as its own follow-up. There’s already a starting point in this PR: `CachedTxGetHistoryAccounting` computes input ownership, debit, credit, and an optional attributable fee in the wallet. Exposing those facts through `interfaces::WalletTx` could let the GUI use the same accounting rules as the RPCs, while leaving presentation decisions with each caller. One useful test case would be a transaction where we spend 1 BTC and the only foreign input is known to be worth 0 BTC. That foreign input adds no money, so all the funds still come from our wallet. This PR recognizes that and can report the outputs and fee normally. The GUI on master currently puts this transaction into its generic “Other” handling because one input isn’t ours. Sharing the wallet’s accounting result would let it recognize that all the funds still came from our wallet. I’d concept ACK that direction too, and would be happy to help review both drafts.
DrahtBot commented 2026-10-19 14:28:43 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
w0xlt commented 2026-11-11 22:18:44 +00:00 (Migrated from github.com)

Rebased

Rebased
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!34872
No description provided.