Search in sources :

Example 1 with DataDirLayout

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");
}
Also used : DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Test(org.junit.jupiter.api.Test)

Example 2 with DataDirLayout

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();
}
Also used : Path(java.nio.file.Path) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Test(org.junit.jupiter.api.Test)

Example 3 with DataDirLayout

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"));
}
Also used : DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Test(org.junit.jupiter.api.Test)

Example 4 with DataDirLayout

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());
    }
}
Also used : Path(java.nio.file.Path) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) IOException(java.io.IOException) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) URL(java.net.URL) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Example 5 with DataDirLayout

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");
}
Also used : DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)

Aggregations

DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)23 Test (org.junit.jupiter.api.Test)14 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)13 Path (java.nio.file.Path)10 IOException (java.io.IOException)6 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)5 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 URL (java.net.URL)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Validator (tech.pegasys.teku.validator.client.Validator)3 Charsets (com.google.common.base.Charsets)2 HttpClient (java.net.http.HttpClient)2 HttpResponse (java.net.http.HttpResponse)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Files.createTempFile (java.nio.file.Files.createTempFile)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Supplier (java.util.function.Supplier)2