Search in sources :

Example 1 with Eth2NetworkOptions

use of tech.pegasys.teku.cli.options.Eth2NetworkOptions in project teku by ConsenSys.

the class DebugDbCommand method getLatestFinalizedState.

@Command(name = "get-latest-finalized-state", description = "Get the latest finalized state, if available, as SSZ", 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 getLatestFinalizedState(@Mixin final BeaconNodeDataOptions dataOptions, @Mixin final DataStorageOptions dataStorageOptions, @Mixin final Eth2NetworkOptions eth2NetworkOptions, @Option(required = true, names = { "--output", "-o" }, description = "File to write state to") final Path outputFile, @Option(names = { "--block-output" }, description = "File to write the block matching the latest finalized state to") final Path blockOutputFile) throws Exception {
    final AsyncRunner asyncRunner = ScheduledExecutorAsyncRunner.create("async", 1, new MetricTrackingExecutorFactory(new NoOpMetricsSystem()));
    try (final Database database = createDatabase(dataOptions, dataStorageOptions, eth2NetworkOptions)) {
        final Optional<AnchorPoint> finalizedAnchor = database.createMemoryStore().map(builder -> builder.blockProvider(BlockProvider.NOOP).asyncRunner(asyncRunner).stateProvider(StateAndBlockSummaryProvider.NOOP).build()).map(UpdatableStore::getLatestFinalized);
        int result = writeState(outputFile, finalizedAnchor.map(AnchorPoint::getState));
        if (result == 0 && blockOutputFile != null) {
            final Optional<SignedBeaconBlock> finalizedBlock = finalizedAnchor.flatMap(AnchorPoint::getSignedBeaconBlock);
            result = writeBlock(blockOutputFile, finalizedBlock);
        }
        return result;
    } finally {
        asyncRunner.shutdown();
    }
}
Also used : BlockProvider(tech.pegasys.teku.dataproviders.lookup.BlockProvider) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) BeaconNodeDataOptions(tech.pegasys.teku.cli.options.BeaconNodeDataOptions) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) DepositStorage(tech.pegasys.teku.storage.server.DepositStorage) VersionedDatabaseFactory(tech.pegasys.teku.storage.server.VersionedDatabaseFactory) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Command(picocli.CommandLine.Command) MetricTrackingExecutorFactory(tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Path(java.nio.file.Path) CommandLine(picocli.CommandLine) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) Files(java.nio.file.Files) ScheduledExecutorAsyncRunner(tech.pegasys.teku.infrastructure.async.ScheduledExecutorAsyncRunner) Mixin(picocli.CommandLine.Mixin) IOException(java.io.IOException) StateAndBlockSummaryProvider(tech.pegasys.teku.dataproviders.lookup.StateAndBlockSummaryProvider) Option(picocli.CommandLine.Option) PicoCliVersionProvider(tech.pegasys.teku.cli.converter.PicoCliVersionProvider) Database(tech.pegasys.teku.storage.server.Database) Eth2NetworkOptions(tech.pegasys.teku.cli.options.Eth2NetworkOptions) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) Optional(java.util.Optional) DataStorageOptions(tech.pegasys.teku.cli.options.DataStorageOptions) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) MetricTrackingExecutorFactory(tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Database(tech.pegasys.teku.storage.server.Database) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ScheduledExecutorAsyncRunner(tech.pegasys.teku.infrastructure.async.ScheduledExecutorAsyncRunner) Command(picocli.CommandLine.Command)

Aggregations

IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 CommandLine (picocli.CommandLine)1 Command (picocli.CommandLine.Command)1 Mixin (picocli.CommandLine.Mixin)1 Option (picocli.CommandLine.Option)1 PicoCliVersionProvider (tech.pegasys.teku.cli.converter.PicoCliVersionProvider)1 BeaconNodeDataOptions (tech.pegasys.teku.cli.options.BeaconNodeDataOptions)1 DataStorageOptions (tech.pegasys.teku.cli.options.DataStorageOptions)1 Eth2NetworkOptions (tech.pegasys.teku.cli.options.Eth2NetworkOptions)1 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)1 StateAndBlockSummaryProvider (tech.pegasys.teku.dataproviders.lookup.StateAndBlockSummaryProvider)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 MetricTrackingExecutorFactory (tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory)1 ScheduledExecutorAsyncRunner (tech.pegasys.teku.infrastructure.async.ScheduledExecutorAsyncRunner)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)1