@Test void onAttestation_shouldBeInvalidWhenInvalidCheckpointThrown() { final SignedBlockAndState targetBlock = chainBuilder.generateBlockAtSlot(5); importBlock(chainBuilder, targetBlock); final Checkpoint targetCheckpoint = new Checkpoint(ZERO, targetBlock.getRoot()); final Attestation attestation = new Attestation( new Bitlist(5, 5), new AttestationData( targetBlock.getSlot(), compute_epoch_at_slot(targetBlock.getSlot()), targetBlock.getRoot(), targetBlock.getState().getCurrent_justified_checkpoint(), targetCheckpoint), BLSSignature.empty()); final SafeFuture<AttestationProcessingResult> result = forkChoice.onAttestation(ValidateableAttestation.fromAttestation(attestation)); assertThat(result) .isCompletedWithValue( AttestationProcessingResult.invalid( String.format( "Checkpoint state (%s) must be at or prior to checkpoint slot boundary (%s)", targetBlock.getSlot(), targetCheckpoint.getEpochStartSlot()))); }
public SafeFuture<AttestationProcessingResult> onAttestation( final ValidateableAttestation attestation) { return recentChainData .retrieveCheckpointState(attestation.getData().getTarget()) .thenCompose( targetBlockState -> onForkChoiceThread( () -> { final StoreTransaction transaction = recentChainData.startStoreTransaction(); final AttestationProcessingResult result = on_attestation( transaction, attestation, targetBlockState, getForkChoiceStrategy()); return result.isSuccessful() ? transaction.commit().thenApply(__ -> result) : SafeFuture.completedFuture(result); })) .exceptionallyCompose( error -> { final Throwable rootCause = Throwables.getRootCause(error); if (rootCause instanceof InvalidCheckpointException) { return SafeFuture.completedFuture( AttestationProcessingResult.invalid(rootCause.getMessage())); } return SafeFuture.failedFuture(error); }); }
ForkChoice { public SafeFuture<AttestationProcessingResult> onAttestation( final ValidateableAttestation attestation) { return recentChainData .retrieveCheckpointState(attestation.getData().getTarget()) .thenCompose( targetBlockState -> onForkChoiceThread( () -> { final StoreTransaction transaction = recentChainData.startStoreTransaction(); final AttestationProcessingResult result = on_attestation( transaction, attestation, targetBlockState, getForkChoiceStrategy()); return result.isSuccessful() ? transaction.commit().thenApply(__ -> result) : SafeFuture.completedFuture(result); })) .exceptionallyCompose( error -> { final Throwable rootCause = Throwables.getRootCause(error); if (rootCause instanceof InvalidCheckpointException) { return SafeFuture.completedFuture( AttestationProcessingResult.invalid(rootCause.getMessage())); } return SafeFuture.failedFuture(error); }); } }
ForkChoice { public SafeFuture<AttestationProcessingResult> onAttestation( final ValidateableAttestation attestation) { return recentChainData .retrieveCheckpointState(attestation.getData().getTarget()) .thenCompose( targetBlockState -> onForkChoiceThread( () -> { final StoreTransaction transaction = recentChainData.startStoreTransaction(); final AttestationProcessingResult result = on_attestation( transaction, attestation, targetBlockState, getForkChoiceStrategy()); return result.isSuccessful() ? transaction.commit().thenApply(__ -> result) : SafeFuture.completedFuture(result); })) .exceptionallyCompose( error -> { final Throwable rootCause = Throwables.getRootCause(error); if (rootCause instanceof InvalidCheckpointException) { return SafeFuture.completedFuture( AttestationProcessingResult.invalid(rootCause.getMessage())); } return SafeFuture.failedFuture(error); }); } ForkChoice(
      final ForkChoiceExecutor forkChoiceExecutor,
      final RecentChainData recentChainData,
      final StateTransition stateTransition); }
ForkChoice { public SafeFuture<AttestationProcessingResult> onAttestation( final ValidateableAttestation attestation) { return recentChainData .retrieveCheckpointState(attestation.getData().getTarget()) .thenCompose( targetBlockState -> onForkChoiceThread( () -> { final StoreTransaction transaction = recentChainData.startStoreTransaction(); final AttestationProcessingResult result = on_attestation( transaction, attestation, targetBlockState, getForkChoiceStrategy()); return result.isSuccessful() ? transaction.commit().thenApply(__ -> result) : SafeFuture.completedFuture(result); })) .exceptionallyCompose( error -> { final Throwable rootCause = Throwables.getRootCause(error); if (rootCause instanceof InvalidCheckpointException) { return SafeFuture.completedFuture( AttestationProcessingResult.invalid(rootCause.getMessage())); } return SafeFuture.failedFuture(error); }); } ForkChoice(
      final ForkChoiceExecutor forkChoiceExecutor,
      final RecentChainData recentChainData,
      final StateTransition stateTransition); void processHead(); void processHead(UInt64 nodeSlot, boolean syncing); SafeFuture<BlockImportResult> onBlock(
      final SignedBeaconBlock block, Optional<BeaconState> preState); SafeFuture<AttestationProcessingResult> onAttestation(
      final ValidateableAttestation attestation); void save(); void applyIndexedAttestations(final List<ValidateableAttestation> attestations); }
ForkChoice { public SafeFuture<AttestationProcessingResult> onAttestation( final ValidateableAttestation attestation) { return recentChainData .retrieveCheckpointState(attestation.getData().getTarget()) .thenCompose( targetBlockState -> onForkChoiceThread( () -> { final StoreTransaction transaction = recentChainData.startStoreTransaction(); final AttestationProcessingResult result = on_attestation( transaction, attestation, targetBlockState, getForkChoiceStrategy()); return result.isSuccessful() ? transaction.commit().thenApply(__ -> result) : SafeFuture.completedFuture(result); })) .exceptionallyCompose( error -> { final Throwable rootCause = Throwables.getRootCause(error); if (rootCause instanceof InvalidCheckpointException) { return SafeFuture.completedFuture( AttestationProcessingResult.invalid(rootCause.getMessage())); } return SafeFuture.failedFuture(error); }); } ForkChoice(
      final ForkChoiceExecutor forkChoiceExecutor,
      final RecentChainData recentChainData,
      final StateTransition stateTransition); void processHead(); void processHead(UInt64 nodeSlot, boolean syncing); SafeFuture<BlockImportResult> onBlock(
      final SignedBeaconBlock block, Optional<BeaconState> preState); SafeFuture<AttestationProcessingResult> onAttestation(
      final ValidateableAttestation attestation); void save(); void applyIndexedAttestations(final List<ValidateableAttestation> attestations);  }