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

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK achow101

    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:

    • #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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    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

    <sup>2026-04-13 14:17:12</sup>

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

  16. bittoby force-pushed on Apr 7, 2026
  17. bittoby force-pushed on Apr 7, 2026
  18. bittoby commented at 9:18 PM on April 7, 2026: none

    @achow101 I have updated. Pls review again. Thanks for your feedback. 👍

  19. bittoby requested review from achow101 on Apr 7, 2026
  20. 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?

  21. 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.

  22. 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:
                    {"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", {
    

    bittoby commented at 2:17 PM on April 13, 2026:

    Updated! thanks

  23. luke-jr changes_requested
  24. rpc: add prevtxs param to utxoupdatepsbt
    Add an optional prevtxs parameter to utxoupdatepsbt that accepts an
    array of raw transaction hex strings. This allows callers to supply
    previous transactions whose outputs are being spent in the PSBT but
    may not be available in the UTXO set, txindex, or the mempool.
    
    The lookup order is: caller-provided transactions, then txindex,
    then mempool. Duplicate entries in prevtxs are rejected with an
    error.
    50fbe309e3
  25. rpc: add prevtxs parameter to descriptorprocesspsbt
    Extend the prevtxs parameter (added to utxoupdatepsbt in the
    previous commit) to descriptorprocesspsbt as well, for consistency.
    2cbbbc53cd
  26. bittoby force-pushed on Apr 13, 2026
  27. DrahtBot added the label CI failed on Apr 17, 2026
  28. maflcko removed the label CI failed on Apr 17, 2026

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-05-02 12:12 UTC

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