walletcreatefundedpsbt fails unexpectedly with "insufficient funds" #22821

issue GambolingPangolin opened this issue on August 27, 2021
  1. GambolingPangolin commented at 10:27 PM on August 27, 2021: none

    <!-- This issue tracker is only for technical issues related to Bitcoin Core. General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com. For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/. If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

    <!-- Describe the issue -->

    I would like to use bitcoin core to track watch-only addresses and create PSBTs. For my use case, I tried to use walletcreatefundedpsbt with fully specified inputs and outputs, mostly for the purpose of modifying the outputs to achieve a certain fee rate for the transaction. I define outputs with pre-fee amounts, then set fee_rate and subtractFeeFromOutputs.

    Expected behavior

    <!--- What behavior did you expect? -->

    The RPC call should succeed and give me a PSBT where each output amount is a little less than the argument amount, to cover the fee.

    Actual behavior

    <!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

    The call fails with "Insufficient funds". If I use getnewaddress and fund an output paying to this address instead, the call works as expected. The problem only appears when the output I am trying to spend is watch-only.

    To reproduce

    <!--- How reliably can you reproduce the issue, what are the steps to do so? -->

    This script demonstrates the problem in a minimal scenario: https://gist.github.com/GambolingPangolin/587c46e9e5421a5401973406a0869519

    System information

    <!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

    Bitcoin Core v0.21.1 downloaded from bitcoincore.org.

    <!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

    Ubuntu 20.04

    <!-- GUI-related issue? What is your operating system and its version? If Linux, what is your desktop environment and graphical shell? -->

    <!-- Any extra information that might be useful in the debugging process. -->

    <!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->

  2. GambolingPangolin added the label Bug on Aug 27, 2021
  3. achow101 commented at 11:10 PM on August 27, 2021: member

    I don't think there is any bug here, just a misunderstanding of how the software works.

    There are a few possible issues with the provided script that could cause an insufficient funds message.

    First, your input specification could be incorrect. You have specified "vout": 0, but there is no guarantee that the UTXO you want is at index 0. If the UTXO is not in the wallet, then the wallet will not know anything about it and cannot create the transaction.

    Second, You have only imported the address, not the public key. The wallet does not have enough information to estimate the size of the signed input so it is unable to choose inputs. You will need to import a public key rather than just the address.

  4. GambolingPangolin commented at 11:30 PM on August 27, 2021: none

    @achow101 Thanks for your comments!

    My example script does indeed have the incorrect vout configured. I corrected it and can confirm that when the outpoint is correct (known via the call to listtransactions), the call to walletcreatefundedpsbt fails with the same error.

    Your second point makes a lot of sense. I was expecting the wallet to use a heuristic, such as assume all signatures are as large as possible, rather than failing. It seems appropriate to have a different error message here, if this is indeed what is happening.

  5. GambolingPangolin commented at 4:09 PM on August 30, 2021: none

    @achow101 I updated the script and verified that your suggestion to import the public key does give the expected result. Thanks for your help!

  6. GambolingPangolin closed this on Aug 30, 2021

  7. DrahtBot locked this on Aug 30, 2022
Labels

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-03 15:14 UTC

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