Pages:
Author

Topic: Help me understand how private keys work in wallet.dat (Read 1430 times)

legendary
Activity: 3514
Merit: 4895
- snip -
I forgot that if your wallet is encrypted the client will wai until the first time you unlock it (like sending coins) to expand the keypool.
- snip -
This is new behavior in 0.9.x right?
I think it has always been this way as it doesn't write unecrypted keys to an encrypted wallet.  Without the wallet passphrase that is what it would have to do in order to expand the keypool.

Duh.  I really didn't think that one through.  Thanks.
donator
Activity: 1218
Merit: 1079
Gerald Davis
- snip -
I forgot that if your wallet is encrypted the client will wai until the first time you unlock it (like sending coins) to expand the keypool.
- snip -

This is new behavior in 0.9.x right?

I think it has always been this way as it doesn't write unecrypted keys to an encrypted wallet.  Without the wallet passphrase that is what it would have to do in order to expand the keypool.
legendary
Activity: 3514
Merit: 4895
- snip -
I forgot that if your wallet is encrypted the client will wai until the first time you unlock it (like sending coins) to expand the keypool.
- snip -

This is new behavior in 0.9.x right?
donator
Activity: 1218
Merit: 1079
Gerald Davis
from the debug console type getinfo to get some stats including the number of keys currently in the keypool.  I forgot that if your wallet is encrypted the client will wai until the first time you unlock it (like sending coins) to expand the keypool.  You can force the wallet to unlock to generate the additional keys now.  You can do that from the debug console as well with walletpassphrase .  I would set time to remain unlocked to something like 600 seconds to ensure sufficient time to generate all the keys.   Once it completes you can lock the wallet early if neccessary with lockwallet IIRC (type help in debug console to verify exact command).
full member
Activity: 209
Merit: 100
I just opened Bitcoin Core in CMD with bitcoin-qt -keypool=10000. The time it took from launch to UI, with regard to the 10,000 key pool, wasn't noticable.

How do I verify that my wallet has 10,000 keys in its pool? Should I notice an increase in the my wallet filesize?

It should be noted that I opened Bitcoin Core with an existing wallet with roughly 0.16 BTC in it.

So did this expand my existing wallet's keypool to 10,000?
donator
Activity: 1218
Merit: 1079
Gerald Davis
If you plan on making a long-term backup, for the purpose of safeguard against data loss, after encrypting with a passphrase, you might consider starting Bitcoin once with a large keypool option such as bitcoin-qt -keypool=2000. This will fill the wallet with future keys that will keep your backup from becoming obsolete for a long time.
Good idea. Do I change it in the shortcut properties, or somewhere within the program itself?

Neither since you only need to set it once.  In windows the easiest way is probably use the command prompt and type the command exactly as shown above.  Once the keypool is set loading it in the future won't unset it so there is no need to add it to a shortcut.  Understand it can take a while to generate a large number of keys and there will be no progress indicated by the system so just be patient eventually once the keypool is expanded the client will load normally.

Quote
Another question: If I kept my wallet in cold storage, and I deposit more coins to a known address in that cold storage wallet, does that change the number of keys in use? How would that affect the existing unused keypool?

It wouldn't use a new address thus it won't change the number of available keys in the keypool.


full member
Activity: 209
Merit: 100
If you plan on making a long-term backup, for the purpose of safeguard against data loss, after encrypting with a passphrase, you might consider starting Bitcoin once with a large keypool option such as bitcoin-qt -keypool=2000. This will fill the wallet with future keys that will keep your backup from becoming obsolete for a long time.
Good idea. Do I change it in the shortcut properties, or somewhere within the program itself?

Another question: If I kept my wallet in cold storage, and I deposit more coins to a known address in that cold storage wallet, does that change the number of keys in use? How would that affect the existing unused keypool?
legendary
Activity: 1512
Merit: 1036
If you plan on making a long-term backup, for the purpose of safeguard against data loss, after encrypting with a passphrase, you might consider starting Bitcoin once with a large keypool option such as bitcoin-qt -keypool=2000. This will fill the wallet with future keys that will keep your backup from becoming obsolete for a long time.
legendary
Activity: 4522
Merit: 3426
With the keypool queuing 100 unused private keys after every transaction, does this mean that a wallet will grow in size (because of used private/public keypairs) after every transaction?
...

Is this correct?

That is correct.
full member
Activity: 209
Merit: 100
With the keypool queuing 100 unused private keys after every transaction, does this mean that a wallet will grow in size (because of used private/public keypairs) after every transaction?

One wallet example:

1. Received BTC (Generated new request code)
Wallet total: 1 Pub - 1 Priv - 100 unused Priv

2. Spent BTC
Wallet total: 2 Pub - 2 Priv - 100 unused Priv

3.  Received BTC (Generated new request code)
Wallet total: 3 Pub - 3 Priv - 100 unused Priv

4. Spent BTC
Wallet total: 4 Pub - 4 Priv - 100 unused Priv

... and so on...

Is this correct?
donator
Activity: 1218
Merit: 1079
Gerald Davis
They client doesn't wait until the keypool is exhausted before refreshing.  It refreshes the keypool whenever possible if the current size is less than the preset seize. 

If the wallet is not encrypted the keypool refreshes each time a new key is used.
If the wallet is locked (encrypted) the client will refresh the keypool the next time the wallet is unlocked.  
This means in situations where the wallet is not routinely unlocked (like a server watching wallet) they keypool will eventually be exhausted.  

You can get the current size of the keypool by the rpc command getinfo.

Eventually the Bitcoin-core wallet will probably use deterministic wallets making the concept of a keypool obsolete.

hero member
Activity: 820
Merit: 1000
If you use a deterministic wallet such as electrum then you don't need to worry about how many keys you've used.  It will keep track of as many as you want using a seed phrase.  Just write down that phrase and it's all you need.

Exactly.

And just a side note, you could set the keypool size to whatever you want with "-keypool=".
So, if you don't want to make backup so "frequently", you could use the argument to set a larger keypool.
cp1
hero member
Activity: 616
Merit: 500
Stop using branwallets
If you use a deterministic wallet such as electrum then you don't need to worry about how many keys you've used.  It will keep track of as many as you want using a seed phrase.  Just write down that phrase and it's all you need.
legendary
Activity: 1918
Merit: 1018
It is still a bit complicated to safely keep bitcoins on your computer long term
sr. member
Activity: 294
Merit: 250
Is this something that a "normal" user needs to know, or is this more advanced stuff?
And why would you need 100 unused keys when it generates a new one when you need it anyway?

A "normal" user of the Bitcoin-Qt (or Bitcoin Core) wallet needs to know that they have to backup their wallet regularly.

Otherwise, they will lose all their bitcoins if their hard drive crashes (or their computer is stolen, burns in a fire, or is destroyed in a flood, tornado, or earthquake).

Since "regularly" can mean different things to different people, it would be good for a "normal" user of the Bitcoin-Qt (or Bitcoin Core) wallet to keep track of how many new addresses they've used (including change addresses) and backup their wallet every 25 addresses or so. Then keep the most recent 3 backups in 3 separate secure locations.

If you don't ever store enough bitcoins to care whether they are permanently lost, then the backups are not important.
Okay, that cleared it up pretty good. Thank you! Smiley
legendary
Activity: 3514
Merit: 4895
Is this something that a "normal" user needs to know, or is this more advanced stuff?
And why would you need 100 unused keys when it generates a new one when you need it anyway?

A "normal" user of the Bitcoin-Qt (or Bitcoin Core) wallet needs to know that they have to backup their wallet regularly.

Otherwise, they will lose all their bitcoins if their hard drive crashes (or their computer is stolen, burns in a fire, or is destroyed in a flood, tornado, or earthquake).

Since "regularly" can mean different things to different people, it would be good for a "normal" user of the Bitcoin-Qt (or Bitcoin Core) wallet to keep track of how many new addresses they've used (including change addresses) and backup their wallet every 25 addresses or so. Then keep the most recent 3 backups in 3 separate secure locations.

If you don't ever store enough bitcoins to care whether they are permanently lost, then the backups are not important.
cp1
hero member
Activity: 616
Merit: 500
Stop using branwallets
Is this something that a "normal" user needs to know, or is this more advanced stuff?
And why would you need 100 unused keys when it generates a new one when you need it anyway?

You'd have to back it up every transaction otherwise.
sr. member
Activity: 294
Merit: 250
Is this something that a "normal" user needs to know, or is this more advanced stuff?
And why would you need 100 unused keys when it generates a new one when you need it anyway?
Pages:
Jump to: