Bitcoin Forum
June 16, 2024, 08:28:16 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Help me understand how private keys work in wallet.dat  (Read 1364 times)
BusyBeaverHP (OP)
Full Member
***
Offline Offline

Activity: 209
Merit: 100


View Profile
April 22, 2014, 05:11:41 PM
 #1

I read that wallet.dat in Bitcoin Core has 100 private keys in it.

I also know that everytime you spend, a private key is used up by mechanics of sending and reallocation. For simple assumption, suppose that I've used my 99th private key, what would actually happen once the keypool refreshes itself?

Example: Suppose I have 2 BTC stored in a wallet.dat that already has 99 transactions, what would happen when the keypool refresh itself?
cp1
Hero Member
*****
Offline Offline

Activity: 616
Merit: 500


Stop using branwallets


View Profile
April 22, 2014, 05:13:02 PM
 #2

It keeps 100 unused keys.  So every time you use one it will generate another one.  You should back it up frequently.

Guide to armory offline install on USB key:  https://bitcointalk.org/index.php?topic=241730.0
DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4660



View Profile
April 22, 2014, 05:14:59 PM
 #3

I read that wallet.dat in Bitcoin Core has 100 private keys in it.

Starts with a default of 100 private keys.  Additional keys are generated as needed.

I also know that everytime you spend, a private key is used up by mechanics of sending and reallocation. For simple assumption, suppose that I've used my 99th private key, what would actually happen once the keypool refreshes itself?

Example: Suppose I have 2 BTC stored in a wallet.dat that already has 99 transactions, what would happen when the keypool refresh itself?

The keypool remains refreshed all the time.  It acts like a queue.  Each time the software needs a new address and private key (if you request a new receiving address, or if the software needs an address for the change from the transaction), it takes the next one from the front of the queue.  At the same time, it generates a new address and private key and adds it to the back of the queue.
odolvlobo
Legendary
*
Offline Offline

Activity: 4354
Merit: 3261



View Profile
April 22, 2014, 05:46:24 PM
 #4

It keeps 100 unused keys.  So every time you use one it will generate another one.  You should back it up frequently.

You don't need to back it up frequently. You only need to back it up as often as every 100 keys. One key is used every time you send bitcoins and one is used every time you allocate a new key to receive bitcoins.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4660



View Profile
April 22, 2014, 05:51:31 PM
 #5

It keeps 100 unused keys.  So every time you use one it will generate another one.  You should back it up frequently.

You don't need to back it up frequently.

I suppose that depends on how many transactions you are sending, how many receiving addresses you are generating, and what you mean when you say "frequently".

You only need to back it up as often as every 100 keys. One key is used every time you send bitcoins and one is used every time you allocate a new key to receive bitcoins.

While this is technically true, I tend to be concerned about the possibility that the most recent backup is unusable (for example, backing up a corrupted file before realizing that it is corrupted).

Instead, I prefer to back up every 25 keys, and keep the 3 most recent backups.  If you use a new address for every transaction (like you should), and you average 4 transactions per day, then backing up weekly would make sense.  Some people might use the word "frequent" to describe weekly backups.
blacksails
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250


View Profile
April 22, 2014, 06:52:31 PM
 #6

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?
cp1
Hero Member
*****
Offline Offline

Activity: 616
Merit: 500


Stop using branwallets


View Profile
April 22, 2014, 07:07:59 PM
 #7

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.

Guide to armory offline install on USB key:  https://bitcointalk.org/index.php?topic=241730.0
DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4660



View Profile
April 22, 2014, 07:11:51 PM
 #8

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.
blacksails
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250


View Profile
April 22, 2014, 07:36:45 PM
 #9

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
boumalo
Legendary
*
Offline Offline

Activity: 1904
Merit: 1018


View Profile WWW
April 22, 2014, 08:11:01 PM
 #10

It is still a bit complicated to safely keep bitcoins on your computer long term

cp1
Hero Member
*****
Offline Offline

Activity: 616
Merit: 500


Stop using branwallets


View Profile
April 22, 2014, 08:14:16 PM
 #11

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.

Guide to armory offline install on USB key:  https://bitcointalk.org/index.php?topic=241730.0
far9090
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
April 23, 2014, 09:57:35 AM
 #12

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0CDYQFjAB&url=https%3A%2F%2Fen.bitcoin.it%2Fwiki%2FHow_to_import_private_keys&ei=fo5XU-uiFYuP5ASBzoDABg&usg=AFQjCNEcOmZQ89bxEmtCKgfzlWTsIs7s9w&bvm=bv.65177938,d.bGE
Tammy Chan
Hero Member
*****
Offline Offline

Activity: 820
Merit: 1000



View Profile
April 23, 2014, 03:23:58 PM
 #13


This messy thing is indeed just https://en.bitcoin.it/wiki/How_to_import_private_keys, and it doesn't really help answering OP's question.

Tammy Chan
Hero Member
*****
Offline Offline

Activity: 820
Merit: 1000



View Profile
April 23, 2014, 03:26:20 PM
 #14

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=<n>".
So, if you don't want to make backup so "frequently", you could use the argument to set a larger keypool.

DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
April 23, 2014, 03:36:59 PM
 #15

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.

BusyBeaverHP (OP)
Full Member
***
Offline Offline

Activity: 209
Merit: 100


View Profile
April 24, 2014, 06:45:57 AM
 #16

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?
odolvlobo
Legendary
*
Offline Offline

Activity: 4354
Merit: 3261



View Profile
April 24, 2014, 03:29:26 PM
 #17

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.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1032



View Profile WWW
April 30, 2014, 06:40:32 AM
 #18

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.
BusyBeaverHP (OP)
Full Member
***
Offline Offline

Activity: 209
Merit: 100


View Profile
May 05, 2014, 11:36:21 PM
 #19

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?
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
May 06, 2014, 02:27:24 AM
 #20

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.


Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!