Search in sources :

Example 1 with InvalidConfigurationException

use of tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException in project teku by ConsenSys.

the class SyncDataAccessor method create.

public static SyncDataAccessor create(final Path path) {
    boolean atomicFileMoveSupport = false;
    final Path tmpFile;
    if (Files.isDirectory(path.toAbsolutePath())) {
        tmpFile = path.toAbsolutePath().resolve("syncWriteTest.tmp");
    } else {
        tmpFile = path.toAbsolutePath().getParent().resolve("syncWriteTest.tmp");
    }
    try {
        atomicSyncedWrite(tmpFile, Bytes32.ZERO);
        atomicFileMoveSupport = true;
    } catch (AtomicMoveNotSupportedException e) {
        LOG.debug("File system doesn't support atomic move");
        atomicFileMoveSupport = false;
    } catch (IOException e) {
        LOG.error(String.format("Failed to write in %s", path), e);
        throw new InvalidConfigurationException(String.format("Cannot write to folder %s", path), e);
    } finally {
        try {
            Files.deleteIfExists(tmpFile);
        } catch (IOException e) {
            LOG.debug("Failed to delete the temporary file ", e);
        }
    }
    return new SyncDataAccessor(atomicFileMoveSupport);
}
Also used : Path(java.nio.file.Path) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) IOException(java.io.IOException) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Example 2 with InvalidConfigurationException

use of tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException in project teku by ConsenSys.

the class BeaconNodeCommand method call.

@Override
public Integer call() {
    try {
        startLogging();
        final TekuConfiguration tekuConfig = tekuConfiguration();
        startAction.start(tekuConfig, false);
        return 0;
    } catch (InvalidConfigurationException | DatabaseStorageException ex) {
        reportUserError(ex);
    } catch (CompletionException e) {
        ExceptionUtil.<Throwable>getCause(e, InvalidConfigurationException.class).or(() -> ExceptionUtil.getCause(e, DatabaseStorageException.class)).ifPresentOrElse(this::reportUserError, () -> reportUnexpectedError(e));
    } catch (Throwable t) {
        reportUnexpectedError(t);
    }
    return 1;
}
Also used : DatabaseStorageException(tech.pegasys.teku.storage.server.DatabaseStorageException) TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) CompletionException(java.util.concurrent.CompletionException) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Example 3 with InvalidConfigurationException

use of tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException in project teku by ConsenSys.

the class KeyStoreFilesLocator method parseEntry.

private void parseEntry(final String keyFileName, final String passwordFileName, Map<Path, Path> pathMap) {
    final File keyFile = new File(keyFileName);
    final File passwordFile = new File(passwordFileName);
    if (!keyFile.exists()) {
        throw new InvalidConfigurationException(String.format("Invalid configuration. Could not find the key file (%s).", keyFileName));
    }
    if (isDepositDataFile(keyFile)) {
        return;
    }
    if (!passwordFile.exists()) {
        throw new InvalidConfigurationException(String.format("Invalid configuration. Could not find the password file (%s).", passwordFileName));
    }
    if (keyFile.isDirectory() != passwordFile.isDirectory()) {
        throw new InvalidConfigurationException(String.format("Invalid configuration. --validator-keys entry (%s" + pathSeparator + "%s) must be both directories or both files", keyFileName, passwordFileName));
    }
    if (keyFile.isFile()) {
        pathMap.putIfAbsent(keyFile.toPath(), passwordFile.toPath());
    } else {
        parseDirectory(keyFile, passwordFile, pathMap);
    }
}
Also used : File(java.io.File) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Example 4 with InvalidConfigurationException

use of tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException 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 InvalidConfigurationException

use of tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException in project teku by ConsenSys.

the class BeaconChainController method setupInitialState.

protected void setupInitialState(final RecentChainData client) {
    final Optional<AnchorPoint> initialAnchor = wsInitializer.loadInitialAnchorPoint(spec, beaconConfig.eth2NetworkConfig().getInitialState());
    // Validate
    initialAnchor.ifPresent(anchor -> {
        final UInt64 currentSlot = getCurrentSlot(anchor.getState().getGenesis_time());
        wsInitializer.validateInitialAnchor(anchor, currentSlot, spec);
    });
    if (initialAnchor.isPresent()) {
        final AnchorPoint anchor = initialAnchor.get();
        client.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds());
        if (anchor.isGenesis()) {
            EVENT_LOG.genesisEvent(anchor.getStateRoot(), recentChainData.getBestBlockRoot().orElseThrow(), anchor.getState().getGenesis_time());
        }
    } else if (beaconConfig.interopConfig().isInteropEnabled()) {
        setupInteropState();
    } else if (!beaconConfig.powchainConfig().isEnabled()) {
        throw new InvalidConfigurationException("ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state.");
    }
}
Also used : AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)21 IOException (java.io.IOException)9 Path (java.nio.file.Path)6 File (java.io.File)3 TekuConfiguration (tech.pegasys.teku.config.TekuConfiguration)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 UncheckedIOException (java.io.UncheckedIOException)2 URL (java.net.URL)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyStore (java.security.KeyStore)2 CompletionException (java.util.concurrent.CompletionException)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)2 DatabaseStorageException (tech.pegasys.teku.storage.server.DatabaseStorageException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Splitter (com.google.common.base.Splitter)1 PeerId (io.libp2p.core.PeerId)1