Skip to content

Commit

Permalink
CheckpointManager, BuildCheckpoints: support checkpoints with 32 byte…
Browse files Browse the repository at this point in the history
… chain work

* `BuildCheckpoints` now always creates checkpoints with 32 byte chain work
* `CheckpointManager` knows how to read both 12 and 32 byte chain work

Also updates the bundle checkpoints to the new format.
  • Loading branch information
schildbach committed Jun 27, 2024
1 parent b4a4137 commit 4149536
Show file tree
Hide file tree
Showing 5 changed files with 1,929 additions and 1,927 deletions.
14 changes: 8 additions & 6 deletions core/src/main/java/org/bitcoinj/core/CheckpointManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,17 @@ private Sha256Hash readTextual(InputStream inputStream) throws IOException {
checkState(numCheckpoints > 0);
// Hash numCheckpoints in a way compatible to the binary format.
hasher.putBytes(ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(numCheckpoints).array());
final int size = StoredBlock.COMPACT_SERIALIZED_SIZE;
ByteBuffer buffer = ByteBuffer.allocate(size);
for (int i = 0; i < numCheckpoints; i++) {
byte[] bytes = BASE64.decode(reader.readLine());
hasher.putBytes(bytes);
((Buffer) buffer).position(0);
buffer.put(bytes);
((Buffer) buffer).position(0);
StoredBlock block = StoredBlock.deserializeCompact(buffer);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
StoredBlock block;
if (bytes.length == StoredBlock.COMPACT_SERIALIZED_SIZE)
block = StoredBlock.deserializeCompact(buffer);
else if (bytes.length == StoredBlock.COMPACT_SERIALIZED_SIZE_V2)
block = StoredBlock.deserializeCompactV2(buffer);
else
throw new IllegalStateException("unexpected length of checkpoint: " + bytes.length);
checkpoints.put(block.getHeader().time(), block);
}
HashCode hash = hasher.hash();
Expand Down
Loading

0 comments on commit 4149536

Please sign in to comment.