Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: jamoes on June 11, 2011, 06:52:23 AM



Title: [SOLVED]Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 06:52:23 AM
I seemed to have lost some bitcoins, only 0.01, so not really a big deal, but this scares me. I'd like to get a better understanding of exactly where I went wrong. Here's the steps I followed:

1. Closed my Bitcoin client.
2. Copied wallet.dat to wallet-savings.dat
3. Transferred 0.01 BTC from my BTC Guild account to an address from wallet.dat.
4. Copied wallet-savings.dat over wallet.dat.
5. Opened up my Bitcoin client, and waited until the transaction showed up. After the blockchain caught up, the transaction, and the 0.01 BTC were there.
6. Closed my bitcoin client, and copied wallet-savings.dat over wallet.dat.
7. Re-opened my bitcoin client - this time the transaction never showed up. It's been a few hours now, and the transaction still isn't there - I seem to have lost that 0.01 BTC forever.

Obviously, step 6 was where I went wrong. I should never have just overwritten my wallet.dat. However, I did it somewhat intentionally, since I figured that the transaction should show up again, and I wanted to test that hypothesis.

So, what happened? If restoring from backup in step 4 didn't mess anything up, why did it break when I overwrote it the second time?

Thanks for any help. I'd really like to understand this so I don't mess anything up when dealing with larger amount of bitcoins.


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: nazgulnarsil on June 11, 2011, 07:02:13 AM
explain what's getting copied more clearly.


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: FreeMoney on June 11, 2011, 07:09:32 AM
I don't get it. Shouldn't 6 have done nothing at all? What were you hoping to do?


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 07:09:53 AM
explain what's getting copied more clearly.

Step 2 was this command:
cp ~/Library/Application\ Support/Bitcoin/wallet.dat ~/Library/Application\ Support/Bitcoin/wallet-savings.dat

Step 4 was this command:
cp ~/Library/Application\ Support/Bitcoin/wallet-savings.dat ~/Library/Application\ Support/Bitcoin/wallet.dat

And Step 6 was also this command:
cp ~/Library/Application\ Support/Bitcoin/wallet-savings.dat ~/Library/Application\ Support/Bitcoin/wallet.dat


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 07:10:38 AM
I don't get it. Shouldn't 6 have done nothing at all? What were you hoping to do?

Yeah, exactly, Stop 6 shouldn't have done anything I thought. I was really surprised when I opened up the client and the transaction was gone.

edit: What is was hoping to do was experiment. I wanted to confirm that the transaction would indeed show up again.


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: Dude65535 on June 11, 2011, 07:49:49 AM
try bitcoin.exe -rescan and see if that helps.


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 07:58:49 AM
try bitcoin.exe -rescan and see if that helps.

I deleted the whole blockchain, and it's re-downloading now. I suspect -rescan would have had the same effect, but just been faster.

From what it sound like, this should bring back my transaction. I'll report back here when I have the results. Thanks for your help!


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 08:39:04 AM
Re-downloading the blockchain worked! (so did -rescan, which I tried from a different computer, and it was much faster).

I'd consider my experiment a success, since I now have a better understanding of how the bitcoin client actually finds transactions. Thanks for your help!


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: joan on June 11, 2011, 08:48:47 AM
From what I understand:
- The few transactions pertaining to addresses in your wallet (shown in the UI) are stored in the wallet.dat file itself.
- They are only stored when the block containing them is downloaded. Upon download, the block is parsed and wallet updated on the fly with the new TX.
- On step 5, your client download the block with the TX. Updates wallet.dat.
- On step 6, your re-erase the wallet with the old copy. But the block with the TX has already been downloaded and consolidated in blkindex.dat and blk0001.dat.
- The client doesn't realize that the wallet.dat doesn't know about the TX in blocks already downloaded. The UI only shows the TX history found in the old wallet.dat.
- The -rescan option allows the client to rescan the blocks and update the wallet.dat with transaction it's involved in.



Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: jamoes on June 11, 2011, 09:05:34 AM
From what I understand:
- The few transactions pertaining to addresses in your wallet (shown in the UI) are stored in the wallet.dat file itself.
- They are only stored when the block containing them is downloaded. Upon download, the block is parsed and wallet updated on the fly with the new TX.
- On step 5, your client download the block with the TX. Updates wallet.dat.
- On step 6, your re-erase the wallet with the old copy. But the block with the TX has already been downloaded and consolidated in blkindex.dat and blk0001.dat.
- The client doesn't realize that the wallet.dat doesn't know about the TX in blocks already downloaded. The UI only shows the TX history found in the old wallet.dat.
- The -rescan option allows the client to rescan the blocks and update the wallet.dat with transaction it's involved in.



This sounds exactly correct based on what I experienced. Thanks for the detailed explanation.

I think a good solution would be to have wallet.dat also store the most recent block that it has knowledge of, this way when the client boots up, it knows how many blocks need to be rescanned, and it can rescan those automatically (not that I'd expect the devs to actually implement this - just an idea off the top of my head). Either way, I'm just happy to have a better understanding, and happy that it's not so easy to lose bitcoins!


Title: Re: Lost some Bitcoins, what did I do wrong?
Post by: joan on June 11, 2011, 09:32:49 AM
I think a good solution would be to have wallet.dat also store the most recent block that it has knowledge of, this way when the client boots up, it knows how many blocks need to be rescanned, and it can rescan those automatically (not that I'd expect the devs to actually implement this - just an idea off the top of my head). Either way, I'm just happy to have a better understanding, and happy that it's not so easy to lose bitcoins!

Hmm, after reading the source a bit more, it looks like this behavior is implemented already. There is a "bestblock" entry in the wallet.dat, and upon client initialization, it is compared to the bestblock of the blkindex.dat. If the wallet is missing some, a partial rescan is triggered.
So in the end, it should have worked right away…