Search in sources :

Example 1 with MetricTrackingExecutorFactory

use of tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory in project teku by ConsenSys.

the class AggregatingSignatureVerificationServiceTest method testRealServiceWithThreads.

@Test
public void testRealServiceWithThreads() throws Exception {
    final MetricsSystem metrics = new StubMetricsSystem();
    final AsyncRunnerFactory realRunnerFactory = AsyncRunnerFactory.createDefault(new MetricTrackingExecutorFactory(metrics));
    service = new AggregatingSignatureVerificationService(metrics, realRunnerFactory, realRunnerFactory.create("completion", 1), 1, queueCapacity, batchSize, minBatchSizeToSplit, strictThreadLimitEnabled);
    startService();
    final Random random = new Random(1);
    for (int i = 0; i < 3; i++) {
        final List<SafeFuture<Boolean>> validFutures = new ArrayList<>();
        final List<SafeFuture<Boolean>> invalidFutures = new ArrayList<>();
        for (int j = 0; j < queueCapacity - i; j++) {
            if (random.nextFloat() < .5) {
                validFutures.add(executeValidVerify(j, j));
            } else {
                invalidFutures.add(executeInvalidVerify(j, j));
            }
        }
        final List<SafeFuture<Boolean>> allFutures = new ArrayList<>();
        allFutures.addAll(validFutures);
        allFutures.addAll(invalidFutures);
        Waiter.waitFor(SafeFuture.allOf(allFutures.toArray(SafeFuture<?>[]::new)), Duration.ofSeconds(5));
        validFutures.forEach(f -> assertThat(f).isCompletedWithValue(true));
        invalidFutures.forEach(f -> assertThat(f).isCompletedWithValue(false));
    }
}
Also used : StubAsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.StubAsyncRunnerFactory) AsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory) Random(java.util.Random) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) MetricTrackingExecutorFactory(tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory) ArrayList(java.util.ArrayList) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) Test(org.junit.jupiter.api.Test)

Example 2 with MetricTrackingExecutorFactory

use of tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory 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 3 with MetricTrackingExecutorFactory

use of tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory in project teku by ConsenSys.

the class VoluntaryExitCommand method initialise.

private void initialise() {
    config = tekuConfiguration();
    final AsyncRunnerFactory asyncRunnerFactory = AsyncRunnerFactory.createDefault(new MetricTrackingExecutorFactory(metricsSystem));
    final AsyncRunner asyncRunner = asyncRunnerFactory.create("voluntary-exits", 8);
    apiClient = config.validatorClient().getValidatorConfig().getBeaconNodeApiEndpoint().map(RemoteSpecLoader::createApiClient).orElseThrow();
    spec = getSpec(apiClient);
    validateOrDefaultEpoch();
    fork = spec.getForkSchedule().getFork(epoch);
    // get genesis time
    final Optional<Bytes32> maybeRoot = getGenesisRoot();
    if (maybeRoot.isEmpty()) {
        SUB_COMMAND_LOG.error("Unable to fetch genesis data, cannot generate an exit.");
        System.exit(1);
    }
    genesisRoot = maybeRoot.get();
    final RejectingSlashingProtector slashingProtector = new RejectingSlashingProtector();
    final SlashingProtectionLogger slashingProtectionLogger = new SlashingProtectionLogger(slashingProtector, spec, asyncRunner, ValidatorLogger.VALIDATOR_LOGGER);
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config.validatorClient().getValidatorConfig(), config.validatorClient().getInteropConfig(), new RejectingSlashingProtector(), slashingProtectionLogger, new PublicKeyLoader(), asyncRunner, metricsSystem, Optional.empty());
    try {
        validatorLoader.loadValidators();
        validators = validatorLoader.getOwnedValidators();
    } catch (InvalidConfigurationException ex) {
        SUB_COMMAND_LOG.error(ex.getMessage());
        System.exit(1);
    }
    if (validators.hasNoValidators()) {
        SUB_COMMAND_LOG.error("No validators were found to exit.");
        System.exit(1);
    }
}
Also used : AsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) PublicKeyLoader(tech.pegasys.teku.validator.client.loader.PublicKeyLoader) MetricTrackingExecutorFactory(tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory) SlashingProtectionLogger(tech.pegasys.teku.validator.client.loader.SlashingProtectionLogger) Bytes32(org.apache.tuweni.bytes.Bytes32) RejectingSlashingProtector(tech.pegasys.teku.core.signatures.RejectingSlashingProtector) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Aggregations

MetricTrackingExecutorFactory (tech.pegasys.teku.infrastructure.async.MetricTrackingExecutorFactory)3 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)2 AsyncRunnerFactory (tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 Test (org.junit.jupiter.api.Test)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