What is Nostr?
TracaChang
npub1e9n…tld9
2024-10-06 14:24:09

TracaChang on Nostr: What is the Keypool and how to deal with it? ---------------------------------------- ...

What is the Keypool and how to deal with it?

----------------------------------------

When you create a bitcoin wallet, it is by default an HD (Hierarchical Deterministic) wallet, and all of its keys and addresses are generated from a single source, so a single backup is enough to restore all of your funds. By default, the keypool is set to 1000, meaning that 1000 keys have been pre-generated and added to your wallet.

And you may be wondering... but what if I am a heavy bitcoin user (according to the offline setup of Bitcoin Core: https://primal.net/e/note1qystgp2xs2kref9dd9uvrzp8nwu0pdkr0upfxj35v3vjg83wumfqxefjud ) and, knowing that address reuse is bad, I receive funds to address 1001 according to your previous offline setup? Does that mean my offline wallet doesn't have the private key, so I can't access the funds?

Yes, your offline wallet does not contain the key, but as it is an HD wallet, we will simply refill the keypoll.

To test it, I edit bitcoin.conf with keypool=3, it generates a wallet with 3 addresses, when I type "listdescriptors" it shows range [0,2] and I import the descriptor into a watch only wallet.

With the watch only I create 4 receive addresses and I will check all addresses with the command:

getaddressinfo (and the address)

The first 3 addresses show that they belong to me:

"ismine": true,
"solvable": true,

But when I run "getaddressinfo" on the 4th address:

getaddressinfo bc1qqdpe3fq7vqza7z9zquc7fedp7jkgvjruskhlrn

We can see that this key is not in the wallet:

{
"address": "bc1qqdpe3fq7vqza7z9zquc7fedp7jkgvjruskhlrn",
"scriptPubKey": "0014034398a41e6005df08a20731e4e5a1f4ac86487c",
**"ismine": false,**
**"solvable": false,**
"iswatchonly": false,
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "034398a41e6005df08a20731e4e5a1f4ac86487c",
"ischange": false,
"labels": [
]
}

But do not panic! Just refill the keypool with "keypoolrefill" and the number of keys you want, in this example just 10:

keypoolrefill 10

and then I check it again:

getaddressinfo bc1qqdpe3fq7vqza7z9zquc7fedp7jkgvjruskhlrn

Now we can see "ismine": true

{
"address": "bc1qqdpe3fq7vqza7z9zquc7fedp7jkgvjruskhlrn",
"scriptPubKey": "0014034398a41e6005df08a20731e4e5a1f4ac86487c",
** "ismine": true,
"solvable": true,**
"desc": "wpkh([edd03c2d/84'/0'/0'/0/3]030297ae103edc4b156bc35d5b3c047ebcd6bca10ce8cf9e33ef90fe39918e7a7f)#mhhfrenc",
"parent_desc": "wpkh([edd03c2d/84'/0'/0']xpub6D4Xg4No2w9q8nwGGDPa2R1UruBtGrb7VsNBS394qg5bMdzibkcM1ziwN8J2Pc9rPA3c2QE6k23qt6cKioJgRMahN6AY6oAQDkqWgYYMnqb/0/*)#7nsk7kfc",
"iswatchonly": false,
"isscript": false,
"iswitness": true,
"witness_version": 0,
"witness_program": "034398a41e6005df08a20731e4e5a1f4ac86487c",
"pubkey": "030297ae103edc4b156bc35d5b3c047ebcd6bca10ce8cf9e33ef90fe39918e7a7f",
"ischange": true,
"timestamp": 1650271498,
"hdkeypath": "m/84'/0'/0'/0/3",
"hdseedid": "0000000000000000000000000000000000000000",
"hdmasterfingerprint": "edd03c2d",
"labels": [
]
}

Author Public Key
npub1e9n6ly0nldg0yjm4j036e03mkgqrkxy6znk9zmxm6mx604yy2j5qmhtld9