use of tech.pegasys.teku.service.serviceutils.layout.DataDirLayout in project teku by ConsenSys.
the class DatabaseMigraterTest method shouldOpenDatabases.
@Test
void shouldOpenDatabases(@TempDir Path tmpDir) throws IOException, DatabaseMigraterError {
final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "5");
final DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
migrater.openDatabases(DatabaseVersion.V5, DatabaseVersion.LEVELDB2);
migrater.closeDatabases();
assertThat(tmpDir.resolve("beacon").toFile().isDirectory()).isTrue();
assertThat(tmpDir.resolve("beacon.new").toFile().isDirectory()).isTrue();
assertThat(tmpDir.resolve("beacon.old").toFile().isDirectory()).isFalse();
assertThat(dbVersionInPath(dataDirLayout.getBeaconDataDirectory())).isEqualTo("5");
assertThat(dbVersionInPath(migrater.getNewBeaconFolderPath())).isEqualTo("leveldb2");
}
use of tech.pegasys.teku.service.serviceutils.layout.DataDirLayout in project teku by ConsenSys.
the class DatabaseMigraterTest method shouldCreateNewDatabaseFolderStructure.
@Test
void shouldCreateNewDatabaseFolderStructure(@TempDir Path tmpDir) throws IOException {
final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "leveldb1");
final Path generatedDatabase = tmpDir.resolve("beacon.new");
final DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
migrater.duplicateBeaconFolderContents();
assertThat(generatedDatabase.toFile().isDirectory()).isTrue();
assertThat(generatedDatabase.resolve("network.yml").toFile().isFile()).isTrue();
final Path kvStore = generatedDatabase.resolve("kvstore");
assertThat(kvStore.toFile().isDirectory()).isTrue();
assertThat(kvStore.resolve("local-enr-seqno.dat").toFile().isFile()).isTrue();
}
use of tech.pegasys.teku.service.serviceutils.layout.DataDirLayout in project teku by ConsenSys.
the class DatabaseMigraterTest method shouldSupplyNewDatabasePath.
@Test
void shouldSupplyNewDatabasePath(@TempDir Path tmpDir) throws IOException {
final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "leveldb1");
final DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
assertThat(migrater.getNewBeaconFolderPath()).isEqualTo(tmpDir.resolve("beacon.new"));
}
use of tech.pegasys.teku.service.serviceutils.layout.DataDirLayout in project teku by ConsenSys.
the class ExternalValidatorSource method addValidator.
@Override
public AddValidatorResult addValidator(final BLSPublicKey publicKey, final Optional<URL> signerUrl) {
if (!canUpdateValidators()) {
return new AddValidatorResult(PostKeyResult.error("Cannot add validator to a read only source."), Optional.empty());
}
final DataDirLayout dataDirLayout = maybeDataDirLayout.orElseThrow();
final String fileName = publicKey.toBytesCompressed().toUnprefixedHexString();
final Path path = ValidatorClientService.getManagedRemoteKeyPath(dataDirLayout).resolve(fileName + ".json");
try {
ensureDirectoryExists(ValidatorClientService.getManagedRemoteKeyPath(dataDirLayout));
if (path.toFile().exists()) {
return new AddValidatorResult(PostKeyResult.duplicate(), Optional.empty());
}
Files.write(path, serialize(new ExternalValidator(publicKey, signerUrl), ValidatorTypes.EXTERNAL_VALIDATOR_STORE).getBytes(UTF_8));
final URL url = signerUrl.orElse(config.getValidatorExternalSignerUrl());
final ValidatorProvider provider = new ExternalValidatorProvider(spec, externalSignerHttpClientFactory, url, publicKey, config.getValidatorExternalSignerTimeout(), externalSignerTaskQueue, metricsSystem, readOnly);
externalValidatorSourceMap.put(publicKey, url);
return new AddValidatorResult(PostKeyResult.success(), Optional.of(provider.createSigner()));
} catch (InvalidConfigurationException | IOException ex) {
cleanupIncompleteSave(path);
return new AddValidatorResult(PostKeyResult.error(ex.getMessage()), Optional.empty());
}
}
use of tech.pegasys.teku.service.serviceutils.layout.DataDirLayout in project teku by ConsenSys.
the class LocalValidatorSource method getPasswordPath.
private Path getPasswordPath(final BLSPublicKey publicKey) {
final DataDirLayout dataDirLayout = maybeDataDirLayout.orElseThrow();
final String fileName = publicKey.toBytesCompressed().toUnprefixedHexString();
return ValidatorClientService.getManagedLocalKeystorePasswordPath(dataDirLayout).resolve(fileName + ".txt");
}
Aggregations