use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary in project teku by ConsenSys.
the class StoreTransactionUpdatesFactory method calculatePrunedHotBlockRoots.
private void calculatePrunedHotBlockRoots() {
final BeaconBlockSummary finalizedBlock = tx.getLatestFinalized().getBlockSummary();
baseStore.forkChoiceStrategy.processAllInOrder((blockRoot, slot, parentRoot) -> {
if (shouldPrune(finalizedBlock, blockRoot, slot, parentRoot)) {
prunedHotBlockRoots.add(blockRoot);
}
});
tx.blockAndStates.values().stream().sorted(Comparator.comparing(SignedBlockAndState::getSlot)).filter(newBlockAndState -> shouldPrune(finalizedBlock, newBlockAndState.getRoot(), newBlockAndState.getSlot(), newBlockAndState.getParentRoot())).forEach(newBlockAndState -> prunedHotBlockRoots.add(newBlockAndState.getRoot()));
}
use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary in project teku by ConsenSys.
the class HistoricalBatchFetcherTest method run_requestBatchWithSkippedSlots.
@Test
public void run_requestBatchWithSkippedSlots() {
final ChainBuilder chain = ChainBuilder.create(spec);
final int batchSize = 20;
final SignedBlockAndState genesis = chain.generateGenesis();
chain.generateBlockAtSlot(5);
chain.generateBlocksUpToSlot(10);
chain.generateBlockAtSlot(15);
chain.generateBlocksUpToSlot(30);
final SignedBeaconBlock latestBlock = chain.getBlockAtSlot(19);
final List<SignedBeaconBlock> targetBatch = chain.streamBlocksAndStates(0, latestBlock.getSlot().longValue()).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
peer = RespondingEth2Peer.create(spec, chain);
fetcher = new HistoricalBatchFetcher(storageUpdateChannel, signatureVerifier, chainDataClient, spec, peer, latestBlock.getSlot(), latestBlock.getRoot(), UInt64.valueOf(batchSize), maxRequests);
assertThat(peer.getOutstandingRequests()).isEqualTo(0);
final SafeFuture<BeaconBlockSummary> future = fetcher.run();
assertThat(peer.getOutstandingRequests()).isEqualTo(1);
peer.completePendingRequests();
assertThat(peer.getOutstandingRequests()).isEqualTo(0);
assertThat(future).isCompletedWithValue(genesis.getBlock());
verify(storageUpdateChannel).onFinalizedBlocks(blockCaptor.capture());
assertThat(blockCaptor.getValue()).containsExactlyElementsOf(targetBatch);
}
use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary in project teku by ConsenSys.
the class OperationsTestExecutor method processOperation.
private void processOperation(final TestDefinition testDefinition, final MutableBeaconState state, final OperationProcessor processor) throws Exception {
switch(operation) {
case ATTESTER_SLASHING:
final AttesterSlashing attesterSlashing = loadSsz(testDefinition, dataFileName, testDefinition.getSpec().getGenesisSchemaDefinitions().getAttesterSlashingSchema());
processor.processAttesterSlashing(state, attesterSlashing);
break;
case PROPOSER_SLASHING:
final ProposerSlashing proposerSlashing = loadSsz(testDefinition, dataFileName, ProposerSlashing.SSZ_SCHEMA);
processor.processProposerSlashing(state, proposerSlashing);
break;
case PROCESS_BLOCK_HEADER:
final BeaconBlockSummary blockHeader = loadSsz(testDefinition, dataFileName, testDefinition.getSpec().getGenesisSchemaDefinitions().getBeaconBlockSchema());
processor.processBlockHeader(state, blockHeader);
break;
case DEPOSIT:
final Deposit deposit = loadSsz(testDefinition, dataFileName, Deposit.SSZ_SCHEMA);
processor.processDeposit(state, deposit);
break;
case VOLUNTARY_EXIT:
final SignedVoluntaryExit voluntaryExit = loadSsz(testDefinition, dataFileName, SignedVoluntaryExit.SSZ_SCHEMA);
processor.processVoluntaryExit(state, voluntaryExit);
break;
case ATTESTATION:
final Attestation attestation = loadSsz(testDefinition, dataFileName, testDefinition.getSpec().getGenesisSchemaDefinitions().getAttestationSchema());
processor.processAttestation(state, attestation);
break;
case SYNC_AGGREGATE:
final SyncAggregate syncAggregate = loadSsz(testDefinition, dataFileName, BeaconBlockBodySchemaAltair.required(testDefinition.getSpec().getGenesisSchemaDefinitions().getBeaconBlockBodySchema()).getSyncAggregateSchema());
processor.processSyncCommittee(state, syncAggregate);
break;
case EXECUTION_PAYLOAD:
final ExecutionMeta executionMeta = loadYaml(testDefinition, "execution.yaml", ExecutionMeta.class);
final ExecutionPayload payload = loadSsz(testDefinition, dataFileName, testDefinition.getSpec().getGenesisSchemaDefinitions().toVersionBellatrix().orElseThrow().getExecutionPayloadSchema());
processor.processExecutionPayload(state, payload, (latestExecutionPayloadHeader, payloadToExecute) -> executionMeta.executionValid);
break;
}
}
use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary in project teku by ConsenSys.
the class KvStoreDatabase method updateFinalizedDataArchiveMode.
private void updateFinalizedDataArchiveMode(Map<Bytes32, Bytes32> finalizedChildToParentMap, final Map<Bytes32, SignedBeaconBlock> finalizedBlocks, final Map<Bytes32, BeaconState> finalizedStates) {
final BlockProvider blockProvider = BlockProvider.withKnownBlocks(roots -> SafeFuture.completedFuture(getHotBlocks(roots)), finalizedBlocks);
final Optional<Checkpoint> initialCheckpoint = hotDao.getAnchor();
final Optional<Bytes32> initialBlockRoot = initialCheckpoint.map(Checkpoint::getRoot);
// Get previously finalized block to build on top of
final BeaconBlockSummary baseBlock = getLatestFinalizedBlockOrSummary();
final List<Bytes32> finalizedRoots = HashTree.builder().rootHash(baseBlock.getRoot()).childAndParentRoots(finalizedChildToParentMap).build().preOrderStream().collect(Collectors.toList());
int i = 0;
UInt64 lastSlot = baseBlock.getSlot();
while (i < finalizedRoots.size()) {
final int start = i;
try (final FinalizedUpdater updater = finalizedDao.finalizedUpdater()) {
final StateRootRecorder recorder = new StateRootRecorder(lastSlot, updater::addFinalizedStateRoot, spec);
while (i < finalizedRoots.size() && (i - start) < TX_BATCH_SIZE) {
final Bytes32 blockRoot = finalizedRoots.get(i);
final Optional<SignedBeaconBlock> maybeBlock = blockProvider.getBlock(blockRoot).join();
maybeBlock.ifPresent(updater::addFinalizedBlock);
// If block is missing and doesn't match the initial anchor, throw
if (maybeBlock.isEmpty() && initialBlockRoot.filter(r -> r.equals(blockRoot)).isEmpty()) {
throw new IllegalStateException("Missing finalized block");
}
Optional.ofNullable(finalizedStates.get(blockRoot)).or(() -> getHotState(blockRoot)).ifPresent(state -> {
updater.addFinalizedState(blockRoot, state);
recorder.acceptNextState(state);
});
lastSlot = maybeBlock.map(SignedBeaconBlock::getSlot).orElseGet(() -> initialCheckpoint.orElseThrow().getEpochStartSlot(spec));
i++;
}
updater.commit();
if (i >= TX_BATCH_SIZE) {
STATUS_LOG.recordedFinalizedBlocks(i, finalizedRoots.size());
}
}
}
}
Aggregations