diff --git a/core/src/main/java/org/bitcoinj/core/CheckpointManager.java b/core/src/main/java/org/bitcoinj/core/CheckpointManager.java index 07c50fb8b..93b840e51 100644 --- a/core/src/main/java/org/bitcoinj/core/CheckpointManager.java +++ b/core/src/main/java/org/bitcoinj/core/CheckpointManager.java @@ -76,7 +76,7 @@ public class CheckpointManager { private static final String TEXTUAL_MAGIC = "TXT CHECKPOINTS 1"; private static final int MAX_SIGNATURES = 256; - // Map of block header time to data. + // Map of block header time (in seconds) to data. protected final TreeMap checkpoints = new TreeMap<>(); protected final NetworkParameters params; @@ -192,11 +192,11 @@ public class CheckpointManager { * Returns a {@link StoredBlock} representing the last checkpoint before the given time, for example, normally * you would want to know the checkpoint before the earliest wallet birthday. */ - public StoredBlock getCheckpointBefore(long time) { + public StoredBlock getCheckpointBefore(long timeSecs) { try { - checkArgument(time > params.getGenesisBlock().getTimeSeconds()); + checkArgument(timeSecs > params.getGenesisBlock().getTimeSeconds()); // This is thread safe because the map never changes after creation. - Map.Entry entry = checkpoints.floorEntry(time); + Map.Entry entry = checkpoints.floorEntry(timeSecs); if (entry != null) return entry.getValue(); Block genesis = params.getGenesisBlock().cloneAsHeader(); return new StoredBlock(genesis, genesis.getWork(), 0); @@ -220,22 +220,23 @@ public class CheckpointManager { * time, then inserts it into the store and sets that to be the chain head. Useful when you have just created * a new store from scratch and want to use configure it all in one go.

* - *

Note that time is adjusted backwards by a week to account for possible clock drift in the block headers.

+ *

Note that timeSecs is adjusted backwards by a week to account for possible clock drift in the block headers.

*/ - public static void checkpoint(NetworkParameters params, InputStream checkpoints, BlockStore store, long time) + public static void checkpoint(NetworkParameters params, InputStream checkpoints, BlockStore store, long timeSecs) throws IOException, BlockStoreException { checkNotNull(params); checkNotNull(store); checkArgument(!(store instanceof FullPrunedBlockStore), "You cannot use checkpointing with a full store."); - time -= 86400 * 7; + timeSecs -= 60 * 60 * 24 * 7; // one week in seconds - checkArgument(time > 0); - log.info("Attempting to initialize a new block store with a checkpoint for time {} ({})", time, Utils.dateTimeFormat(time * 1000)); + checkArgument(timeSecs > 0); + log.info("Attempting to initialize a new block store with a checkpoint for time {} ({})", timeSecs, + Utils.dateTimeFormat(timeSecs * 1000)); BufferedInputStream stream = new BufferedInputStream(checkpoints); CheckpointManager manager = new CheckpointManager(params, stream); - StoredBlock checkpoint = manager.getCheckpointBefore(time); + StoredBlock checkpoint = manager.getCheckpointBefore(timeSecs); store.put(checkpoint); store.setChainHead(checkpoint); }