Bitcoin Forum

Bitcoin => BitcoinJ => Topic started by: jonas.schnelli on September 24, 2013, 08:12:14 AM



Title: understanding the checkpoints concept
Post by: jonas.schnelli on September 24, 2013, 08:12:14 AM
Hi

1)
I've played a bit with bitcoinj but still does not understand the concept of the checkpoint-file (i could also not found any docs about it).
Is anyone willing to explain that shortly?

2)
I also don't understand why my transactions "jump back" to "pending" confidence (= balance of 0 BTC) when i delete the .spvchain file (while leaving the .wallet file) and recreate/redownload the .spvchain.
Is there something like "recheck the .spvchain and rebuilt transactions in my current wallet"?

thanks
---
</jonas>


Title: Re: understanding the checkpoints concept
Post by: Mike Hearn on September 24, 2013, 12:52:00 PM
Docs here:

https://code.google.com/p/bitcoinj/wiki/SpeedingUpChainSync

When you delete the SPV chain file, at the moment the application is supposed to call wallet.clearTransactions(0). WalletAppKit does this for you. Replaying a wallet into an already full wallet will mess it up, but there aren't any assertions to catch that at the current time.


Title: Re: understanding the checkpoints concept
Post by: jonas.schnelli on September 24, 2013, 01:10:39 PM
Thanks for the doc link (overlooked that).

So you're saying, that i can't replace/exchange a .wallet file (even when i nicely close the app first), delete the .spvchain file and re-sync with the network?
Just to know: I don't have a use case for that, i just feel i need to understand that correct. :)

--
</jonas>


Title: Re: understanding the checkpoints concept
Post by: Mike Hearn on September 24, 2013, 01:16:43 PM
Sure you can. You just have some code like in WalletAppKit that does the following:

Code:
boolean chainFileExisted = chainFile.exists();
boolean shouldReplayWallet = vWalletFile.exists() && !chainFileExists;
BlockStore store = new SPVBlockStore(params, chainFile);

... later ....

                if (shouldReplayWallet)
                    wallet.clearTransactions(0);

Now when you start things up the wallet will contain only keys (and, uh, extension data, but that's a bug). The chain file will start at zero or wherever you checkpointed to (i.e. earliest key time), the wallet will have no transactions in it, and the replay will get you back in sync with the network.


Title: Re: understanding the checkpoints concept
Post by: jonas.schnelli on September 24, 2013, 02:39:15 PM
Code:
wallet.clearTransactions(0)
works just perfect.

Thanks!