use of tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory 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));
}
}
use of tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory 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);
}
}
Aggregations