Skip to content

Import watch only pubkeys to the keypool if private keys are disabled#14075

Merged
meshcollider merged 5 commits intobitcoin:masterfrom
achow101:watch-only-keypool
Feb 14, 2019
Merged

Import watch only pubkeys to the keypool if private keys are disabled#14075
meshcollider merged 5 commits intobitcoin:masterfrom
achow101:watch-only-keypool

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Aug 26, 2018

If the wallet has private keys disabled, allow importing public keys into the keypool. A keypool option has been added to importmulti in order to signal that the keys should be added to the keypool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit "Fetch keys from keypool when private keys are disabled"

Could move test to a different commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit "Fetch keys from keypool when private keys are disabled"

Use named argument disable_private_keys=True?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit "Add option to importmulti add an imported pubkey to the keypool"

Default false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit "Add option to importmulti add an imported pubkey to the keypool"

... can be ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be renamed or called into from a new one.

WalletModel::KeypoolEmptyAndPrivkeysDisabled or something obnoxiously explicit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be time to make a TryToTopUpKeyPool function for when we will continue regardless. We do this in a number of places in the PR and probably elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TopUpKeypool actually already has this check in it so it won't do anything when the disable private keys flag is set. This is just an extra belt and suspenders check.

@achow101
Copy link
Member Author

Rebased. The first commit is still from #14019

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mu-nit: add commit for KeypoolCountInternalKeys

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's unnecssary.

@instagibbs
Copy link
Member

CWallet::CreateTransaction needs to check for keys in change keypool even if WALLET_FLAG_DISABLE_PRIVATE_KEYS is set.

@achow101 achow101 force-pushed the watch-only-keypool branch 2 times, most recently from 50cff8c to acb05a1 Compare August 30, 2018 14:31
@Sjors
Copy link
Member

Sjors commented Sep 13, 2018

Concept ACK. Lightly tested via your combined branch 3fa968e: I was able to import a bunch of receive and change keys. I was also able to receive coins on a bech32 address and send from it.

For some reason when I composed the transaction it picked change address with index 1 instead of with index 0. Is that an existing rule?

What I also found confusing, though I don't know if that's this PR, or the other two or just existing weirdness, is how dumpwallet shows p2sh-p2wpkh addresses under # addr, even though I launched bitcoind with -addresstype=bech32.

@achow101
Copy link
Member Author

For some reason when I composed the transaction it picked change address with index 1 instead of with index 0. Is that an existing rule?

Maybe your import command was weird? It should be adding them in the order of the import command so you should be getting them in that order too.

@Sjors
Copy link
Member

Sjors commented Oct 4, 2018

What's a good way to inspect the wallet / keypool?

@achow101
Copy link
Member Author

achow101 commented Oct 4, 2018

@Sjors You can use dumpwallet

@Sjors
Copy link
Member

Sjors commented Oct 5, 2018

@achow101 dumpwallet doesn't contain the bip32 derivation paths though.

I'll try with getaddressinfo.

@achow101
Copy link
Member Author

I will rework this to not require #14019 as soon as I have time (in a few days)

@DrahtBot DrahtBot mentioned this pull request Oct 20, 2018
@instagibbs
Copy link
Member

Good news: I'm wrong, and I'm the one who wrote the logic originally :(

Test and I'm happy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./test/functional/wallet_importmulti.py:730:35: F821 undefined name 'xpub'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops

@Sjors
Copy link
Member

Sjors commented Feb 14, 2019

@instagibbs keys from a ranged descriptor are imported in order. Feel free to replace this test:

        # Test importing of a ranged descriptor without keys, check order
        self.log.info("Should import the ranged descriptor with specified range as solvable")
        self.test_importmulti({"desc": desc,
                               "timestamp": "now",
                               "range": {"end": 9}},
                              success=True,
                              warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
        # Check the first two addresses:
        for address in addresses:
            test_address(self.nodes[1],
                         key.p2sh_p2wpkh_addr,
                         solvable=True)

        # Check keys were imported in the correct order:
        for i in range(10):
            address = self.nodes[1].getnewaddress()
            assert_equal(self.nodes[1].getaddressinfo(address)["hdkeypath"], "m/0'/0'/%s'" % i)

@instagibbs
Copy link
Member

Test fix only change.

reACK 32fd3bb

@instagibbs
Copy link
Member

re-ACK 38fbc10

Ordering test fixed, at least locally.

@Sjors
Copy link
Member

Sjors commented Feb 14, 2019

utACK a6e2c3331023d11112f8e9d176aa823d84b3f5ce (only adds a test since my last ACK)

@meshcollider
Copy link
Contributor

utACK 38fbc10

Introduces AddKeypoolPubkey in order to add a pubkey to the keypool
When private keys are disabled, still fetch keys from the keypool
if the keypool has keys. Those keys come from importing them and
adding them to the keypool.
Adds a new option to importmulti where the pubkeys specified in the import
object can be added to the keypool. This only works if the wallet has
private keys disabled.
Do public key imports in the order that they are specified in the import
or in the descriptor range.
@meshcollider
Copy link
Contributor

LGTM f4b00b7

@meshcollider meshcollider merged commit f4b00b7 into bitcoin:master Feb 14, 2019
@Sjors
Copy link
Member

Sjors commented Feb 15, 2019

Post merge utACK f4b00b7

laanwj added a commit that referenced this pull request Feb 17, 2019
…ption

a607c9a [Doc] importmulti: add missing description of keypool option (David A. Harding)

Pull request description:

  Option was added in #14075 but not documented there.

  CC: @achow101

Tree-SHA512: dcb6421fa1be3d733d7a00c1b57ffd591fe76c02d1c479e729089c118bec52f53bd7ebdb5454b3b1c7603ab189e91682a688b673a7f6b04fa8610c4249711217
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 4, 2020
Summary:
 * Add a method to add a pubkey to the keypool

Introduces AddKeypoolPubkey in order to add a pubkey to the keypool

 * Fetch keys from keypool when private keys are disabled

When private keys are disabled, still fetch keys from the keypool
if the keypool has keys. Those keys come from importing them and
adding them to the keypool.

 * Add option to importmulti add an imported pubkey to the keypool

Adds a new option to importmulti where the pubkeys specified in the import
object can be added to the keypool. This only works if the wallet has
private keys disabled.

 * Test pubkey import to keypool

 * Import public keys in order

Do public key imports in the order that they are specified in the import
or in the descriptor range.

This is a backport of Core [[bitcoin/bitcoin#14075 | PR14075]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D6366
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants