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 commented at 10:29 am on July 21, 2021: member

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

    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.

  6. 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
  7. theStack commented at 11:16 am on July 21, 2021: member
    Concept ACK
  8. 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
  9. 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
  10. achow101 force-pushed on Jul 24, 2021
  11. achow101 force-pushed on Jul 24, 2021
  12. 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).
  13. 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.

  14. ryanofsky commented at 8:22 pm on July 28, 2021: member

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

  15. achow101 force-pushed on Jul 28, 2021
  16. 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.
  17. darosior approved
  18. darosior commented at 8:55 am on July 29, 2021: member
    re-ACK 7f9310db58d77571adc04c6e6d48f5d11fa44c8c
  19. luke-jr changes_requested
  20. 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.
  21. DrahtBot added the label Needs rebase on Sep 28, 2021
  22. psbt: sign without finalizing
    We don't always want to finalize after signing, so make it possible to
    do that.
    a99ed89865
  23. achow101 force-pushed on Sep 28, 2021
  24. DrahtBot removed the label Needs rebase on Sep 29, 2021
  25. 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
  26. meshcollider commented at 1:55 am on September 30, 2021: contributor
    utACK a99ed8986554fa1ecc854e43ea373d957e598db8
  27. luke-jr referenced this in commit ee19f41b07 on Oct 10, 2021
  28. Sjors commented at 10:02 am on November 19, 2021: member
    utACK a99ed89
  29. laanwj merged this on Nov 29, 2021
  30. laanwj closed this on Nov 29, 2021

  31. sidhujag referenced this in commit 6b36216180 on Nov 30, 2021
  32. RandyMcMillan referenced this in commit b63551cc4a on Dec 23, 2021
  33. DrahtBot 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: 2024-09-28 22:12 UTC

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