rpc: add prev_txs param to utxoupdatepsbt #34992

pull bittoby wants to merge 2 commits into bitcoin:master from bittoby:rpc-utxoupdatepsbt-add-prev-txs changing 3 files +110 −8
  1. bittoby commented at 9:47 pm on April 2, 2026: none

    Summary

    Add an optional prev_txs parameter to utxoupdatepsbt, allowing callers to provide raw parent transactions whose outputs are not yet in the UTXO set, txindex, or mempool.

    Motivation

    When constructing presigned transaction chains (e.g. a Lightning commitment transaction at zero fee paired with an anchor spend), the child PSBT cannot be populated because the parent has not been broadcast yet. The existing signrawtransactionwithwallet supports this via its prevtxs parameter, but no equivalent exists in the PSBT workflow. Users are forced to either fall back to legacy raw transaction signing or manually edit the PSBT binary with external tools.

    This closes the gap so that utxoupdatepsbt can handle the same use case natively, which is increasingly relevant with submitpackage and TRUC/anchor adoption.

    Changes

    • Add ParsePrevTxs() helper to decode an array of raw transaction hex into a txid-indexed map
    • Extend ProcessPSBT() to accept caller-provided transactions and check them before falling through to txindex/mempool/UTXO set lookup
    • Register the new prev_txs array parameter on utxoupdatepsbt
    • Add functional test covering the happy path, named parameter form, and invalid hex error handling

    refs #30873

    Test plan

    • test/functional/rpc_psbt.py passes, including new test_utxoupdatepsbt_prev_txs covering:
      • Input NOT populated when parent is unavailable
      • Input populated correctly via prev_txs
      • Correct txid in the resulting non_witness_utxo
      • Error on invalid hex
      • Named parameter form works
  2. DrahtBot added the label RPC/REST/ZMQ on Apr 2, 2026
  3. DrahtBot commented at 9:47 pm on April 2, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK achow101

    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:

    • #33014 (rpc: Fix internal bug in descriptorprocesspsbt when encountering invalid signatures by b-l-u-e)

    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.

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • node.descriptorprocesspsbt(child_psbt, [desc], “DEFAULT”, True, True, [parent_hex]) in test/functional/rpc_psbt.py

    2026-04-07 21:18:09

  4. bittoby commented at 11:14 am on April 6, 2026: none
    @achow101 Sorry to ping you. I haven’t gotten any messages yet. Could you please review this PR? Welcome to any feedback.
  5. instagibbs commented at 12:14 pm on April 6, 2026: member
    my prior attempt hit a lack of interest in reviewing: #30886 (comment)
  6. in src/rpc/rawtransaction.cpp:137 in 9bff773567
    132+        if (!DecodeHexTx(mtx, prev_txs[i].get_str())) {
    133+            throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
    134+                               strprintf("TX decode failed for prev_tx %u", i));
    135+        }
    136+        CTransactionRef tx{MakeTransactionRef(std::move(mtx))};
    137+        result.emplace(tx->GetHash(), std::move(tx));
    


    achow101 commented at 8:09 pm on April 6, 2026:
    This could check if the tx was actually inserted and error if not as that means a tx was specified multiple times.
  7. in src/rpc/rawtransaction.cpp:2079 in 9bff773567
    2074@@ -2044,7 +2075,8 @@ RPCMethod descriptorprocesspsbt()
    2075         request.context,
    2076         HidingSigningProvider(&provider, /*hide_secret=*/false, !bip32derivs),
    2077         sighash_type,
    2078-        finalize);
    2079+        finalize,
    2080+        /*prev_txs=*/{});
    


    achow101 commented at 8:09 pm on April 6, 2026:
    Any reason to not implement this for descriptorprocesspsbt?
  8. achow101 commented at 8:09 pm on April 6, 2026: member
    Concept ACK
  9. bittoby commented at 8:23 pm on April 6, 2026: none
    Thanks for your feedback. Updated! please review again
  10. achow101 commented at 10:24 pm on April 6, 2026: member
    Please rebase your changes in accordance with https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes. PRs should not have merge commits, and each commit needs to compile and pass the tests individually.
  11. bittoby force-pushed on Apr 6, 2026
  12. bittoby commented at 11:17 pm on April 6, 2026: none
    @achow101 I rebased my changes following the contribution guideline.
  13. bittoby requested review from achow101 on Apr 7, 2026
  14. bittoby commented at 8:08 pm on April 7, 2026: none
    Pls let me know what else should I need to update.
  15. rpc: add prev_txs param to utxoupdatepsbt 71fa3d1ffb
  16. rpc: add prev_txs parameter to descriptorprocesspsbt ab8c690549
  17. in src/rpc/rawtransaction.cpp:141 in 84a8a26d4e outdated
    133@@ -134,7 +134,11 @@ static std::map<Txid, CTransactionRef> ParsePrevTxs(const UniValue& prev_txs)
    134                                strprintf("TX decode failed for prev_tx %u", i));
    135         }
    136         CTransactionRef tx{MakeTransactionRef(std::move(mtx))};
    137-        result.emplace(tx->GetHash(), std::move(tx));
    138+        auto [it, inserted] = result.emplace(tx->GetHash(), std::move(tx));
    139+        if (!inserted) {
    140+            throw JSONRPCError(RPC_INVALID_PARAMETER,
    141+                               strprintf("Duplicate prev_tx %s at index %u", it->first.ToString(), i));
    142+        }
    


    achow101 commented at 8:54 pm on April 7, 2026:

    In 84a8a26d4e11ae43fc5663c614baa4f36d01dd69 “rpc: error on duplicate prev_txs entries and add prev_txs parameter to descriptorprocesspsbt”

    This should be done in the previous commit when this function is introduced.

  18. bittoby force-pushed on Apr 7, 2026
  19. bittoby force-pushed on Apr 7, 2026
  20. bittoby commented at 9:18 pm on April 7, 2026: none
    @achow101 I have updated. Pls review again. Thanks for your feedback. 👍
  21. bittoby requested review from achow101 on Apr 7, 2026
  22. bittoby commented at 1:06 pm on April 10, 2026: none
    Hi @achow101, could you approve this pr or pls let me know what else should I need to update?
  23. maflcko commented at 1:20 pm on April 10, 2026: member
    @bittoby Please stop spamming! Every ping is sent to 4000 notifications and continuing to ping will likely get you blocked by people or even banned by the project for violating the documented review process.
  24. in src/rpc/rawtransaction.cpp:1769 in ab8c690549
    1765@@ -1750,12 +1766,16 @@ static RPCMethod utxoupdatepsbt()
    1766                          {"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "Up to what index HD chains should be explored (either end or [begin,end])"},
    1767                     }},
    1768                 }},
    1769+                {"prev_txs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "An array of raw transaction hex strings for previous transactions whose outputs are being spent in this PSBT but may not be available in the UTXO set, txindex, or the mempool", {
    


    luke-jr commented at 5:53 pm on April 11, 2026:
    0                {"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "An array of raw transaction hex strings for previous transactions whose outputs are being spent in this PSBT but may not be available in the UTXO set, txindex, or the mempool", {
    
  25. luke-jr changes_requested

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-12 03:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me