3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-14 19:25:51 +00:00

wallet-tool: Use checkpoints to speed up the blockchain sync.

This commit is contained in:
Andreas Schildbach 2016-03-05 00:49:03 +01:00
parent b6975a2760
commit 814bad4efb

View File

@ -1176,14 +1176,26 @@ public class WalletTool {
private static void setup() throws BlockStoreException {
if (store != null) return; // Already done.
// Will create a fresh chain if one doesn't exist or there is an issue with this one.
if (!chainFileName.exists() && wallet.getTransactions(true).size() > 0) {
boolean reset = !chainFileName.exists();
if (reset) {
// No chain, so reset the wallet as we will be downloading from scratch.
System.out.println("Chain file is missing so clearing transactions from the wallet.");
System.out.println("Chain file is missing so resetting the wallet.");
reset();
}
if (mode == ValidationMode.SPV) {
store = new SPVBlockStore(params, chainFileName);
chain = new BlockChain(params, wallet, store);
if (reset) {
try {
CheckpointManager.checkpoint(params, CheckpointManager.openStream(params), store,
wallet.getEarliestKeyCreationTime());
StoredBlock head = store.getChainHead();
System.out.println("Skipped to checkpoint " + head.getHeight() + " at "
+ Utils.dateTimeFormat(head.getHeader().getTimeSeconds() * 1000));
} catch (IOException x) {
System.out.println("Could not load checkpoints: " + x.getMessage());
}
}
} else if (mode == ValidationMode.FULL) {
FullPrunedBlockStore s = new H2FullPrunedBlockStore(params, chainFileName.getAbsolutePath(), 5000);
store = s;