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);
});
}
Aggregations