fundrawtransaction fails to add watchonly addresses imported with importaddress #7879

issue dooglus opened this issue on April 15, 2016
  1. dooglus commented at 2:11 AM on April 15, 2016: contributor

    I have a wallet with nothing but a bunch of addresses I imported using importaddress.

    I tried using fundrawtransaction with includeWatching set to true but it always tells me I have insufficient funds.

    It turns out that for this to work I need to have added the watchonly address using importpubkey not importaddress because otherwise IsMine() on the output's scriptPubKey fails because the dummy signer's scriptSig has 0 for the public key, causing the HASH160 ... EQUALVERIFY part to fail when testing the signature in here:

    ProduceSignature(DummySignatureCreator(&keystore), scriptPubKey, scriptSig) ? ISMINE_WATCH_SOLVABLE : ISMINE_WATCH_UNSOLVABLE;
    

    That evaluates to ISMINE_WATCH_UNSOLVABLE even though it is actually solvable, and so stops any of my outputs being considered for inclusion. output.fSpendable is false for each output when CWallet::SelectCoinsMinConf() runs.

  2. laanwj added the label RPC/REST/ZMQ on Apr 15, 2016
  3. dooglus commented at 5:03 AM on April 16, 2016: contributor

    I was able to fund a raw transaction using watchonly outputs for which I don't have a local copy of the public keys using this workaround: https://github.com/dooglus/bitcoin/commit/0b29c31da9d711ce87b7d7f0987fc3f57f1b7e91

    I have the public keys on an airgapped machine, where I intend to sign the funded raw transaction. I don't want to have to have the public keys on my online machine.

    It's probably not the correct fix, but it demonstrates where the problem is.

  4. MarcoFalke commented at 6:16 PM on July 16, 2018: member

    @dooglus Is this still an issue?

    If so, you might also write a functional test that exercises the logic.

  5. dooglus commented at 2:30 AM on July 17, 2018: contributor

    @MarcoFalke It is still an issue. It's quite easy to reproduce. I'm starting with two brand new wallets in the following.

    If I use importaddress, I'm unable to use fundrawtransaction:

    $ bitcoin-cli -rpcwallet=wallet.dat.without-pubkey importaddress 31tWekVaFzyNmnHUpnEyXNxU5LFNLLPY1R '' false
    $ bitcoin-cli -rpcwallet=wallet.dat.without-pubkey importprunedfunds 01000000021dbc1565f9384a9734ca989495f5f6af293fa138f33d7ec07d024ba36f4040d7010000006b483045022100e6621fab2ea54ffcfca7a23f72016726f145c664f13e075321aa5bcdcf0f395d0220149f7cdada8a49fa4c9b98a339f488e07d3ca99aee0fb4645b40662eeb6fff34012103c1d769f2c71f29ee7903958ff0feba19d369ae6962958d3e4c75c0cf574f20b7ffffffff0e732a7bb9bca70ad7419710a6547cfa6141df7b51bbcdabad6f66fc17d56d43010000006a47304402202690fb573848bfadfba74da2d7de14e52fb5e6e256f176ee6d5b40478e7fc1680220619a4267cf43e6b49ad41525e618f010cf304b2da8b0f252cada26b1439e3519012103af3c9a39f55efdcd497595935ffff1f0ff0974a966780d9698d5b60fc6c7e5c0ffffffff0227158c00000000001976a91462fc24c1381521b89da1749f51e5c61124dba0c988ac00e1f5050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000 0000002096711ff59ef599014f92c3969abbef7cbfbabb7b61ad23000000000000000000d5c0b889391aa9f264f300afda71731f3d5ea7965949ff90b07825ca46a5833707a13a5b287a3417a08e64c3050900000ddc84846cdb49891e8fb6f7340cf0f0b4e5cc5a0056fae2fdf45fd7031b00ad2335c710e38a998f33afa3c237620544b7ef2ae1ed11ff1a4148d429afd1a0c4826369a4d2ab7b1bf21ceecc717de9f32311aa52065d51dd9337978070175dcc95867d2c8b7dff2cdc6064886d59a584c62646dfa06df416166cad1239da9d8808465252f1ee50c409aecd247c59b5ccd9c26b54707615a683a445e035f626b3fa6140d95433e014a8a033ba2ef6bfde46f138850c601e4ea4bcb1d88e09fe0b7be1361fa3d96c58be1dabbc0ab551aa9e93b3742c169a442e8aa7e4fe87568ada6e183c892b2ad1af439c013935e8058aae9f60bb0a3b48932f7018194e1705dff0b85157086409d68bfc664eefa1278f330d3d965ff1bc105e8b13f951fa425cef39ec9b6a444cd6de8061245c59ab00c559ea650723f96381a865c0a4d4a2e1dc65e28364622d34b64c0dccbbe46d84ea3a05cf6de09257d97aa268f9e9fbb5be8eb80776ae1d289cf41586e64c6f79f59533bc392b92831897ed66d92c3ccf3726328012cde8c825667d4b94e1ca200ae2603f5b1fb3307551d98717c16fcf04abdd0500
    $ bitcoin-cli -rpcwallet=wallet.dat.without-pubkey listunspent
    [
      {
        "txid": "da8a5687fee4a78a2e449a162c74b3939eaa51b50abcab1dbe586cd9a31f36e1",
        "vout": 1,
        "address": "31tWekVaFzyNmnHUpnEyXNxU5LFNLLPY1R",
        "account": "",
        "scriptPubKey": "a914022c8e671bef27b8b6ebea31d40608e0ba8444a787",
        "amount": 1.00000000,
        "confirmations": 1967,
        "spendable": false,
        "solvable": false,
        "safe": true
      }
    ]
    $ bitcoin-cli -rpcwallet=wallet.dat.without-pubkey createrawtransaction '[]' '{"31tWekVaFzyNmnHUpnEyXNxU5LFNLLPY1R":0.9}'
    020000000001804a5d050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000
    $ bitcoin-cli -rpcwallet=wallet.dat.without-pubkey fundrawtransaction 020000000001804a5d050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000 '{"includeWatching":true}'
    error code: -4
    error message:
    Insufficient funds

    But if I use importpubkey instead and do everything else the same, it works:

    $ bitcoin-cli -rpcwallet=wallet.dat.with-pubkey importpubkey 03297f5884ce5b2afde7f420c8a38ea26c0af44423be5f6919eb47f6b947e7f243 '' false
    $ bitcoin-cli -rpcwallet=wallet.dat.with-pubkey importprunedfunds 01000000021dbc1565f9384a9734ca989495f5f6af293fa138f33d7ec07d024ba36f4040d7010000006b483045022100e6621fab2ea54ffcfca7a23f72016726f145c664f13e075321aa5bcdcf0f395d0220149f7cdada8a49fa4c9b98a339f488e07d3ca99aee0fb4645b40662eeb6fff34012103c1d769f2c71f29ee7903958ff0feba19d369ae6962958d3e4c75c0cf574f20b7ffffffff0e732a7bb9bca70ad7419710a6547cfa6141df7b51bbcdabad6f66fc17d56d43010000006a47304402202690fb573848bfadfba74da2d7de14e52fb5e6e256f176ee6d5b40478e7fc1680220619a4267cf43e6b49ad41525e618f010cf304b2da8b0f252cada26b1439e3519012103af3c9a39f55efdcd497595935ffff1f0ff0974a966780d9698d5b60fc6c7e5c0ffffffff0227158c00000000001976a91462fc24c1381521b89da1749f51e5c61124dba0c988ac00e1f5050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000 0000002096711ff59ef599014f92c3969abbef7cbfbabb7b61ad23000000000000000000d5c0b889391aa9f264f300afda71731f3d5ea7965949ff90b07825ca46a5833707a13a5b287a3417a08e64c3050900000ddc84846cdb49891e8fb6f7340cf0f0b4e5cc5a0056fae2fdf45fd7031b00ad2335c710e38a998f33afa3c237620544b7ef2ae1ed11ff1a4148d429afd1a0c4826369a4d2ab7b1bf21ceecc717de9f32311aa52065d51dd9337978070175dcc95867d2c8b7dff2cdc6064886d59a584c62646dfa06df416166cad1239da9d8808465252f1ee50c409aecd247c59b5ccd9c26b54707615a683a445e035f626b3fa6140d95433e014a8a033ba2ef6bfde46f138850c601e4ea4bcb1d88e09fe0b7be1361fa3d96c58be1dabbc0ab551aa9e93b3742c169a442e8aa7e4fe87568ada6e183c892b2ad1af439c013935e8058aae9f60bb0a3b48932f7018194e1705dff0b85157086409d68bfc664eefa1278f330d3d965ff1bc105e8b13f951fa425cef39ec9b6a444cd6de8061245c59ab00c559ea650723f96381a865c0a4d4a2e1dc65e28364622d34b64c0dccbbe46d84ea3a05cf6de09257d97aa268f9e9fbb5be8eb80776ae1d289cf41586e64c6f79f59533bc392b92831897ed66d92c3ccf3726328012cde8c825667d4b94e1ca200ae2603f5b1fb3307551d98717c16fcf04abdd0500
    $ bitcoin-cli -rpcwallet=wallet.dat.with-pubkey listunspent
    [
      {
        "txid": "da8a5687fee4a78a2e449a162c74b3939eaa51b50abcab1dbe586cd9a31f36e1",
        "vout": 1,
        "address": "31tWekVaFzyNmnHUpnEyXNxU5LFNLLPY1R",
        "account": "",
        "redeemScript": "001440e5442f95994d108c9730d2b53a85c6c33141d7",
        "scriptPubKey": "a914022c8e671bef27b8b6ebea31d40608e0ba8444a787",
        "amount": 1.00000000,
        "confirmations": 1967,
        "spendable": false,
        "solvable": true,
        "safe": true
      }
    ]
    $ bitcoin-cli -rpcwallet=wallet.dat.with-pubkey createrawtransaction '[]' '{"31tWekVaFzyNmnHUpnEyXNxU5LFNLLPY1R":0.9}'
    020000000001804a5d050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000
    $ bitcoin-cli -rpcwallet=wallet.dat.with-pubkey fundrawtransaction 020000000001804a5d050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000 '{"includeWatching":true}'
    {
      "hex": "0200000001e1361fa3d96c58be1dabbc0ab551aa9e93b3742c169a442e8aa7e4fe87568ada0100000000feffffff02759298000000000016001447470cba8d0decaacc5e790afb65f4a48cd2119d804a5d050000000017a914022c8e671bef27b8b6ebea31d40608e0ba8444a78700000000",
      "changepos": 0,
      "fee": 0.00001035
    }

    I would like to be able to keep my public keys offline and still be able to use fundrawtransaction to create unsigned but funded raw transactions on the online machine.

  6. sipa commented at 3:03 AM on July 17, 2018: member

    I don't really understand why this should work. importaddress marks outputs as watchonly but unsolvable. fundrawtransaction needs solvable imports (pubkeys/scripts).

  7. dooglus commented at 3:43 AM on July 17, 2018: contributor

    Fair enough. I thought that when I first created this issue I was able to get fundrawtransaction to work without knowing the pubkey (using the commit I linked to here - but that was 2 years ago and I was probably using P2PKH addresses back then.

  8. sipa commented at 3:46 AM on July 17, 2018: member

    Ah I see; for P2PKH you can't solve without knowing the pubkey, but you can know ahead of time what the size of a scriptSog would be.

    I'm not sure we should bother with that.

  9. stevenroose commented at 2:14 PM on July 16, 2019: contributor

    I don't really understand why this should work. importaddress marks outputs as watchonly but unsolvable. fundrawtransaction needs solvable imports (pubkeys/scripts).

    So is there a way so mark an imported address as solvable?

    fundraw has the includeWatching flag, so what's the point of that if watched addresses are not considered?

  10. achow101 commented at 2:45 PM on July 16, 2019: member

    So is there a way so mark an imported address as solvable?

    fundraw has the includeWatching flag, so what's the point of that if watched addresses are not considered?

    You can't mark an imported address as solvable, there's no flag for that. Rather every output considered for coin selection goes through the solvability test which checks to see whether the wallet has enough information to construct the final input for that output if it knew what the private keys were. The whole point of this is to allow for fee estimation. If you don't know what needs to be in the inputs for a given output, you won't be able to know how big that input will be so you cannot reliably estimate the fee for the transaction. This then effects what coins you select because you need to know how much you will pay in fees for each input so that you can be sure that there are enough inputs to cover the outgoing amounts and the transaction fees.

  11. dooglus commented at 12:35 PM on July 17, 2019: contributor

    @stevenroose > what's the point of that if watched addresses are not considered?

    I'm guessing the point is that you can have a watchonly address that was imported using importpubkey instead of by importaddress, and those are considered by fundrawtransaction.

  12. sipa commented at 1:07 PM on July 17, 2019: member

    And on the other side, addresses watched by using importaddress (or non-solvable importmulti) can still work in a wallet that just needs to track incoming payments etc, but not participate in spending.

  13. stevenroose commented at 10:09 AM on July 19, 2019: contributor

    I agree just clarifying this in fundrawtransaction is sufficient. https://github.com/bitcoin/bitcoin/pull/16397

  14. laanwj referenced this in commit 79aeed8e76 on Sep 30, 2019
  15. MarcoFalke commented at 8:12 PM on September 30, 2019: member

    This has been fixed in 79aeed8e76e8bc70722e6178678b0b3840694d5c?

  16. MarcoFalke closed this on Sep 30, 2019

  17. sidhujag referenced this in commit 87f572d383 on Oct 2, 2019
  18. jasonbcox referenced this in commit b942902439 on Sep 7, 2020
  19. vijaydasmp referenced this in commit de90806b39 on Oct 29, 2021
  20. vijaydasmp referenced this in commit 109c46514d on Oct 29, 2021
  21. humbleDasher referenced this in commit 3d642e293b on Dec 5, 2021
  22. MarcoFalke locked this on Dec 16, 2021

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

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