Search in sources :

Example 1 with CapturingIndexedAttestationCache

use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.

the class AbstractBlockProcessor method processAttestations.

@Override
public void processAttestations(final MutableBeaconState state, final SszList<Attestation> attestations, final BLSSignatureVerifier signatureVerifier) throws BlockProcessingException {
    final CapturingIndexedAttestationCache indexedAttestationCache = IndexedAttestationCache.capturing();
    processAttestationsNoVerification(state, attestations, indexedAttestationCache);
    final BlockValidationResult result = verifyAttestationSignatures(state, attestations, signatureVerifier, indexedAttestationCache);
    if (!result.isValid()) {
        throw new BlockProcessingException(result.getFailureReason());
    }
}
Also used : CapturingIndexedAttestationCache(tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache) BlockProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException) BlockValidationResult(tech.pegasys.teku.spec.logic.common.statetransition.blockvalidator.BlockValidationResult)

Example 2 with CapturingIndexedAttestationCache

use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.

the class ForkChoice method onBlock.

/**
 * Import a block to the store. The supplied blockSlotState must already have empty slots
 * processed to the same slot as the block.
 */
private SafeFuture<BlockImportResult> onBlock(final SignedBeaconBlock block, final Optional<BeaconState> blockSlotState, final ExecutionEngineChannel executionEngine) {
    if (blockSlotState.isEmpty()) {
        return SafeFuture.completedFuture(BlockImportResult.FAILED_UNKNOWN_PARENT);
    }
    checkArgument(block.getSlot().equals(blockSlotState.get().getSlot()), "State must have processed slots up to the block slot. Block slot %s, state slot %s", block.getSlot(), blockSlotState.get().getSlot());
    final ForkChoicePayloadExecutor payloadExecutor = ForkChoicePayloadExecutor.create(spec, recentChainData, block, executionEngine);
    final ForkChoiceUtil forkChoiceUtil = spec.atSlot(block.getSlot()).getForkChoiceUtil();
    final BlockImportResult preconditionCheckResult = forkChoiceUtil.checkOnBlockConditions(block, blockSlotState.get(), recentChainData.getStore());
    if (!preconditionCheckResult.isSuccessful()) {
        reportInvalidBlock(block, preconditionCheckResult);
        return SafeFuture.completedFuture(preconditionCheckResult);
    }
    final CapturingIndexedAttestationCache indexedAttestationCache = IndexedAttestationCache.capturing();
    final BeaconState postState;
    try {
        postState = spec.getBlockProcessor(block.getSlot()).processAndValidateBlock(block, blockSlotState.get(), indexedAttestationCache, payloadExecutor);
    } catch (final StateTransitionException e) {
        final BlockImportResult result = BlockImportResult.failedStateTransition(e);
        reportInvalidBlock(block, result);
        return SafeFuture.completedFuture(result);
    }
    return payloadExecutor.getExecutionResult().thenApplyAsync(payloadResult -> importBlockAndState(block, blockSlotState.get(), forkChoiceUtil, indexedAttestationCache, postState, payloadResult), forkChoiceExecutor);
}
Also used : ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) CapturingIndexedAttestationCache(tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Example 3 with CapturingIndexedAttestationCache

use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.

the class ForkChoice method applyVotesFromBlock.

private void applyVotesFromBlock(final ForkChoiceStrategy forkChoiceStrategy, final UInt64 currentEpoch, final CapturingIndexedAttestationCache indexedAttestationProvider) {
    final VoteUpdater voteUpdater = recentChainData.startVoteUpdate();
    indexedAttestationProvider.getIndexedAttestations().stream().filter(attestation -> validateBlockAttestation(forkChoiceStrategy, currentEpoch, attestation)).forEach(attestation -> forkChoiceStrategy.onAttestation(voteUpdater, attestation));
    voteUpdater.commit();
}
Also used : StateRootCollector.addParentStateRoots(tech.pegasys.teku.statetransition.forkchoice.StateRootCollector.addParentStateRoots) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) ExceptionThrowingRunnable(tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) IndexedAttestation(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) CapturingIndexedAttestationCache(tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache) ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) InvalidCheckpointException(tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Bytes32(org.apache.tuweni.bytes.Bytes32) FatalServiceFailureException(tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) EventThread(tech.pegasys.teku.infrastructure.async.eventthread.EventThread) Throwables(com.google.common.base.Throwables) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) INTERVALS_PER_SLOT(tech.pegasys.teku.spec.constants.NetworkConstants.INTERVALS_PER_SLOT) P2P_LOG(tech.pegasys.teku.infrastructure.logging.P2PLogger.P2P_LOG) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) List(java.util.List) ForkChoiceStrategy(tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy) ExceptionUtil(tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil) Logger(org.apache.logging.log4j.Logger) IndexedAttestationCache(tech.pegasys.teku.spec.cache.IndexedAttestationCache) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) ExceptionThrowingSupplier(tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater)

Aggregations

CapturingIndexedAttestationCache (tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 StateTransitionException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)2 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)2 ForkChoiceUtil (tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Throwables (com.google.common.base.Throwables)1 List (java.util.List)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 ForkChoiceStrategy (tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy)1 ExceptionThrowingRunnable (tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable)1 ExceptionThrowingSupplier (tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 EventThread (tech.pegasys.teku.infrastructure.async.eventthread.EventThread)1 ExceptionUtil (tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil)1 FatalServiceFailureException (tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException)1 P2P_LOG (tech.pegasys.teku.infrastructure.logging.P2PLogger.P2P_LOG)1