@Test void shouldLoadKeysFromKeyStores(@TempDir final Path tempDir) throws Exception { final Path scryptKeystore = Path.of(Resources.getResource("scryptTestVector.json").toURI()); final Path pbkdf2Keystore = Path.of(Resources.getResource("pbkdf2TestVector.json").toURI()); final Path tempPasswordFile = createTempFile(tempDir, "pass", ".txt"); writeString(tempPasswordFile, EXPECTED_PASSWORD); final List<Pair<Path, Path>> keystorePasswordFilePairs = List.of( Pair.of(scryptKeystore, tempPasswordFile), Pair.of(pbkdf2Keystore, tempPasswordFile)); when(config.getValidatorKeystorePasswordFilePairs()).thenReturn(keystorePasswordFilePairs); final List<BLSKeyPair> blsKeyPairs = keystoresValidatorKeyProvider.loadValidatorKeys(); Assertions.assertThat(blsKeyPairs).containsExactly(EXPECTED_BLS_KEY_PAIR); }
@Override public List<BLSKeyPair> loadValidatorKeys() { final List<Pair<Path, Path>> keystorePasswordFilePairs = config.getValidatorKeystorePasswordFilePairs(); checkNotNull(keystorePasswordFilePairs, "validator keystore and password pairs cannot be null"); final int totalValidatorCount = keystorePasswordFilePairs.size(); StatusLogger.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<Bytes32>> futures = keystorePasswordFilePairs.stream() .map( pair -> executorService.submit( () -> { Bytes32 privateKey = loadBLSPrivateKey(pair.getLeft(), loadPassword(pair.getRight())); int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet(); if (loadedValidatorCount % 10 == 0) { StatusLogger.STATUS_LOG.atLoadedValidatorNumber( loadedValidatorCount, totalValidatorCount); } return privateKey; })) .collect(toList()); Set<Bytes32> result = new HashSet<>(); for (Future<Bytes32> future : futures) { result.add(future.get()); } return result.stream() .map(privKey -> new BLSKeyPair(BLSSecretKey.fromBytes(privKey))) .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(); } }
KeystoresValidatorKeyProvider implements ValidatorKeyProvider { @Override public List<BLSKeyPair> loadValidatorKeys() { final List<Pair<Path, Path>> keystorePasswordFilePairs = config.getValidatorKeystorePasswordFilePairs(); checkNotNull(keystorePasswordFilePairs, "validator keystore and password pairs cannot be null"); final int totalValidatorCount = keystorePasswordFilePairs.size(); StatusLogger.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<Bytes32>> futures = keystorePasswordFilePairs.stream() .map( pair -> executorService.submit( () -> { Bytes32 privateKey = loadBLSPrivateKey(pair.getLeft(), loadPassword(pair.getRight())); int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet(); if (loadedValidatorCount % 10 == 0) { StatusLogger.STATUS_LOG.atLoadedValidatorNumber( loadedValidatorCount, totalValidatorCount); } return privateKey; })) .collect(toList()); Set<Bytes32> result = new HashSet<>(); for (Future<Bytes32> future : futures) { result.add(future.get()); } return result.stream() .map(privKey -> new BLSKeyPair(BLSSecretKey.fromBytes(privKey))) .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(); } } }
KeystoresValidatorKeyProvider implements ValidatorKeyProvider { @Override public List<BLSKeyPair> loadValidatorKeys() { final List<Pair<Path, Path>> keystorePasswordFilePairs = config.getValidatorKeystorePasswordFilePairs(); checkNotNull(keystorePasswordFilePairs, "validator keystore and password pairs cannot be null"); final int totalValidatorCount = keystorePasswordFilePairs.size(); StatusLogger.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<Bytes32>> futures = keystorePasswordFilePairs.stream() .map( pair -> executorService.submit( () -> { Bytes32 privateKey = loadBLSPrivateKey(pair.getLeft(), loadPassword(pair.getRight())); int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet(); if (loadedValidatorCount % 10 == 0) { StatusLogger.STATUS_LOG.atLoadedValidatorNumber( loadedValidatorCount, totalValidatorCount); } return privateKey; })) .collect(toList()); Set<Bytes32> result = new HashSet<>(); for (Future<Bytes32> future : futures) { result.add(future.get()); } return result.stream() .map(privKey -> new BLSKeyPair(BLSSecretKey.fromBytes(privKey))) .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(); } } KeystoresValidatorKeyProvider(
      final KeystoreLocker keystoreLocker, final ValidatorConfig config); }
KeystoresValidatorKeyProvider implements ValidatorKeyProvider { @Override public List<BLSKeyPair> loadValidatorKeys() { final List<Pair<Path, Path>> keystorePasswordFilePairs = config.getValidatorKeystorePasswordFilePairs(); checkNotNull(keystorePasswordFilePairs, "validator keystore and password pairs cannot be null"); final int totalValidatorCount = keystorePasswordFilePairs.size(); StatusLogger.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<Bytes32>> futures = keystorePasswordFilePairs.stream() .map( pair -> executorService.submit( () -> { Bytes32 privateKey = loadBLSPrivateKey(pair.getLeft(), loadPassword(pair.getRight())); int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet(); if (loadedValidatorCount % 10 == 0) { StatusLogger.STATUS_LOG.atLoadedValidatorNumber( loadedValidatorCount, totalValidatorCount); } return privateKey; })) .collect(toList()); Set<Bytes32> result = new HashSet<>(); for (Future<Bytes32> future : futures) { result.add(future.get()); } return result.stream() .map(privKey -> new BLSKeyPair(BLSSecretKey.fromBytes(privKey))) .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(); } } KeystoresValidatorKeyProvider(
      final KeystoreLocker keystoreLocker, final ValidatorConfig config); @Override List<BLSKeyPair> loadValidatorKeys(); }
KeystoresValidatorKeyProvider implements ValidatorKeyProvider { @Override public List<BLSKeyPair> loadValidatorKeys() { final List<Pair<Path, Path>> keystorePasswordFilePairs = config.getValidatorKeystorePasswordFilePairs(); checkNotNull(keystorePasswordFilePairs, "validator keystore and password pairs cannot be null"); final int totalValidatorCount = keystorePasswordFilePairs.size(); StatusLogger.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<Bytes32>> futures = keystorePasswordFilePairs.stream() .map( pair -> executorService.submit( () -> { Bytes32 privateKey = loadBLSPrivateKey(pair.getLeft(), loadPassword(pair.getRight())); int loadedValidatorCount = numberOfLoadedKeys.incrementAndGet(); if (loadedValidatorCount % 10 == 0) { StatusLogger.STATUS_LOG.atLoadedValidatorNumber( loadedValidatorCount, totalValidatorCount); } return privateKey; })) .collect(toList()); Set<Bytes32> result = new HashSet<>(); for (Future<Bytes32> future : futures) { result.add(future.get()); } return result.stream() .map(privKey -> new BLSKeyPair(BLSSecretKey.fromBytes(privKey))) .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(); } } KeystoresValidatorKeyProvider(
      final KeystoreLocker keystoreLocker, final ValidatorConfig config); @Override List<BLSKeyPair> loadValidatorKeys();  }