use of tech.pegasys.teku.core.signatures.DeletableSigner in project teku by ConsenSys.
the class ValidatorLoader method addValidator.
private void addValidator(final Signer signer, final BLSPublicKey publicKey) {
ownedValidators.addValidator(new Validator(publicKey, new DeletableSigner(signer), graffitiProvider, false));
LOG.info("Added validator: {}", publicKey.toString());
}
use of tech.pegasys.teku.core.signatures.DeletableSigner in project teku by ConsenSys.
the class MultithreadedValidatorLoader method loadValidators.
public static void loadValidators(final OwnedValidators ownedValidators, final Map<BLSPublicKey, ValidatorProvider> providers, final GraffitiProvider graffitiProvider) {
final int totalValidatorCount = providers.size();
STATUS_LOG.loadingValidators(totalValidatorCount);
final ExecutorService executorService = Executors.newFixedThreadPool(Math.min(4, Runtime.getRuntime().availableProcessors()));
try {
final AtomicInteger numberOfLoadedKeys = new AtomicInteger(0);
final List<Future<Validator>> futures = providers.values().stream().map(provider -> executorService.submit(() -> {
final Validator validator = new Validator(provider.getPublicKey(), new DeletableSigner(provider.createSigner()), graffitiProvider, provider.isReadOnly());
int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet();
if (loadedValidatorCount % 10 == 0) {
STATUS_LOG.atLoadedValidatorNumber(loadedValidatorCount, totalValidatorCount);
}
return validator;
})).collect(toList());
final List<Validator> addedValidators = new ArrayList<>();
for (Future<Validator> future : futures) {
final Validator validator = future.get();
addedValidators.add(validator);
}
// Only start adding validators once we've successfully loaded all keys
addedValidators.forEach(ownedValidators::addValidator);
STATUS_LOG.validatorsInitialised(addedValidators.stream().map(validator -> validator.getPublicKey().toAbbreviatedString()).collect(toList()));
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while attempting to load validator key files", e);
} catch (ExecutionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException("Unable to load validator key files", e);
} finally {
executorService.shutdownNow();
}
}
Aggregations