Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: jerfelix on June 15, 2011, 11:55:52 AM



Title: Lost a Bitcoin? I found one.
Post by: jerfelix on June 15, 2011, 11:55:52 AM
If you've been messing with your wallet.dat file, and "lose" a bitcoin in the process, this tip might help you out.  (This is probably old news for the long timers, but I think this might benefit someone!)

If you start bitcoin with the -rescan option, the block chain is rescanned looking for any bitcoin transactions that pertain to your current wallet.  So make sure you try that!


Here's what I did to lose, and subsequently find, a bitcoin.

 1. I've been running my client program, where I have say 50 Bitcoins.
 2. I ended my client program
 3. I backed up my wallet.dat file, and then renamed it to wallet_50btc.dat
 4. Start the client program, and generate a fresh new wallet with a new wallet ID, new private keys, etc. 
 5. Copy my new Bitcoin Address to notepad
 6. Terminate the client program
 7. Rename wallet.dat to wallet_0btc.dat
 8. Rename wallet_50.dat to wallet.dat
 9. Start the client program.  All looks good, I have 50 Bitcoins.
 10. Pay 1 BTC to my new Bitcoin Address that I had copied to notepad.
 11. Wait for at least 1 confirmation.  (I wanted to make sure that I got my change!). Now my balance is 1 less, i.e. 49 BTC.
 12. Terminate the client program.
 13. Rename wallet.dat to wallet_49btc.dat
 14. Rename wallet_0btc.dat to wallet.dat
 15. Start the client.  The wallet is empty.  Where'd the 1 BTC go?

 (The answer is that it's in a block that was already received and processed (in step 11), and so Bitcoin isn't going to process it again, unless instructed to.  They aren't really lost, they're hidden in the Block Chain, and your client program isn't going to go look for them, unless you tell it to.  The client program thinks it has already processed all those old blocks.)

 To re-find the lost coin:
 16. terminate the client.
 17. run the client with -rescan option.  After processing all the blocks, the 1 BTC shows up in the client.

Hopefully this helps someone find some lost Bitcoins.  If so, I'll gladly accept a cut!
Reference: https://en.bitcoin.it/wiki/Running_Bitcoin



Title: Re: Lost a Bitcoin? I found one.
Post by: elements on June 15, 2011, 12:14:08 PM
How do you do that, if you use the bitcoin client for Max OSX?

Where can one enter the "-rescan" command?

Thanx


Title: Re: Lost a Bitcoin? I found one.
Post by: cbeast on June 15, 2011, 01:09:51 PM
How do you do that, if you use the bitcoin client for Max OSX?

Where can one enter the "-rescan" command?

Thanx

Mac OSX    $HOME/Library/Application Support/Bitcoin/    /Users/username/Library/Application Support/Bitcoin/bitcoin.conf

https://en.bitcoin.it/wiki/Running_Bitcoin#Mac


Title: Re: Lost a Bitcoin? I found one.
Post by: clonedone on June 15, 2011, 01:32:35 PM
cool nice tip!
i would have panicked if that happened to me lol


Title: Re: Lost a Bitcoin? I found one.
Post by: joan on June 15, 2011, 01:41:08 PM
(The answer is that it's in a block that was already received and processed (in step 11), and so Bitcoin isn't going to process it again, unless instructed to.  They aren't really lost, they're hidden in the Block Chain, and your client program isn't going to go look for them, unless you tell it to.  The client program thinks it has already processed all those old blocks.)

It is the 3rd time I see this reported, so the issue is probably real. I say issue because as far as I can see, there is actually code in the client to automatically rescan the few blocks that the wallet is not aware of that are already in the local blockchain.
(init.cpp (https://github.com/bitcoin/bitcoin/blob/master/src/init.cpp#L386))

The wallet file keeps track of the last block it has synchronized with.
When I try this experiment with a single wallet and an older copy of this wallet, the rescan of the few new blocks is automatic.


Title: Re: Lost a Bitcoin? I found one.
Post by: lemonginger on June 15, 2011, 02:35:36 PM
How do you do that, if you use the bitcoin client for Max OSX?

Where can one enter the "-rescan" command?

Thanx

Mac OSX    $HOME/Library/Application Support/Bitcoin/    /Users/username/Library/Application Support/Bitcoin/bitcoin.conf

https://en.bitcoin.it/wiki/Running_Bitcoin#Mac

Well let's see, you linked to the incorrect directory (unless you want to edit that config file so it always runs with rescan and an empty wiki. We can do better :) )

Instead of using the application icon, you need to actually go inside of it and run it from the terminal so you can enter a command line argument.

1) Open a terminal
2) Go to Applications/Bitcoin.app/Contents/MacOS/

(if you didn't know that you could step into apps, now you do)

3) now type ./bitcoin -rescan

Bitcoin should open up and rescan the block chain for your transactions



Title: Re: Lost a Bitcoin? I found one.
Post by: dacoinminster on June 15, 2011, 03:06:03 PM
If you've been messing with your wallet.dat file, and "lose" a bitcoin in the process, this tip might help you out.  (This is probably old news for the long timers, but I think this might benefit someone!)

If you start bitcoin with the -rescan option, the block chain is rescanned looking for any bitcoin transactions that pertain to your current wallet.  So make sure you try that!


Here's what I did to lose, and subsequently find, a bitcoin.

 1. I've been running my client program, where I have say 50 Bitcoins.
 2. I ended my client program
 3. I backed up my wallet.dat file, and then renamed it to wallet_50btc.dat
 4. Start the client program, and generate a fresh new wallet with a new wallet ID, new private keys, etc. 
 5. Copy my new Bitcoin Address to notepad
 6. Terminate the client program
 7. Rename wallet.dat to wallet_0btc.dat
 8. Rename wallet_50.dat to wallet.dat
 9. Start the client program.  All looks good, I have 50 Bitcoins.
 10. Pay 1 BTC to my new Bitcoin Address that I had copied to notepad.
 11. Wait for at least 1 confirmation.  (I wanted to make sure that I got my change!). Now my balance is 1 less, i.e. 49 BTC.
 12. Terminate the client program.
 13. Rename wallet.dat to wallet_49btc.dat
 14. Rename wallet_0btc.dat to wallet.dat
 15. Start the client.  The wallet is empty.  Where'd the 1 BTC go?

 (The answer is that it's in a block that was already received and processed (in step 11), and so Bitcoin isn't going to process it again, unless instructed to.  They aren't really lost, they're hidden in the Block Chain, and your client program isn't going to go look for them, unless you tell it to.  The client program thinks it has already processed all those old blocks.)

 To re-find the lost coin:
 16. terminate the client.
 17. run the client with -rescan option.  After processing all the blocks, the 1 BTC shows up in the client.

Hopefully this helps someone find some lost Bitcoins.  If so, I'll gladly accept a cut!
Reference: https://en.bitcoin.it/wiki/Running_Bitcoin



Thanks for posting this info. I sent you a small tip for being awesome and helping out the community.


Title: Re: Lost a Bitcoin? I found one.
Post by: jerfelix on June 15, 2011, 03:42:52 PM
(The answer is that it's in a block that was already received and processed (in step 11), and so Bitcoin isn't going to process it again, unless instructed to.  They aren't really lost, they're hidden in the Block Chain, and your client program isn't going to go look for them, unless you tell it to.  The client program thinks it has already processed all those old blocks.)

It is the 3rd time I see this reported, so the issue is probably real. I say issue because as far as I can see, there is actually code in the client to automatically rescan the few blocks that the wallet is not aware of that are already in the local blockchain.
(init.cpp (https://github.com/bitcoin/bitcoin/blob/master/src/init.cpp#L386))

The wallet file keeps track of the last block it has synchronized with.
When I try this experiment with a single wallet and an older copy of this wallet, the rescan of the few new blocks is automatic.

@Joan-
Hmm, boy, you are right.  The code seems to be there.  Here it is, along with my notes in bold:


    CBlockIndex *pindexRescan = pindexBest;                  # Set two values to be EQUAL
    if (GetBoolArg("-rescan"))
        pindexRescan = pindexGenesisBlock;
    else
    {
        CWalletDB walletdb;
        CBlockLocator locator;
        if (walletdb.ReadBestBlock(locator))                      # Some conditional *
            pindexRescan = locator.GetBlockIndex();            # Conditionally set one of the values to something else
    }
    if (pindexBest != pindexRescan)                                # Check to see if the two values are EQUAL
    {
        printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
        nStart = GetTimeMillis();
        ScanForWalletTransactions(pindexRescan);
        printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
    }


So, my deductive skills tell me that the conditional marked with a "*" is not True for me. 
In other words, walletdb.ReadBestBlock(locator) is False when you are using a new wallet.
And it's true when you use an old used wallet (as you did in your experiment).

This is just a guess.  What do you think?  I'm all for squashing bugs when it comes to our money!


Thanks for posting this info. I sent you a small tip for being awesome and helping out the community.
THANK YOU dacoinminster!


Title: Re: Lost a Bitcoin? I found one.
Post by: Ricochet on June 15, 2011, 05:41:29 PM
I experienced the exact same thing when creating my "Savings account" wallet the other night, fixed with the -rescan option.  Definitely a bug in the "check if I need to rescan" code.  Thanks!


Title: Re: Lost a Bitcoin? I found one.
Post by: Maged on June 15, 2011, 06:11:19 PM
This is just a guess.  What do you think?  I'm all for squashing bugs when it comes to our money!
You were running 0.3.23, right?


Title: Re: Lost a Bitcoin? I found one.
Post by: jerfelix on June 15, 2011, 06:36:42 PM
This is just a guess.  What do you think?  I'm all for squashing bugs when it comes to our money!
You were running 0.3.23, right?
OK, I lied a little in my description of how it occurred, in the interest of simplification.  I actually created the wallet.dat file on LinuxCoin, using the version of Bitcoin that's on their 0.2a release.  Given that it came out on May 6, I don't think that my wallet.dat file was created on 0.3.23 of Bitcoin.

However, the rest of my story is pretty accurate, and the software that I tried loading the wallet.dat file onto was 0.3.23.  Well, it was downloaded today (as the latest release), so I am pretty certain that's the version number, although I am not in a position to check.