Search in sources :

Example 1 with InvalidCheckpointException

use of tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException in project teku by ConsenSys.

the class ForkChoice method onAttestation.

public SafeFuture<AttestationProcessingResult> onAttestation(final ValidateableAttestation attestation) {
    return recentChainData.retrieveCheckpointState(attestation.getData().getTarget()).thenCompose(maybeTargetState -> {
        final UpdatableStore store = recentChainData.getStore();
        final AttestationProcessingResult validationResult = spec.validateAttestation(store, attestation, maybeTargetState);
        if (!validationResult.isSuccessful()) {
            return SafeFuture.completedFuture(validationResult);
        }
        return onForkChoiceThread(() -> {
            final VoteUpdater transaction = recentChainData.startVoteUpdate();
            getForkChoiceStrategy().onAttestation(transaction, getIndexedAttestation(attestation));
            transaction.commit();
        }).thenApply(__ -> validationResult);
    }).exceptionallyCompose(error -> {
        final Throwable rootCause = Throwables.getRootCause(error);
        if (rootCause instanceof InvalidCheckpointException) {
            return SafeFuture.completedFuture(AttestationProcessingResult.invalid(rootCause.getMessage()));
        }
        return SafeFuture.failedFuture(error);
    });
}
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) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) InvalidCheckpointException(tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException)

Aggregations

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 Subscribers (tech.pegasys.teku.infrastructure.subscribers.Subscribers)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Spec (tech.pegasys.teku.spec.Spec)1 CapturingIndexedAttestationCache (tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache)1 IndexedAttestationCache (tech.pegasys.teku.spec.cache.IndexedAttestationCache)1