public class StoredBlock extends Object implements Serializable
Block
object with extra data that can be derived from the block chain but is slow or inconvenient to
calculate. By storing it alongside the block header we reduce the amount of work required significantly.
Recalculation is slow because the fields are cumulative - to find the chainWork you have to iterate over every
block in the chain back to the genesis block, which involves lots of seeking/loading etc. So we just keep a
running total: it's a disk space vs cpu/io tradeoff.
StoredBlocks are put inside a BlockStore
which saves them to memory or disk.
Modifier and Type | Field and Description |
---|---|
static int |
CHAIN_WORK_BYTES |
static int |
COMPACT_SERIALIZED_SIZE |
static byte[] |
EMPTY_BYTES |
Constructor and Description |
---|
StoredBlock(Block header,
BigInteger chainWork,
int height) |
Modifier and Type | Method and Description |
---|---|
StoredBlock |
build(Block block)
Creates a new StoredBlock, calculating the additional fields by adding to the values in this block.
|
static StoredBlock |
deserializeCompact(NetworkParameters params,
ByteBuffer buffer)
De-serializes the stored block from a custom packed format.
|
boolean |
equals(Object o) |
BigInteger |
getChainWork()
The total sum of work done in this block, and all the blocks below it in the chain.
|
Block |
getHeader()
The block header this object wraps.
|
int |
getHeight()
Position in the chain for this block.
|
StoredBlock |
getPrev(BlockStore store)
Given a block store, looks up the previous block in this chain.
|
int |
hashCode() |
boolean |
moreWorkThan(StoredBlock other)
Returns true if this objects chainWork is higher than the others.
|
void |
serializeCompact(ByteBuffer buffer)
Serializes the stored block to a custom packed format.
|
String |
toString() |
public static final int CHAIN_WORK_BYTES
public static final byte[] EMPTY_BYTES
public static final int COMPACT_SERIALIZED_SIZE
public StoredBlock(Block header, BigInteger chainWork, int height)
public Block getHeader()
public BigInteger getChainWork()
public int getHeight()
public boolean moreWorkThan(StoredBlock other)
public StoredBlock build(Block block) throws VerificationException
VerificationException
public StoredBlock getPrev(BlockStore store) throws BlockStoreException
BlockStoreException
public void serializeCompact(ByteBuffer buffer)
CheckpointManager
.public static StoredBlock deserializeCompact(NetworkParameters params, ByteBuffer buffer) throws ProtocolException
CheckpointManager
.ProtocolException
Copyright © 2014. All rights reserved.