Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fundrawtransaction fails to add watchonly addresses imported with importaddress #7879

Closed
dooglus opened this issue Apr 15, 2016 · 12 comments
Closed

Comments

@dooglus
Copy link
Contributor

dooglus commented Apr 15, 2016

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.

@dooglus
Copy link
Contributor Author

dooglus commented Apr 16, 2016

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: dooglus@0b29c31

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.

@maflcko
Copy link
Member

maflcko commented Jul 16, 2018

@dooglus Is this still an issue?

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

@dooglus
Copy link
Contributor Author

dooglus commented Jul 17, 2018

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

@sipa
Copy link
Member

sipa commented Jul 17, 2018

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

@dooglus
Copy link
Contributor Author

dooglus commented Jul 17, 2018

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.

@sipa
Copy link
Member

sipa commented Jul 17, 2018

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.

@stevenroose
Copy link
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?

@achow101
Copy link
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.

@dooglus
Copy link
Contributor Author

dooglus commented Jul 17, 2019

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

@sipa
Copy link
Member

sipa commented Jul 17, 2019

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.

@stevenroose
Copy link
Contributor

I agree just clarifying this in fundrawtransaction is sufficient.
#16397

laanwj added a commit that referenced this issue Sep 30, 2019
8003104 Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve #16396, #7879 and #14405.

ACKs for top commit:
  Sjors:
    ACK 8003104. This will always be confusing, but at least it gives a bunch more clues for the user to google.

Tree-SHA512: 9b8002c259c50f93d89fc5574105aae6152858d8d45c07b4c3d5b7023adafe73c7a98a290874ff3fbbb7dfad2ac1bdf4acb8769a2a1c14e38484922f44e84e54
@maflcko
Copy link
Member

maflcko commented Sep 30, 2019

This has been fixed in 79aeed8?

@maflcko maflcko closed this as completed Sep 30, 2019
sidhujag pushed a commit to syscoin/syscoin that referenced this issue Oct 2, 2019
8003104 Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve bitcoin#16396, bitcoin#7879 and bitcoin#14405.

ACKs for top commit:
  Sjors:
    ACK 8003104. This will always be confusing, but at least it gives a bunch more clues for the user to google.

Tree-SHA512: 9b8002c259c50f93d89fc5574105aae6152858d8d45c07b4c3d5b7023adafe73c7a98a290874ff3fbbb7dfad2ac1bdf4acb8769a2a1c14e38484922f44e84e54
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this issue Sep 7, 2020
Summary:
Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve bitcoin/bitcoin#16396, bitcoin/bitcoin#7879 and bitcoin/bitcoin#14405.

---

Backport of Core [[bitcoin/bitcoin#16397 | PR16397]]

Test Plan:
  ninja
  bitcoin-cli -regtest help fundrawtransaction

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7381
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this issue Oct 29, 2021
8003104 Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve bitcoin#16396, bitcoin#7879 and bitcoin#14405.

ACKs for top commit:
  Sjors:
    ACK 8003104. This will always be confusing, but at least it gives a bunch more clues for the user to google.

Tree-SHA512: 9b8002c259c50f93d89fc5574105aae6152858d8d45c07b4c3d5b7023adafe73c7a98a290874ff3fbbb7dfad2ac1bdf4acb8769a2a1c14e38484922f44e84e54
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this issue Oct 29, 2021
8003104 Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve bitcoin#16396, bitcoin#7879 and bitcoin#14405.

ACKs for top commit:
  Sjors:
    ACK 8003104. This will always be confusing, but at least it gives a bunch more clues for the user to google.

Tree-SHA512: 9b8002c259c50f93d89fc5574105aae6152858d8d45c07b4c3d5b7023adafe73c7a98a290874ff3fbbb7dfad2ac1bdf4acb8769a2a1c14e38484922f44e84e54
humbleDasher pushed a commit to humbleDasher/dash that referenced this issue Dec 5, 2021
8003104 Clarify includeWatching for fundrawtransaction (Steven Roose)

Pull request description:

  Might be sufficient to solve bitcoin#16396, bitcoin#7879 and bitcoin#14405.

ACKs for top commit:
  Sjors:
    ACK 8003104. This will always be confusing, but at least it gives a bunch more clues for the user to google.

Tree-SHA512: 9b8002c259c50f93d89fc5574105aae6152858d8d45c07b4c3d5b7023adafe73c7a98a290874ff3fbbb7dfad2ac1bdf4acb8769a2a1c14e38484922f44e84e54
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants