Watchonly descriptor wallets classifying funds as `mine`, are "spendable" #21104

issue niftynei opened this issue on February 7, 2021
  1. niftynei commented at 7:30 PM on February 7, 2021: contributor

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

    Expected behavior

    I'd expect funds in a watchonly wallet to be shown as "watchonly", be unspendable.

    Actual behavior

    Funds are shown as "mine" in getbalances, can be "spent" (sendtoaddress completes without error, however transaction is unspent and fails to enter mempool. Balance is incorrectly decremented)

    To reproduce

    Make a watchonly descriptor wallet.

    bitcoin-cli createwallet w2 true true "" true true false 
    

    Load up a descriptor that's got some funds on it.

    $ bitcoin-cli -rpcwallet=w2 importdescriptors '[{"desc":"wpkh(tpubD6NzVbkrYhZ4Wh1z2cvkzQsM12k9kvyMMrGXi7rdk5eyUYUFND1qhB1zEZ3pJwSSSGLYsKfZLKNvs4L7oqNb8vJj3zJTvxMRCKWsNhX9JXQ/*)#86kup682", "timestamp":"now","active":true,"range":100}]'
    
    

    See the balance.

    $ bitcoin-cli -rpcwallet=w2 getbalances
    {
      "mine": {
        "trusted": 3.00000000,
        "untrusted_pending": 3.00000000,
        "immature": 0.00000000,
        "used": 0.00000000
      }
    }
    

    Spend the balance.

    $ bitcoin-cli -rpcwallet=w2 sendtoaddress bcrt1qnk09yy5ayyhwvfydg2x58zwy443pjx5uesg9gw 3.0 "" "" true
    90bce182f476376e6cf3552e234c686ce5bfee4d47739081f5cba90de374156b
    

    See the balance update.

    $ bitcoin-cli -rpcwallet=w2 getbalances
    {
      "mine": {
        "trusted": 0.00000000,
        "untrusted_pending": 0.00000000,
        "immature": 0.00000000,
        "used": 3.00000000
      }
    }
    

    Not in the mempool though

    $ bitcoin-cli getmempoolentry 90bce182f476376e6cf3552e234c686ce5bfee4d47739081f5cba90de374156b
    error code: -5
    error message:
    Transaction not in mempool
    

    System information

    Bitcoin Core version v0.21.0

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

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

    <!-- 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. niftynei added the label Bug on Feb 7, 2021
  3. fanquake added the label Wallet on Feb 8, 2021
  4. fanquake commented at 1:25 AM on February 8, 2021: member
  5. danben commented at 10:22 PM on February 15, 2021: contributor

    I've started reading wallet code in order to hopefully fix this, but if it is or becomes urgent then someone who already knows how should do it instead.

  6. sipa commented at 10:29 PM on February 15, 2021: member

    I believe that the fact that the funds are listed as spendable is expected (descriptor wallets don't distinguish between watchonly and spendable funds; if you want separate balances, create separate wallets). I can't explain why sending doesn't error, or reduces available funds, though.

  7. sipa commented at 10:36 PM on February 15, 2021: member

    ping @achow101

  8. achow101 commented at 6:31 PM on February 16, 2021: member

    The funds being shown as spendable is intended behavior. However sendtoaddress (and sendmany) should not actually be creating a transaction when private keys are not available. #21201 should fix this.

  9. sipa commented at 6:33 PM on February 16, 2021: member

    @achow101 What if you have a wallet that doesn't have private keys disabled, but has a descriptor without private keys (or with insufficient private keys) imported. Is there a risk that sendtoaddress would still "succeed"?

  10. achow101 commented at 6:39 PM on February 16, 2021: member

    @sipa it shouldn't be possible to import a descriptor without private keys to a wallet with private keys enabled.

  11. meshcollider closed this on Feb 19, 2021

  12. sidhujag referenced this in commit 528500d884 on Feb 19, 2021
  13. DrahtBot locked this on Aug 18, 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-04-13 15:14 UTC

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