Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: CIYAM on January 09, 2012, 08:45:37 AM



Title: When exactly does the client generates new keys?
Post by: CIYAM on January 09, 2012, 08:45:37 AM
Hi all,

Just wondering exactly when the standard client will generate new keys in your wallet. Will it do so only exactly when the last key in the key pool has been used or will it do it before that?

The reason for the question (and depending upon the answer the reason perhaps for a change request) is that I keep my wallet encrypted using external software which via a script I use to run the client decrypts and after the client finishes executing automatically re-encrypts the wallet (I am not using the Bitcoin wallet encryption).

My concern is that if the new keys are only generated when the pool is totally exhausted then if something terrible happens to my computer whilst the wallet is being re-encrypted then I could potentially lose BTC that was received via a newly generated key (this would not be a problem if new keys were generated whilst a number of "old keys" are still available to be used first).


Cheers,

Ian.


Title: Re: When exactly does the client generates new keys?
Post by: vuce on January 09, 2012, 10:27:19 AM
It will add one address for every one used, so there will always be 100 (by default) unused addresses. That is as far as I know.


Title: Re: When exactly does the client generates new keys?
Post by: mila on January 09, 2012, 12:20:46 PM
my best guess is that every time your client uses an address from the "100 addresses pool" it generates a new one.
also when you hit the button 'create new address' it will take an existing one from the pool, make it visible to you and creates a new one which is added to the pool but not to your eyes directly (is not visible in your address book). this way you have always a reserve list of addresses that will surface in the client gui on demand. and if you have to return to a backup wallet which is missing last transactions, you have pretty good chance to recover all your coins as they were send to yourself using the pool and/or if you received any bitcoins to any 'new' addresses, they were in fact already in that older backup sitting in the pool waiting for you to be 'generated'.

i hope some veteran user would comment if generate new address is the same as un-hide an address from pool and attach a new address at the pools end.

and that client generates new addresses for the pool as soon as any of them are used.


Title: Re: When exactly does the client generates new keys?
Post by: CIYAM on January 09, 2012, 12:24:19 PM
It will add one address for every one used, so there will always be 100 (by default) unused addresses. That is as far as I know.

Great - I think that means my wallet encryption approach is safe then (as I never run the client to do more than a small number of transactions at a time).


Title: Re: When exactly does the client generates new keys?
Post by: Pieter Wuille on January 09, 2012, 01:00:49 PM
i hope some veteran user would comment if generate new address is the same as un-hide an address from pool and attach a new address at the pools end.

This is correct, at least as long as the wallet is not locked.

If your wallet is encrypted, and not unlocked by the user (by providing the passphrase), any new key retrieved from the key pool will cause the generation of a fresh one.


Title: Re: When exactly does the client generates new keys?
Post by: tlhonmey on January 19, 2012, 07:15:29 PM
Strictly speaking it generates a new key any time the number of keys in the pool drops below the number it thinks it should have.  The default is 100, but you can adjust that with the -keypool parameter.  Personally I run it once with the keypool size set to 10,000, and then backup the wallet.  It makes your wallet about 70Mb, but you don't have to worry about the backup becoming obsolete for quite a while.  Key creations and the size of the pool are recorded in the debug.log file if you feel the need to check on its status.


Title: Re: When exactly does the client generates new keys?
Post by: DeathAndTaxes on January 19, 2012, 07:32:10 PM
It will add one address for every one used, so there will always be 100 (by default) unused addresses. That is as far as I know.

Great - I think that means my wallet encryption approach is safe then (as I never run the client to do more than a small number of transactions at a time).


For more safety you can increase the size of the keypool.  200 or 500 keys in keypool doesn't make the wallet much bigger (about 1 KB per key).

Just run client from command line w/ -keypool=xxx option (where xxx is desired size of keypool).  It does take a few seconds for it to generate a couple hundred keypairs so just let it run.  Once client loads if you will notice wallet.dat size has increased.