Search in sources :

Example 1 with WeakSubjectivityState

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) WeakSubjectivityState(tech.pegasys.teku.storage.events.WeakSubjectivityState) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 2 with WeakSubjectivityState

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;
    }
}
Also used : Database(tech.pegasys.teku.storage.server.Database) WeakSubjectivityState(tech.pegasys.teku.storage.events.WeakSubjectivityState)

Example 3 with WeakSubjectivityState

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;
    }
}
Also used : Database(tech.pegasys.teku.storage.server.Database) WeakSubjectivityState(tech.pegasys.teku.storage.events.WeakSubjectivityState)

Example 4 with WeakSubjectivityState

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) WeakSubjectivityState(tech.pegasys.teku.storage.events.WeakSubjectivityState) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 5 with WeakSubjectivityState

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());
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) WeakSubjectivityState(tech.pegasys.teku.storage.events.WeakSubjectivityState) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Aggregations

WeakSubjectivityState (tech.pegasys.teku.storage.events.WeakSubjectivityState)5 Test (org.junit.jupiter.api.Test)3 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)3 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)3 WeakSubjectivityConfig (tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig)3 Database (tech.pegasys.teku.storage.server.Database)2