Skip to content

wallet, rpc: add v3 transaction creation and wallet support - #32896

Merged
glozow merged 12 commits into
bitcoin:masterfrom
ishaanam:wallet_v3_txs
Aug 19, 2025
Merged

glozow merged 12 commits into
bitcoin:masterfrom
ishaanam:wallet_v3_txs

Conversation

@ishaanam

@ishaanam ishaanam commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

This PR Implements the following:

  • If creating a v3 transaction, AvailableCoins doesn't return unconfirmed v2 utxos (and vice versa)
  • AvailableCoins doesn't return an unconfirmed v3 utxo if its transaction already has a child
  • If a v3 transaction is kicked out of the mempool by a sibling, mark the sibling as a mempool conflict
  • Throw an error if pre-selected inputs are of the wrong transaction version
  • Allow setting version to 3 manually in createrawtransaction (uses commits from rpc: Support v3 raw transactions creation #31936)
  • Limits a v3 transaction weight in coin selection

Closes #31348

To-Do:

  • Test a v3 sibling conflict kicking out one of our transactions from the mempool
  • Implement separate size limit for TRUC children
  • Test that we can't fund a v2 transaction when everything is v3 unconfirmed
  • Test a v3 sibling conflict being removed from the mempool
  • Test limiting v3 transaction weight in coin selection
  • Simplify tests
  • Add documentation
  • Test that user-input max weight is not overwritten by truc max weight
  • Test v3 in RPCs other than createrawtransaction

@DrahtBot

DrahtBot commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32896.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK glozow, achow101, rkrux
Concept ACK murchandamus
Stale ACK w0xlt

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32983 (rpc: refactor: use string_view in Arg/MaybeArg by stickies-v)
  • #32857 (wallet: allow skipping script paths by Sjors)
  • #32523 (wallet: Remove isminetypes by achow101)
  • #28201 (Silent Payments: sending by josibake)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
  • #21283 (Implement BIP 370 PSBTv2 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.

@DrahtBot

DrahtBot commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/45505893140
LLM reason (✨ experimental): The CI failure is caused by a lint error due to a file permission issue with a Python script that has a shebang line but incorrect executable permissions.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@glozow glozow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, concept ACK! Saw that these tests fail on #31936, which is helpful for showing its issues. Ultimately, I think the wallet commits should be introduced before the RPC ones.

Comment thread test/functional/wallet_v3_txs.py Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved
Comment thread src/wallet/transaction.h Resolved
Comment thread src/wallet/spend.h Resolved
@ishaanam
ishaanam force-pushed the wallet_v3_txs branch 3 times, most recently from 0d3a767 to 7fdff3f Compare July 8, 2025 21:02
Comment thread src/rpc/rawtransaction_util.cpp Resolved
@ishaanam
ishaanam force-pushed the wallet_v3_txs branch 6 times, most recently from c6cb62e to 7ded135 Compare July 10, 2025 20:54
@ishaanam
ishaanam force-pushed the wallet_v3_txs branch 2 times, most recently from eee8695 to ca97f19 Compare July 14, 2025 14:05
@DrahtBot DrahtBot mentioned this pull request Jul 14, 2025
2 tasks
@ishaanam
ishaanam marked this pull request as ready for review July 14, 2025 14:45
@ishaanam

Copy link
Copy Markdown
Contributor Author

This PR is now ready for review.

@w0xlt w0xlt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5c087f5

@rkrux rkrux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ACK 5c087f58245cfba6b61691ece5387eccf8a1a5f9

Thanks for taking this over the finish line. To implement the TRUC conditions in the wallet, I've observed that the related changes are done in the following control sites of selecting coins while building the transaction via different corresponding RPCs:

  1. FetchSelectedInputs: to ensure the parent-child TRUC versions are in agreement.
  2. AvailableCoins: to ensure the parent-child TRUC versions are in agreement, to ensure the TRUC ancestor/descendant limits are adhered to.
  3. AutomaticCoinSelection: to ensure the TRUC transaction weight criterion are met.
  4. Notifications - transactionAddedToMempool, transactionRemovedFromMempool: to ensure transaction mempool conflicts are updated and unconfirmed TRUC child is tracked.

The several functional tests also give more confidence.

The couple nits below can be done if there is any other need to retouch the PR.

Comment thread src/wallet/spend.cpp Resolved
Comment thread src/wallet/spend.cpp Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved
ishaanam and others added 12 commits August 15, 2025 10:45
In future commits we assume that coin_control.m_version has a
value when making sure that we follow truc rules, so we should
give it a default value of CTransaction::CURRENT_VERSION.
Adds v3 support to the following RPCs:
- createrawtransaction
- createpsbt
- send
- sendall
- walletcreatefundedpsbt

Co-authored-by: chungeun-choi <cucuridas@gmail.com>
Co-authored-by: dongwook-chan <dongwook.chan@gmail.com>
Co-authored-by: sean-k1 <uhs2000@naver.com>
Co-authored-by: ishaanam <ishaana.misra@gmail.com>
@glozow

glozow commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

reACK 5c8bf7b

@DrahtBot
DrahtBot requested a review from rkrux August 15, 2025 17:00

@achow101 achow101 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5c8bf7b

I'm not fully sold on the approach of choosing the highest value TRUC UTXO, but don't have any ideas on how to change that for this PR. Maybe @murchandamus has some thoughts on that.

Comment thread src/wallet/spend.cpp
const Txid& truc_txid = highest_value_truc_tx->first;
for (const auto& [type, output] : unconfirmed_truc_coins) {
if (output.outpoint.hash == truc_txid) {
result.Add(type, output);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c5a2d08 "wallet: don't return utxos from multiple truc txs in AvailableCoins"

nit: extra indent

@rkrux rkrux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5c8bf7b

git range-diff 5c087f5...5c8bf7b

@murchandamus

Copy link
Copy Markdown
Member

I'm not fully sold on the approach of choosing the highest value TRUC UTXO, but don't have any ideas on how to change that for this PR. Maybe @murchandamus has some thoughts on that.

Been pondering this a bit today.

  • In the first pass, we will always try to fund transactions only with confirmed UTXOs. If we are just requesting a new TRUC transaction, it will always get funded by confirmed UTXOs if we have sufficient confirmed funds.
  • If we are deliberately creating a child transaction, it’s probably because we want to CPFP an existing TRUC transaction and that already restricts the unconfirmed UTXOs to be created by the specific parent transaction. In that case, only other outputs from the same transactions are other eligible unconfirmed inputs.
  • This leaves only the case in which we are creating a TRUC transaction, but we do not have sufficient confirmed funds to pay for it. In that case, we can use one or several unconfirmed UTXOs from a single transaction in addition to any number of confirmed UTXOs.

We do have the nDepth member on COutput, so if we have several unconfirmed single outputs from transactions, we could keep track of whether we have selected an unconfirmed UTXO. Whenever we were to add a second unconfirmed UTXO, we could keep it or replace it with new one, depending on which has the greater effective value instead of adding it. Perhaps, just in case of creating TRUC transactions, we would create a new type of OutputGroups based on common parent transaction instead of common output script in that context. Because we can only use one OutputGroup that contains unconfirmed UTXOs, we could generate all subsets of a transaction’s outputs as separate OutputGroups, and thereby have those unconfirmed UTXOs appear multiple times in different configurations. We could only use that approach if there is a small number (<10?) of outputs to ourselves on the transaction as power sets grow exponentially. Either way, it might be easier to have a dedicated algorithm for TRUC child transactions, that tracks the two pots separately, but all of that seems very complicated.

Given that it should be fairly uncommon to have all of your funds in flight and the complexity of alternatives, using the largest UTXO or group of UTXOs feels viable to me, although it could be improved in the future.

Comment thread src/wallet/spend.cpp
Comment on lines +288 to +292
if (parent_tx.tx->version == TRUC_VERSION && coin_control.m_version != TRUC_VERSION) {
return util::Error{strprintf(_("Can't spend unconfirmed version 3 pre-selected input with a version %d tx"), coin_control.m_version)};
} else if (coin_control.m_version == TRUC_VERSION && parent_tx.tx->version != TRUC_VERSION) {
return util::Error{strprintf(_("Can't spend unconfirmed version %d pre-selected input with a version 3 tx"), parent_tx.tx->version)};
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translations followup in #33193.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for creating v3 raw transactions in createrawtransaction RPC

10 participants