rpc: Allow walletprocesspsbt to sign without finalizing #22513

pull achow101 wants to merge 1 commits into bitcoin:master from achow101:psbt-no-finalize changing 11 files +32 −20
  1. achow101 commented at 2:16 AM on July 21, 2021: member

    It can be useful to sign an input with walletprocesspsbt but not finalize that input if it is complete. This PR adds another option to walletprocesspsbt to be able to do that. We will still finalize by default.

    This does not materially change the PSBT workflow since finalizepsbt needs to be called in order to extract the tx for broadcast.

  2. fanquake added the label PSBT on Jul 21, 2021
  3. darosior approved
  4. darosior commented at 9:44 AM on July 21, 2021: member

    ACK 81a8c35855

    Here is a small test exercising the new logic: https://github.com/darosior/bitcoin/commit/cef80424312f159671977d5152444af4bfbbef41

  5. DrahtBot cross-referenced this on Jul 21, 2021 from issue psbt: Actually use SIGHASH_DEFAULT for PSBT signing by achow101
  6. DrahtBot commented at 10:29 AM on July 21, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23602 (wallet: Split stuff from rpcwallet by MarcoFalke)
    • #23578 (Add external signer taproot support by Sjors)
    • #22558 (psbt: Taproot fields for PSBT by achow101)
    • #22514 (psbt: Actually use SIGHASH_DEFAULT for PSBT signing 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.

  7. in src/wallet/wallet.h:587 in 81a8c35855 outdated
     583 | @@ -584,6 +584,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
     584 |                    int sighash_type = 1 /* SIGHASH_ALL */,
     585 |                    bool sign = true,
     586 |                    bool bip32derivs = true,
     587 | +                  bool finalize = true,
    


    theStack commented at 11:16 AM on July 21, 2021:

    nit: could also add doxygen documentation (a few lines above) for the newly introduced parameter


    achow101 commented at 2:13 AM on July 24, 2021:

    Done

  8. theStack commented at 11:16 AM on July 21, 2021: contributor

    Concept ACK

  9. DrahtBot cross-referenced this on Jul 21, 2021 from issue Implement BIP 370 PSBTv2 by achow101
  10. in src/psbt.h:581 in 81a8c35855 outdated
     577 | @@ -578,7 +578,7 @@ bool PSBTInputSigned(const PSBTInput& input);
     578 |   * txdata should be the output of PrecomputePSBTData (which can be shared across
     579 |   * multiple SignPSBTInput calls). If it is nullptr, a dummy signature will be created.
     580 |   **/
     581 | -bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr);
     582 | +bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash = SIGHASH_ALL, bool finalize = true, SignatureData* out_sigdata = nullptr);
    


    luke-jr commented at 7:54 AM on July 22, 2021:

    Please take more care when changing function signatures. This could silently cast a SignatureData* to a bool when merging another PR created prior to the API change.


    achow101 commented at 2:14 AM on July 24, 2021:

    Changed to the last parameter

  11. in src/wallet/rpcwallet.cpp:4432 in 81a8c35855 outdated
    4314 | @@ -4315,6 +4315,7 @@ static RPCHelpMan walletprocesspsbt()
    4315 |              "       \"NONE|ANYONECANPAY\"\n"
    4316 |              "       \"SINGLE|ANYONECANPAY\""},
    4317 |                      {"bip32derivs", RPCArg::Type::BOOL, RPCArg::Default{true}, "Include BIP 32 derivation paths for public keys if we know them"},
    4318 | +                    {"finalize", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also finalize inputs if possible"},
    


    luke-jr commented at 7:55 AM on July 22, 2021:

    Can you make an options Object instead of another series of booleans?


    achow101 commented at 2:14 AM on July 24, 2021:

    Done

  12. achow101 force-pushed on Jul 24, 2021
  13. achow101 force-pushed on Jul 24, 2021
  14. DrahtBot cross-referenced this on Jul 24, 2021 from issue rpc, gui: bumpfee signer support by Sjors
  15. DrahtBot cross-referenced this on Jul 24, 2021 from issue Allow fundrawtransaction and walletcreatefundedpsbt to take external inputs by achow101
  16. achow101 cross-referenced this on Jul 26, 2021 from issue psbt: Taproot fields for PSBT by achow101
  17. laanwj commented at 2:17 PM on July 28, 2021: member

    I'm not entirely sure whether it's better to use an options object here instead of the conventional interface with named parameters? The latter is easier to use from bitcoin-cli at least (can just use -named arg=value instead of having to wrap everything into JSON manually).

  18. achow101 commented at 6:05 PM on July 28, 2021: member

    I'm not entirely sure whether it's better to use an options object here instead of the conventional interface with named parameters? The latter is easier to use from bitcoin-cli at least (can just use -named arg=value instead of having to wrap everything into JSON manually).

    I wonder if there is some syntactic sugar thing we can add that allows us to not have to write JSON manually.

  19. ryanofsky commented at 8:22 PM on July 28, 2021: contributor

    I wonder if there is some syntactic sugar thing we can add that allows us to not have to write JSON manually.

    If by syntactic sugar you mean a client-only change, then bitcoin-cli could accept a lighter weight YAML-like syntax and turn it into JSON. But this seems it would be a headache to maintain and a new thing users would have to learn to take advantage of.

    I think a better approach, given that we already have a syntax for positional arguments, and we already have a syntax for named arguments, is to just allow these existing syntaxes to be used together. #19762 is a client+server change which does this. And it benefits not just bitcoin-cli but also other RPC clients like the python client so you can call rpc.methodname(arg1, arg2, option=value) instead of rpc.methodname(arg1, arg2, {"option": value})

    A third approach which Luke at one point liked and perhaps still likes is a server-only change which translates named parameters into options values: #11441 (IIRC similar behavior was also part of #11660).

  20. achow101 force-pushed on Jul 28, 2021
  21. achow101 commented at 9:21 PM on July 28, 2021: member

    I've dropped the change to use the options object since it is orthogonal to the purpose of this PR. It seems like that will need more discussion too. I've opened issue #22575 for the discussion of what to do about RPCs with lots of positional arguments.

  22. darosior approved
  23. darosior commented at 8:55 AM on July 29, 2021: member

    re-ACK 7f9310db58d77571adc04c6e6d48f5d11fa44c8c

  24. DrahtBot cross-referenced this on Aug 10, 2021 from issue rpc: Add function walletestimatefee by pranabp-bit
  25. luke-jr changes_requested
  26. luke-jr commented at 6:19 PM on September 11, 2021: member

    NACK with positional bool parameter. We shouldn't make the API worse than it already is.

  27. DrahtBot cross-referenced this on Sep 27, 2021 from issue Ensure wallet is unlocked before signing PSBT with walletprocesspsbt and GUI by meshcollider
  28. DrahtBot added the label Needs rebase on Sep 28, 2021
  29. psbt: sign without finalizing
    We don't always want to finalize after signing, so make it possible to
    do that.
    a99ed89865
  30. achow101 force-pushed on Sep 28, 2021
  31. DrahtBot removed the label Needs rebase on Sep 29, 2021
  32. in test/functional/rpc_psbt.py:124 in a99ed89865
     118 | @@ -119,7 +119,9 @@ def run_test(self):
     119 |          self.nodes[0].walletpassphrase(passphrase="password", timeout=1000000)
     120 |  
     121 |          # Sign the transaction and send
     122 | -        signed_tx = self.nodes[0].walletprocesspsbt(psbtx)['psbt']
     123 | +        signed_tx = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=False)['psbt']
     124 | +        finalized_tx = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=True)['psbt']
     125 | +        assert signed_tx != finalized_tx
    


    meshcollider commented at 1:55 AM on September 30, 2021:

    Could also assert ['complete'] is not true before finalizing but is true afterwards


    Sjors commented at 9:50 AM on November 19, 2021:

    In that case the result documentation for complete should also be clarified: "If the transaction has a complete set of signatures and its inputs are finalized"

  33. meshcollider commented at 1:55 AM on September 30, 2021: contributor

    utACK a99ed8986554fa1ecc854e43ea373d957e598db8

  34. luke-jr referenced this in commit ee19f41b07 on Oct 10, 2021
  35. DrahtBot cross-referenced this on Nov 14, 2021 from issue wallet: Avoid underpaying transaction fees when signing taproot spends by achow101
  36. Sjors commented at 10:02 AM on November 19, 2021: member

    utACK a99ed89

  37. DrahtBot cross-referenced this on Nov 23, 2021 from issue Add external signer taproot support by Sjors
  38. DrahtBot cross-referenced this on Nov 27, 2021 from issue wallet: Split stuff from rpcwallet by MarcoFalke
  39. laanwj merged this on Nov 29, 2021
  40. laanwj closed this on Nov 29, 2021

  41. sidhujag referenced this in commit 6b36216180 on Nov 30, 2021
  42. RandyMcMillan referenced this in commit b63551cc4a on Dec 23, 2021
  43. bitcoin locked this on Nov 29, 2022

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-19 06:53 UTC