@Test public void getSuppressWSPeriodChecksUntilEpoch_shouldModifyConfiguredEpoch() { final UInt64 configuredEpoch = currentEpoch.plus(WeakSubjectivityValidator.MAX_SUPPRESSED_EPOCHS).plus(1); final WeakSubjectivityConfig config = WeakSubjectivityConfig.builder().suppressWSPeriodChecksUntilEpoch(configuredEpoch).build(); final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policies); final UInt64 expected = currentEpoch.plus(WeakSubjectivityValidator.MAX_SUPPRESSED_EPOCHS); assertThat(validator.getSuppressWSPeriodChecksUntilEpoch(currentSlot)).contains(expected); assertThat(validator.getSuppressWSPeriodChecksUntilEpoch(currentSlot.plus(10_000))) .contains(expected); assertThat(validator.getSuppressWSPeriodChecksUntilEpoch(UInt64.ZERO)).contains(expected); }
@VisibleForTesting Optional<UInt64> getSuppressWSPeriodChecksUntilEpoch(final UInt64 currentSlot) { if (suppressWSPeriodErrorsUntilEpoch.isEmpty() && config.getSuppressWSPeriodChecksUntilEpoch().isPresent()) { final UInt64 configuredSuppressionEpoch = config.getSuppressWSPeriodChecksUntilEpoch().get(); final UInt64 startupEpoch = compute_epoch_at_slot(currentSlot); final UInt64 maxSuppressedEpoch = startupEpoch.plus(MAX_SUPPRESSED_EPOCHS); final UInt64 suppressionEpoch = configuredSuppressionEpoch.min(maxSuppressedEpoch); if (suppressionEpoch.isLessThan(configuredSuppressionEpoch)) { LOG.info( "Configured weak subjectivity error suppression epoch ({}) is too large, suppression epoch set to {} ({} epochs ahead of current epoch {}).", configuredSuppressionEpoch, suppressionEpoch, MAX_SUPPRESSED_EPOCHS, startupEpoch); } LOG.warn( "Configured to suppress weak subjectivity period checks until epoch {}", suppressionEpoch); suppressWSPeriodErrorsUntilEpoch = Optional.of(suppressionEpoch); } return suppressWSPeriodErrorsUntilEpoch; }
WeakSubjectivityValidator { @VisibleForTesting Optional<UInt64> getSuppressWSPeriodChecksUntilEpoch(final UInt64 currentSlot) { if (suppressWSPeriodErrorsUntilEpoch.isEmpty() && config.getSuppressWSPeriodChecksUntilEpoch().isPresent()) { final UInt64 configuredSuppressionEpoch = config.getSuppressWSPeriodChecksUntilEpoch().get(); final UInt64 startupEpoch = compute_epoch_at_slot(currentSlot); final UInt64 maxSuppressedEpoch = startupEpoch.plus(MAX_SUPPRESSED_EPOCHS); final UInt64 suppressionEpoch = configuredSuppressionEpoch.min(maxSuppressedEpoch); if (suppressionEpoch.isLessThan(configuredSuppressionEpoch)) { LOG.info( "Configured weak subjectivity error suppression epoch ({}) is too large, suppression epoch set to {} ({} epochs ahead of current epoch {}).", configuredSuppressionEpoch, suppressionEpoch, MAX_SUPPRESSED_EPOCHS, startupEpoch); } LOG.warn( "Configured to suppress weak subjectivity period checks until epoch {}", suppressionEpoch); suppressWSPeriodErrorsUntilEpoch = Optional.of(suppressionEpoch); } return suppressWSPeriodErrorsUntilEpoch; } }
WeakSubjectivityValidator { @VisibleForTesting Optional<UInt64> getSuppressWSPeriodChecksUntilEpoch(final UInt64 currentSlot) { if (suppressWSPeriodErrorsUntilEpoch.isEmpty() && config.getSuppressWSPeriodChecksUntilEpoch().isPresent()) { final UInt64 configuredSuppressionEpoch = config.getSuppressWSPeriodChecksUntilEpoch().get(); final UInt64 startupEpoch = compute_epoch_at_slot(currentSlot); final UInt64 maxSuppressedEpoch = startupEpoch.plus(MAX_SUPPRESSED_EPOCHS); final UInt64 suppressionEpoch = configuredSuppressionEpoch.min(maxSuppressedEpoch); if (suppressionEpoch.isLessThan(configuredSuppressionEpoch)) { LOG.info( "Configured weak subjectivity error suppression epoch ({}) is too large, suppression epoch set to {} ({} epochs ahead of current epoch {}).", configuredSuppressionEpoch, suppressionEpoch, MAX_SUPPRESSED_EPOCHS, startupEpoch); } LOG.warn( "Configured to suppress weak subjectivity period checks until epoch {}", suppressionEpoch); suppressWSPeriodErrorsUntilEpoch = Optional.of(suppressionEpoch); } return suppressWSPeriodErrorsUntilEpoch; } WeakSubjectivityValidator(
      final WeakSubjectivityConfig config,
      WeakSubjectivityCalculator calculator,
      List<WeakSubjectivityViolationPolicy> violationPolicies); }
WeakSubjectivityValidator { @VisibleForTesting Optional<UInt64> getSuppressWSPeriodChecksUntilEpoch(final UInt64 currentSlot) { if (suppressWSPeriodErrorsUntilEpoch.isEmpty() && config.getSuppressWSPeriodChecksUntilEpoch().isPresent()) { final UInt64 configuredSuppressionEpoch = config.getSuppressWSPeriodChecksUntilEpoch().get(); final UInt64 startupEpoch = compute_epoch_at_slot(currentSlot); final UInt64 maxSuppressedEpoch = startupEpoch.plus(MAX_SUPPRESSED_EPOCHS); final UInt64 suppressionEpoch = configuredSuppressionEpoch.min(maxSuppressedEpoch); if (suppressionEpoch.isLessThan(configuredSuppressionEpoch)) { LOG.info( "Configured weak subjectivity error suppression epoch ({}) is too large, suppression epoch set to {} ({} epochs ahead of current epoch {}).", configuredSuppressionEpoch, suppressionEpoch, MAX_SUPPRESSED_EPOCHS, startupEpoch); } LOG.warn( "Configured to suppress weak subjectivity period checks until epoch {}", suppressionEpoch); suppressWSPeriodErrorsUntilEpoch = Optional.of(suppressionEpoch); } return suppressWSPeriodErrorsUntilEpoch; } 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 { @VisibleForTesting Optional<UInt64> getSuppressWSPeriodChecksUntilEpoch(final UInt64 currentSlot) { if (suppressWSPeriodErrorsUntilEpoch.isEmpty() && config.getSuppressWSPeriodChecksUntilEpoch().isPresent()) { final UInt64 configuredSuppressionEpoch = config.getSuppressWSPeriodChecksUntilEpoch().get(); final UInt64 startupEpoch = compute_epoch_at_slot(currentSlot); final UInt64 maxSuppressedEpoch = startupEpoch.plus(MAX_SUPPRESSED_EPOCHS); final UInt64 suppressionEpoch = configuredSuppressionEpoch.min(maxSuppressedEpoch); if (suppressionEpoch.isLessThan(configuredSuppressionEpoch)) { LOG.info( "Configured weak subjectivity error suppression epoch ({}) is too large, suppression epoch set to {} ({} epochs ahead of current epoch {}).", configuredSuppressionEpoch, suppressionEpoch, MAX_SUPPRESSED_EPOCHS, startupEpoch); } LOG.warn( "Configured to suppress weak subjectivity period checks until epoch {}", suppressionEpoch); suppressWSPeriodErrorsUntilEpoch = Optional.of(suppressionEpoch); } return suppressWSPeriodErrorsUntilEpoch; } 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();  }