use of tech.pegasys.teku.storage.events.WeakSubjectivityState in project teku by ConsenSys.
the class WeakSubjectivityInitializerTest method finalizeAndStoreConfig_withStoredCheckpoint_withConsistentCLIArgs.
@Test
public void finalizeAndStoreConfig_withStoredCheckpoint_withConsistentCLIArgs() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final Checkpoint cliCheckpoint = dataStructureUtil.randomCheckpoint();
final WeakSubjectivityConfig cliConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(cliCheckpoint).build();
// Setup storage
final WeakSubjectivityState storedState = WeakSubjectivityState.create(Optional.of(cliCheckpoint));
when(queryChannel.getWeakSubjectivityState()).thenReturn(SafeFuture.completedFuture(storedState));
final SafeFuture<WeakSubjectivityConfig> result = initializer.finalizeAndStoreConfig(cliConfig, queryChannel, updateChannel);
assertThat(result).isCompleted();
verify(queryChannel).getWeakSubjectivityState();
verify(updateChannel, never()).onWeakSubjectivityUpdate(any());
assertThat(result.join()).usingRecursiveComparison().isEqualTo(cliConfig);
}
use of tech.pegasys.teku.storage.events.WeakSubjectivityState in project teku by ConsenSys.
the class WeakSubjectivityCommand method clearWeakSubjectivityState.
@CommandLine.Command(name = "clear-state", description = "Clears stored weak subjectivity configuration", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public int clearWeakSubjectivityState(@CommandLine.Mixin final BeaconNodeDataOptions dataOptions, @CommandLine.Mixin final DataStorageOptions dataStorageOptions, @CommandLine.Mixin final Eth2NetworkOptions eth2NetworkOptions) throws Exception {
try (final Database db = createDatabase(dataOptions, dataStorageOptions, eth2NetworkOptions)) {
// Pull value before updating
final WeakSubjectivityState original = db.getWeakSubjectivityState();
if (original.isEmpty()) {
SUB_COMMAND_LOG.display("Weak subjectivity state is already empty - nothing to clear.");
return 0;
}
SUB_COMMAND_LOG.display("Clearing weak subjectivity state: " + stateToString(original));
db.updateWeakSubjectivityState(WeakSubjectivityUpdate.clearWeakSubjectivityCheckpoint());
SUB_COMMAND_LOG.display("Successfully cleared weak subjectivity state.");
return 0;
}
}
use of tech.pegasys.teku.storage.events.WeakSubjectivityState in project teku by ConsenSys.
the class WeakSubjectivityCommand method displayWeakSubjectivityState.
@CommandLine.Command(name = "display-state", description = "Display the stored weak subjectivity configuration", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public int displayWeakSubjectivityState(@CommandLine.Mixin final BeaconNodeDataOptions dataOptions, @CommandLine.Mixin final DataStorageOptions dataStorageOptions, @CommandLine.Mixin final Eth2NetworkOptions eth2NetworkOptions) throws Exception {
try (final Database db = createDatabase(dataOptions, dataStorageOptions, eth2NetworkOptions)) {
final WeakSubjectivityState wsState = db.getWeakSubjectivityState();
SUB_COMMAND_LOG.display("Stored weak subjectivity state: " + stateToString(wsState));
return 0;
}
}
use of tech.pegasys.teku.storage.events.WeakSubjectivityState in project teku by ConsenSys.
the class WeakSubjectivityInitializerTest method finalizeAndStoreConfig_withStoredCheckpoint_withNewDistinctArgs.
@Test
public void finalizeAndStoreConfig_withStoredCheckpoint_withNewDistinctArgs() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final Checkpoint cliCheckpoint = dataStructureUtil.randomCheckpoint();
final WeakSubjectivityConfig cliConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(cliCheckpoint).suppressWSPeriodChecksUntilEpoch(UInt64.valueOf(123)).safetyDecay(UInt64.valueOf(5)).build();
// Setup storage
final Checkpoint storedCheckpoint = dataStructureUtil.randomCheckpoint();
final WeakSubjectivityState storedState = WeakSubjectivityState.create(Optional.of(storedCheckpoint));
when(queryChannel.getWeakSubjectivityState()).thenReturn(SafeFuture.completedFuture(storedState));
final SafeFuture<WeakSubjectivityConfig> result = initializer.finalizeAndStoreConfig(cliConfig, queryChannel, updateChannel);
assertThat(result).isCompleted();
verify(queryChannel).getWeakSubjectivityState();
verify(updateChannel).onWeakSubjectivityUpdate(WeakSubjectivityUpdate.setWeakSubjectivityCheckpoint(cliCheckpoint));
assertThat(result.join()).usingRecursiveComparison().isEqualTo(cliConfig);
}
use of tech.pegasys.teku.storage.events.WeakSubjectivityState in project teku by ConsenSys.
the class WeakSubjectivityInitializerTest method finalizeAndStoreConfig_withStoredCheckpoint_noNewArgs.
@Test
public void finalizeAndStoreConfig_withStoredCheckpoint_noNewArgs() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
// Setup storage
final Checkpoint storedCheckpoint = dataStructureUtil.randomCheckpoint();
final WeakSubjectivityState storedState = WeakSubjectivityState.create(Optional.of(storedCheckpoint));
when(queryChannel.getWeakSubjectivityState()).thenReturn(SafeFuture.completedFuture(storedState));
final SafeFuture<WeakSubjectivityConfig> result = initializer.finalizeAndStoreConfig(defaultConfig, queryChannel, updateChannel);
assertThat(result).isCompleted();
verify(queryChannel).getWeakSubjectivityState();
verify(updateChannel, never()).onWeakSubjectivityUpdate(any());
assertThat(result.join()).usingRecursiveComparison().isEqualTo(WeakSubjectivityConfig.builder(storedState).specProvider(spec).build());
}
Aggregations