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);
}
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;
}
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);
}
}
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());
}
}
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.");
}
}
Aggregations