Search in sources :

Example 1 with Database

use of tech.pegasys.teku.storage.server.Database in project teku by ConsenSys.

the class InMemoryStorageSystemBuilder method build.

public StorageSystem build() {
    final Database database;
    switch(version) {
        case LEVELDB_TREE:
            database = createLevelDbTreeDatabase();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB2:
        case V6:
            database = createV6Database();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB1:
        case V5:
            database = createV5Database();
            break;
        case V4:
            database = createV4Database();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported database version: " + version);
    }
    final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators);
    return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec, validatorKeys));
}
Also used : Database(tech.pegasys.teku.storage.server.Database) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory)

Example 2 with Database

use of tech.pegasys.teku.storage.server.Database in project teku by ConsenSys.

the class FileBackedStorageSystemBuilder method build.

public StorageSystem build() {
    final Database database;
    switch(version) {
        case LEVELDB_TREE:
            database = createLevelDbTrieDatabase();
            break;
        case LEVELDB2:
            database = createLevelDb2Database();
            break;
        case LEVELDB1:
            database = createLevelDb1Database();
            break;
        case V6:
            database = createV6Database();
            break;
        case V5:
            database = createV5Database();
            break;
        case V4:
            database = createV4Database();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported database version: " + version);
    }
    validate();
    return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec));
}
Also used : Database(tech.pegasys.teku.storage.server.Database)

Example 3 with Database

use of tech.pegasys.teku.storage.server.Database 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)

Example 4 with Database

use of tech.pegasys.teku.storage.server.Database in project teku by ConsenSys.

the class DebugDbCommand method getDeposits.

@Command(name = "get-deposits", description = "List the ETH1 deposit information stored in the database", 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 getDeposits(@Mixin final BeaconNodeDataOptions dataOptions, @Mixin final DataStorageOptions dataStorageOptions, @Mixin final Eth2NetworkOptions eth2NetworkOptions) throws Exception {
    try (final YamlEth1EventsChannel eth1EventsChannel = new YamlEth1EventsChannel(System.out);
        final Database database = createDatabase(dataOptions, dataStorageOptions, eth2NetworkOptions)) {
        final DepositStorage depositStorage = DepositStorage.create(eth1EventsChannel, database);
        depositStorage.replayDepositEvents().join();
    }
    return 0;
}
Also used : DepositStorage(tech.pegasys.teku.storage.server.DepositStorage) Database(tech.pegasys.teku.storage.server.Database) Command(picocli.CommandLine.Command)

Example 5 with Database

use of tech.pegasys.teku.storage.server.Database 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)

Aggregations

Database (tech.pegasys.teku.storage.server.Database)7 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)2 Command (picocli.CommandLine.Command)2 WeakSubjectivityState (tech.pegasys.teku.storage.events.WeakSubjectivityState)2 DepositStorage (tech.pegasys.teku.storage.server.DepositStorage)2 VersionedDatabaseFactory (tech.pegasys.teku.storage.server.VersionedDatabaseFactory)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 CommandLine (picocli.CommandLine)1 Mixin (picocli.CommandLine.Mixin)1 Option (picocli.CommandLine.Option)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)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