use of tech.pegasys.teku.api.schema.PublicKeyException in project teku by ConsenSys.
the class SlashingProtectionExporter method readSlashProtectionFile.
// returns an error if there was one
Optional<String> readSlashProtectionFile(final File file, final Consumer<String> infoLogger) {
try {
Optional<ValidatorSigningRecord> maybeRecord = syncDataAccessor.read(file.toPath()).map(ValidatorSigningRecord::fromBytes);
if (maybeRecord.isEmpty()) {
return Optional.of("Failed to read from file " + file.getName());
}
ValidatorSigningRecord validatorSigningRecord = maybeRecord.get();
if (validatorSigningRecord.getGenesisValidatorsRoot() != null) {
if (genesisValidatorsRoot == null) {
this.genesisValidatorsRoot = validatorSigningRecord.getGenesisValidatorsRoot();
} else if (!genesisValidatorsRoot.equals(validatorSigningRecord.getGenesisValidatorsRoot())) {
return Optional.of("The genesisValidatorsRoot of " + file.getName() + " does not match the expected " + genesisValidatorsRoot.toHexString());
}
}
final String pubkey = file.getName().substring(0, file.getName().length() - ".yml".length());
infoLogger.accept("Exporting " + pubkey);
signingHistoryList.add(new SigningHistory(BLSPubKey.fromHexString(pubkey), validatorSigningRecord));
return Optional.empty();
} catch (UncheckedIOException | IOException e) {
return Optional.of("Failed to read from file " + file);
} catch (PublicKeyException e) {
return Optional.of("Public key in file " + file.getName() + " does not appear valid.");
}
}
use of tech.pegasys.teku.api.schema.PublicKeyException in project teku by ConsenSys.
the class SlashingProtectionRepairer method readSlashProtectionFile.
private void readSlashProtectionFile(final File file) {
final String filePrefix = file.getName().substring(0, file.getName().length() - ".yml".length());
try {
BLSPubKey pubkey = BLSPubKey.fromHexString(filePrefix);
Optional<ValidatorSigningRecord> maybeRecord = syncDataAccessor.read(file.toPath()).map(ValidatorSigningRecord::fromBytes);
if (maybeRecord.isEmpty() && invalidRecords.add(filePrefix)) {
log.display(filePrefix + ": Empty slashing protection record");
return;
}
if (updateAllEnabled) {
log.display(filePrefix + ": looks valid");
}
ValidatorSigningRecord validatorSigningRecord = maybeRecord.get();
signingHistoryList.add(new SigningHistory(pubkey, validatorSigningRecord));
} catch (PublicKeyException e) {
log.display(" --- " + file.getName() + " - invalid public key - ignoring file");
} catch (Exception e) {
if (invalidRecords.add(filePrefix)) {
log.display(filePrefix + ": Incomplete or invalid slashing protection data");
}
}
}
Aggregations