@Test public void validateChainIsConsistentWithWSCheckpoint_checkpointFinalizedWithMissingBlock() { final UInt64 checkpointEpoch = UInt64.valueOf(100); final UInt64 checkpointSlot = compute_start_slot_at_epoch(checkpointEpoch); final SignedBeaconBlock checkpointBlock = dataStructureUtil.randomSignedBeaconBlock(checkpointSlot); final Checkpoint wsCheckpoint = new Checkpoint(checkpointEpoch, checkpointBlock.getRoot()); final WeakSubjectivityConfig config = WeakSubjectivityConfig.builder().weakSubjectivityCheckpoint(wsCheckpoint).build(); final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policies); final CombinedChainDataClient chainData = mockChainDataClientAfterCheckpoint(wsCheckpoint, Optional.empty()); SafeFuture<Void> result = validator.validateChainIsConsistentWithWSCheckpoint(chainData); assertThat(result).isCompletedExceptionally(); verify(chainData).isFinalizedEpoch(wsCheckpoint.getEpoch()); verify(chainData).getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()); orderedPolicyMocks.verifyNoMoreInteractions(); }
public SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint( CombinedChainDataClient chainData) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return SafeFuture.COMPLETE; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); if (!chainData.isFinalizedEpoch(wsCheckpoint.getEpoch())) { return SafeFuture.COMPLETE; } return chainData .getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()) .thenAccept( maybeBlock -> { SignedBeaconBlock blockAtCheckpointSlot = maybeBlock.orElseThrow(); if (!blockAtCheckpointSlot.getRoot().equals(wsCheckpoint.getRoot())) { handleInconsistentWsCheckpoint(blockAtCheckpointSlot); } }); }
WeakSubjectivityValidator { public SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint( CombinedChainDataClient chainData) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return SafeFuture.COMPLETE; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); if (!chainData.isFinalizedEpoch(wsCheckpoint.getEpoch())) { return SafeFuture.COMPLETE; } return chainData .getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()) .thenAccept( maybeBlock -> { SignedBeaconBlock blockAtCheckpointSlot = maybeBlock.orElseThrow(); if (!blockAtCheckpointSlot.getRoot().equals(wsCheckpoint.getRoot())) { handleInconsistentWsCheckpoint(blockAtCheckpointSlot); } }); } }
WeakSubjectivityValidator { public SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint( CombinedChainDataClient chainData) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return SafeFuture.COMPLETE; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); if (!chainData.isFinalizedEpoch(wsCheckpoint.getEpoch())) { return SafeFuture.COMPLETE; } return chainData .getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()) .thenAccept( maybeBlock -> { SignedBeaconBlock blockAtCheckpointSlot = maybeBlock.orElseThrow(); if (!blockAtCheckpointSlot.getRoot().equals(wsCheckpoint.getRoot())) { handleInconsistentWsCheckpoint(blockAtCheckpointSlot); } }); } WeakSubjectivityValidator(
      final WeakSubjectivityConfig config,
      WeakSubjectivityCalculator calculator,
      List<WeakSubjectivityViolationPolicy> violationPolicies); }
WeakSubjectivityValidator { public SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint( CombinedChainDataClient chainData) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return SafeFuture.COMPLETE; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); if (!chainData.isFinalizedEpoch(wsCheckpoint.getEpoch())) { return SafeFuture.COMPLETE; } return chainData .getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()) .thenAccept( maybeBlock -> { SignedBeaconBlock blockAtCheckpointSlot = maybeBlock.orElseThrow(); if (!blockAtCheckpointSlot.getRoot().equals(wsCheckpoint.getRoot())) { handleInconsistentWsCheckpoint(blockAtCheckpointSlot); } }); } WeakSubjectivityValidator(
      final WeakSubjectivityConfig config,
      WeakSubjectivityCalculator calculator,
      List<WeakSubjectivityViolationPolicy> violationPolicies); static WeakSubjectivityValidator strict(final WeakSubjectivityConfig config); static WeakSubjectivityValidator lenient(); static WeakSubjectivityValidator lenient(final WeakSubjectivityConfig config); Optional<Checkpoint> getWSCheckpoint(); SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint(
      CombinedChainDataClient chainData); void validateLatestFinalizedCheckpoint(
      final CheckpointState latestFinalizedCheckpoint, final UInt64 currentSlot); boolean isBlockValid(
      final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy); void handleValidationFailure(final String message); void handleValidationFailure(final String message, Throwable error); @Override boolean equals(final Object o); @Override int hashCode(); }
WeakSubjectivityValidator { public SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint( CombinedChainDataClient chainData) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return SafeFuture.COMPLETE; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); if (!chainData.isFinalizedEpoch(wsCheckpoint.getEpoch())) { return SafeFuture.COMPLETE; } return chainData .getBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot()) .thenAccept( maybeBlock -> { SignedBeaconBlock blockAtCheckpointSlot = maybeBlock.orElseThrow(); if (!blockAtCheckpointSlot.getRoot().equals(wsCheckpoint.getRoot())) { handleInconsistentWsCheckpoint(blockAtCheckpointSlot); } }); } WeakSubjectivityValidator(
      final WeakSubjectivityConfig config,
      WeakSubjectivityCalculator calculator,
      List<WeakSubjectivityViolationPolicy> violationPolicies); static WeakSubjectivityValidator strict(final WeakSubjectivityConfig config); static WeakSubjectivityValidator lenient(); static WeakSubjectivityValidator lenient(final WeakSubjectivityConfig config); Optional<Checkpoint> getWSCheckpoint(); SafeFuture<Void> validateChainIsConsistentWithWSCheckpoint(
      CombinedChainDataClient chainData); void validateLatestFinalizedCheckpoint(
      final CheckpointState latestFinalizedCheckpoint, final UInt64 currentSlot); boolean isBlockValid(
      final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy); void handleValidationFailure(final String message); void handleValidationFailure(final String message, Throwable error); @Override boolean equals(final Object o); @Override int hashCode();  }