use of tech.pegasys.teku.cli.options.BeaconNodeDataOptions 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();
}
}
Aggregations