use of tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs in project teku by ConsenSys.
the class KvStoreDatabase method storeInitialAnchor.
@Override
public void storeInitialAnchor(final AnchorPoint anchor) {
try (final HotUpdater hotUpdater = hotDao.hotUpdater();
final FinalizedUpdater finalizedUpdater = finalizedDao.finalizedUpdater()) {
// We should only have a single block / state / checkpoint at anchorpoint initialization
final Checkpoint anchorCheckpoint = anchor.getCheckpoint();
final Bytes32 anchorRoot = anchorCheckpoint.getRoot();
final BeaconState anchorState = anchor.getState();
final Optional<SignedBeaconBlock> anchorBlock = anchor.getSignedBeaconBlock();
hotUpdater.setAnchor(anchor.getCheckpoint());
hotUpdater.setGenesisTime(anchorState.getGenesis_time());
hotUpdater.setJustifiedCheckpoint(anchorCheckpoint);
hotUpdater.setBestJustifiedCheckpoint(anchorCheckpoint);
hotUpdater.setFinalizedCheckpoint(anchorCheckpoint);
hotUpdater.setLatestFinalizedState(anchorState);
// We need to store the anchor block in both hot and cold storage so that on restart
// we're guaranteed to have at least one block / state to load into RecentChainData.
anchorBlock.ifPresent(block -> {
// Save to hot storage
hotUpdater.addHotBlock(new BlockAndCheckpointEpochs(block, new CheckpointEpochs(anchorState.getCurrent_justified_checkpoint().getEpoch(), anchorState.getFinalized_checkpoint().getEpoch())));
// Save to cold storage
finalizedUpdater.addFinalizedBlock(block);
});
putFinalizedState(finalizedUpdater, anchorRoot, anchorState);
finalizedUpdater.commit();
hotUpdater.commit();
}
}
use of tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs in project teku by ConsenSys.
the class CheckpointEpochsSerializer method deserialize.
@Override
public CheckpointEpochs deserialize(final byte[] data) {
return SSZ.decode(Bytes.of(data), reader -> {
final UInt64 justifiedEpoch = UInt64.fromLongBits(reader.readUInt64());
final UInt64 finalizedEpoch = UInt64.fromLongBits(reader.readUInt64());
return new CheckpointEpochs(justifiedEpoch, finalizedEpoch);
});
}
use of tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs in project teku by ConsenSys.
the class AbstractStoreTest method createGenesisStore.
protected UpdatableStore createGenesisStore(final StoreConfig pruningOptions) {
final SignedBlockAndState genesis = chainBuilder.generateGenesis();
final Checkpoint genesisCheckpoint = chainBuilder.getCurrentCheckpointForEpoch(0);
return StoreBuilder.create().asyncRunner(SYNC_RUNNER).metricsSystem(new StubMetricsSystem()).specProvider(spec).blockProvider(blockProviderFromChainBuilder()).stateProvider(StateAndBlockSummaryProvider.NOOP).anchor(Optional.empty()).genesisTime(genesis.getState().getGenesis_time()).time(genesis.getState().getGenesis_time()).latestFinalized(AnchorPoint.create(spec, genesisCheckpoint, genesis)).justifiedCheckpoint(genesisCheckpoint).bestJustifiedCheckpoint(genesisCheckpoint).blockInformation(Map.of(genesis.getRoot(), new StoredBlockMetadata(genesis.getSlot(), genesis.getRoot(), genesis.getParentRoot(), genesis.getStateRoot(), genesis.getExecutionBlockHash(), Optional.of(new CheckpointEpochs(UInt64.ZERO, UInt64.ZERO))))).storeConfig(pruningOptions).votes(emptyMap()).build();
}
use of tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs in project teku by ConsenSys.
the class CheckpointEpochsSerializerTest method shouldRoundTripCheckpointEpochs.
@Test
void shouldRoundTripCheckpointEpochs() {
final byte[] data = CHECKPOINT_EPOCHS_SERIALIZER.serialize(VALUE);
final CheckpointEpochs result = CHECKPOINT_EPOCHS_SERIALIZER.deserialize(data);
assertThat(result).isEqualTo(VALUE);
}
use of tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs in project teku by ConsenSys.
the class StoreBuilder method forkChoiceStoreBuilder.
public static StoreBuilder forkChoiceStoreBuilder(final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final Spec spec, final BlockProvider blockProvider, final StateAndBlockSummaryProvider stateAndBlockProvider, final AnchorPoint anchor, final UInt64 currentTime) {
final UInt64 genesisTime = anchor.getState().getGenesis_time();
final UInt64 slot = anchor.getState().getSlot();
final UInt64 time = genesisTime.plus(slot.times(spec.getSecondsPerSlot(slot))).max(currentTime);
Map<Bytes32, StoredBlockMetadata> blockInfo = new HashMap<>();
blockInfo.put(anchor.getRoot(), new StoredBlockMetadata(slot, anchor.getRoot(), anchor.getParentRoot(), anchor.getState().hashTreeRoot(), anchor.getExecutionBlockHash(), Optional.of(new CheckpointEpochs(anchor.getCheckpoint().getEpoch(), anchor.getCheckpoint().getEpoch()))));
return create().asyncRunner(asyncRunner).metricsSystem(metricsSystem).specProvider(spec).blockProvider(blockProvider).stateProvider(stateAndBlockProvider).anchor(anchor.getCheckpoint()).time(time).genesisTime(genesisTime).latestFinalized(anchor).justifiedCheckpoint(anchor.getCheckpoint()).bestJustifiedCheckpoint(anchor.getCheckpoint()).blockInformation(blockInfo).votes(new HashMap<>());
}
Aggregations