Search in sources :

Example 1 with ProtoArray

use of tech.pegasys.teku.ethereum.forkchoice.ProtoArray in project teku by ConsenSys.

the class Store method buildProtoArray.

private static ProtoArray buildProtoArray(final Spec spec, final Map<Bytes32, StoredBlockMetadata> blockInfoByRoot, final Optional<Checkpoint> initialCheckpoint, final Checkpoint justifiedCheckpoint, final AnchorPoint finalizedAnchor) {
    final List<StoredBlockMetadata> blocks = new ArrayList<>(blockInfoByRoot.values());
    blocks.sort(Comparator.comparing(StoredBlockMetadata::getBlockSlot));
    final ProtoArray protoArray = ProtoArray.builder().initialCheckpoint(initialCheckpoint).justifiedCheckpoint(justifiedCheckpoint).finalizedCheckpoint(finalizedAnchor.getCheckpoint()).build();
    for (StoredBlockMetadata block : blocks) {
        if (block.getCheckpointEpochs().isEmpty()) {
            throw new IllegalStateException("Incompatible database version detected. The data in this database is too old to be read by Teku. A re-sync will be required.");
        }
        protoArray.onBlock(block.getBlockSlot(), block.getBlockRoot(), block.getParentRoot(), block.getStateRoot(), block.getCheckpointEpochs().get().getJustifiedEpoch(), block.getCheckpointEpochs().get().getFinalizedEpoch(), block.getExecutionBlockHash().orElse(Bytes32.ZERO), spec.isBlockProcessorOptimistic(block.getBlockSlot()));
    }
    return protoArray;
}
Also used : ProtoArray(tech.pegasys.teku.ethereum.forkchoice.ProtoArray) ArrayList(java.util.ArrayList) StoredBlockMetadata(tech.pegasys.teku.ethereum.forkchoice.StoredBlockMetadata)

Aggregations

ArrayList (java.util.ArrayList)1 ProtoArray (tech.pegasys.teku.ethereum.forkchoice.ProtoArray)1 StoredBlockMetadata (tech.pegasys.teku.ethereum.forkchoice.StoredBlockMetadata)1