Search in sources :

Example 1 with CheckpointEpochs

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();
    }
}
Also used : BlockAndCheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) FinalizedUpdater(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreFinalizedDao.FinalizedUpdater) BlockAndCheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs) CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) HotUpdater(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 2 with CheckpointEpochs

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);
    });
}
Also used : CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 3 with CheckpointEpochs

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();
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) StoredBlockMetadata(tech.pegasys.teku.ethereum.forkchoice.StoredBlockMetadata) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)

Example 4 with CheckpointEpochs

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);
}
Also used : CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) Test(org.junit.jupiter.api.Test)

Example 5 with CheckpointEpochs

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<>());
}
Also used : HashMap(java.util.HashMap) CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) StoredBlockMetadata(tech.pegasys.teku.ethereum.forkchoice.StoredBlockMetadata) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32)

Aggregations

CheckpointEpochs (tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 StoredBlockMetadata (tech.pegasys.teku.ethereum.forkchoice.StoredBlockMetadata)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)3 HashMap (java.util.HashMap)2 BlockAndCheckpointEpochs (tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Test (org.junit.jupiter.api.Test)1 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)1 ExecutionPayload (tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload)1 SlotAndExecutionPayload (tech.pegasys.teku.spec.datastructures.execution.SlotAndExecutionPayload)1 VoteTracker (tech.pegasys.teku.spec.datastructures.forkchoice.VoteTracker)1 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)1 FinalizedUpdater (tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreFinalizedDao.FinalizedUpdater)1 HotUpdater (tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater)1