Search in sources :

Example 1 with BeaconBlockSummary

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()));
}
Also used : BeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary) CheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.CheckpointEpochs) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Logger(org.apache.logging.log4j.Logger) BlockAndCheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) Map(java.util.Map) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) FinalizedChainData(tech.pegasys.teku.storage.events.FinalizedChainData) Comparator(java.util.Comparator) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Bytes32(org.apache.tuweni.bytes.Bytes32) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) BeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary)

Example 2 with BeaconBlockSummary

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

Example 3 with BeaconBlockSummary

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;
    }
}
Also used : Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) SyncAggregate(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) BeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ExecutionPayload(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload)

Example 4 with BeaconBlockSummary

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());
            }
        }
    }
}
Also used : FinalizedUpdater(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreFinalizedDao.FinalizedUpdater) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) StateRootRecorder(tech.pegasys.teku.storage.server.state.StateRootRecorder) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary) BlockProvider(tech.pegasys.teku.dataproviders.lookup.BlockProvider) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Aggregations

BeaconBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Test (org.junit.jupiter.api.Test)1 ChainBuilder (tech.pegasys.teku.core.ChainBuilder)1 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)1