|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.bitcoin.core.CheckpointManager
public class CheckpointManager
Vends hard-coded StoredBlocks for blocks throughout the chain. Checkpoints serve two purposes:
Checkpoints are used by the SPV BlockChain to initialize fresh
SPVBlockStores. They are not used by fully validating mode, which instead has a
different concept of checkpoints that are used to hard-code the validity of blocks that violate BIP30 (duplicate
coinbase transactions). Those "checkpoints" can be found in NetworkParameters.
The file format consists of the string "CHECKPOINTS 1", followed by a uint32 containing the number of signatures to read. The value may not be larger than 256 (so it could have been a byte but isn't for historical reasons). If the number of signatures is larger than zero, each 65 byte ECDSA secp256k1 signature then follows. The signatures sign the hash of all bytes that follow the last signature.
After the signatures come an int32 containing the number of checkpoints in the file. Then each checkpoint follows one after the other. A checkpoint is 12 bytes for the total work done field, 4 bytes for the height, 80 bytes for the block header and then 1 zero byte at the end (i.e. number of transactions in the block: always zero).
| Field Summary | |
|---|---|
protected TreeMap<Long,StoredBlock> |
checkpoints
|
protected Sha256Hash |
dataHash
|
protected NetworkParameters |
params
|
| Constructor Summary | |
|---|---|
CheckpointManager(NetworkParameters params,
InputStream inputStream)
|
|
| Method Summary | |
|---|---|
static void |
checkpoint(NetworkParameters params,
InputStream checkpoints,
BlockStore store,
long time)
Convenience method that creates a CheckpointManager, loads the given data, gets the checkpoint for the given time, then inserts it into the store and sets that to be the chain head. |
StoredBlock |
getCheckpointBefore(long time)
Returns a StoredBlock representing the last checkpoint before the given time, for example, normally
you would want to know the checkpoint before the earliest wallet birthday. |
Sha256Hash |
getDataHash()
Returns a hash of the concatenated checkpoint data. |
int |
numCheckpoints()
Returns the number of checkpoints that were loaded. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final TreeMap<Long,StoredBlock> checkpoints
protected final NetworkParameters params
protected final Sha256Hash dataHash
| Constructor Detail |
|---|
public CheckpointManager(NetworkParameters params,
InputStream inputStream)
throws IOException
IOException| Method Detail |
|---|
public StoredBlock getCheckpointBefore(long time)
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 int numCheckpoints()
public Sha256Hash getDataHash()
public static void checkpoint(NetworkParameters params,
InputStream checkpoints,
BlockStore store,
long time)
throws IOException,
BlockStoreException
Convenience method that creates a CheckpointManager, loads the given data, gets the checkpoint for the given 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.
IOException
BlockStoreException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||