@Test public void isBlockValid_withWSCheckpoint_blockAtCheckpointEpochBoundary_mismatch() { final UInt64 wsCheckpointEpoch = UInt64.valueOf(100); final UInt64 wsCheckpointSlot = compute_start_slot_at_epoch(wsCheckpointEpoch); final Checkpoint wsCheckpoint = new Checkpoint(wsCheckpointEpoch, Bytes32.fromHexStringLenient("0x0100")); final WeakSubjectivityConfig config = WeakSubjectivityConfig.builder().weakSubjectivityCheckpoint(wsCheckpoint).build(); final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policies); final SignedBeaconBlock block = mockBlock(wsCheckpointSlot, Bytes32.fromHexString("0x02"), Bytes32.fromHexString("0x01")); assertThat(validator.isBlockValid(block, forkChoiceStrategy)).isFalse(); }
public boolean isBlockValid( final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return true; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); UInt64 blockEpoch = compute_epoch_at_slot(block.getSlot()); boolean blockAtEpochBoundary = compute_start_slot_at_epoch(blockEpoch).equals(block.getSlot()); if (isWSCheckpointEpoch(blockEpoch) && blockAtEpochBoundary) { return isWSCheckpointBlock(block); } else if (isWSCheckpointBlock(block)) { return true; } else if (blockEpoch.isGreaterThanOrEqualTo(wsCheckpoint.getEpoch())) { final Optional<Bytes32> ancestor = get_ancestor( forkChoiceStrategy, block.getParent_root(), wsCheckpoint.getEpochStartSlot()); return ancestor.map(a -> a.equals(wsCheckpoint.getRoot())).orElse(true); } return true; }
WeakSubjectivityValidator { public boolean isBlockValid( final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return true; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); UInt64 blockEpoch = compute_epoch_at_slot(block.getSlot()); boolean blockAtEpochBoundary = compute_start_slot_at_epoch(blockEpoch).equals(block.getSlot()); if (isWSCheckpointEpoch(blockEpoch) && blockAtEpochBoundary) { return isWSCheckpointBlock(block); } else if (isWSCheckpointBlock(block)) { return true; } else if (blockEpoch.isGreaterThanOrEqualTo(wsCheckpoint.getEpoch())) { final Optional<Bytes32> ancestor = get_ancestor( forkChoiceStrategy, block.getParent_root(), wsCheckpoint.getEpochStartSlot()); return ancestor.map(a -> a.equals(wsCheckpoint.getRoot())).orElse(true); } return true; } }
WeakSubjectivityValidator { public boolean isBlockValid( final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return true; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); UInt64 blockEpoch = compute_epoch_at_slot(block.getSlot()); boolean blockAtEpochBoundary = compute_start_slot_at_epoch(blockEpoch).equals(block.getSlot()); if (isWSCheckpointEpoch(blockEpoch) && blockAtEpochBoundary) { return isWSCheckpointBlock(block); } else if (isWSCheckpointBlock(block)) { return true; } else if (blockEpoch.isGreaterThanOrEqualTo(wsCheckpoint.getEpoch())) { final Optional<Bytes32> ancestor = get_ancestor( forkChoiceStrategy, block.getParent_root(), wsCheckpoint.getEpochStartSlot()); return ancestor.map(a -> a.equals(wsCheckpoint.getRoot())).orElse(true); } return true; } WeakSubjectivityValidator(
      final WeakSubjectivityConfig config,
      WeakSubjectivityCalculator calculator,
      List<WeakSubjectivityViolationPolicy> violationPolicies); }
WeakSubjectivityValidator { public boolean isBlockValid( final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return true; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); UInt64 blockEpoch = compute_epoch_at_slot(block.getSlot()); boolean blockAtEpochBoundary = compute_start_slot_at_epoch(blockEpoch).equals(block.getSlot()); if (isWSCheckpointEpoch(blockEpoch) && blockAtEpochBoundary) { return isWSCheckpointBlock(block); } else if (isWSCheckpointBlock(block)) { return true; } else if (blockEpoch.isGreaterThanOrEqualTo(wsCheckpoint.getEpoch())) { final Optional<Bytes32> ancestor = get_ancestor( forkChoiceStrategy, block.getParent_root(), wsCheckpoint.getEpochStartSlot()); return ancestor.map(a -> a.equals(wsCheckpoint.getRoot())).orElse(true); } return true; } 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 boolean isBlockValid( final SignedBeaconBlock block, ForkChoiceStrategy forkChoiceStrategy) { if (config.getWeakSubjectivityCheckpoint().isEmpty()) { return true; } final Checkpoint wsCheckpoint = config.getWeakSubjectivityCheckpoint().get(); UInt64 blockEpoch = compute_epoch_at_slot(block.getSlot()); boolean blockAtEpochBoundary = compute_start_slot_at_epoch(blockEpoch).equals(block.getSlot()); if (isWSCheckpointEpoch(blockEpoch) && blockAtEpochBoundary) { return isWSCheckpointBlock(block); } else if (isWSCheckpointBlock(block)) { return true; } else if (blockEpoch.isGreaterThanOrEqualTo(wsCheckpoint.getEpoch())) { final Optional<Bytes32> ancestor = get_ancestor( forkChoiceStrategy, block.getParent_root(), wsCheckpoint.getEpochStartSlot()); return ancestor.map(a -> a.equals(wsCheckpoint.getRoot())).orElse(true); } return true; } 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();  }