use of tech.pegasys.teku.data.slashinginterchange.SignedBlock in project teku by ConsenSys.
the class SlashingProtectionImporter method signingHistoryConverter.
private SigningHistory signingHistoryConverter(final SigningHistory signingHistory) {
final Optional<UInt64> lastSlot = signingHistory.signedBlocks.stream().map(SignedBlock::getSlot).filter(Objects::nonNull).max(UInt64::compareTo);
final Optional<UInt64> sourceEpoch = signingHistory.signedAttestations.stream().map(SignedAttestation::getSourceEpoch).filter(Objects::nonNull).max(UInt64::compareTo);
final Optional<UInt64> targetEpoch = signingHistory.signedAttestations.stream().map(SignedAttestation::getTargetEpoch).filter(Objects::nonNull).max(UInt64::compareTo);
final ValidatorSigningRecord record = new ValidatorSigningRecord(metadata.genesisValidatorsRoot, lastSlot.orElse(UInt64.ZERO), sourceEpoch.orElse(ValidatorSigningRecord.NEVER_SIGNED), targetEpoch.orElse(ValidatorSigningRecord.NEVER_SIGNED));
return new SigningHistory(signingHistory.pubkey, record);
}
use of tech.pegasys.teku.data.slashinginterchange.SignedBlock in project teku by ConsenSys.
the class SlashingProtectionExporterTest method shouldHaveNoSignedAttestationsWhenNoAttestationsSigned.
@Test
void shouldHaveNoSignedAttestationsWhenNoAttestationsSigned(@TempDir Path tempDir) throws Exception {
final Path exportedFile = tempDir.resolve("exportedFile.json").toAbsolutePath();
final SlashingProtectionExporter exporter = new SlashingProtectionExporter(tempDir);
final UInt64 blockSlot = UInt64.ONE;
final ValidatorSigningRecord signingRecord = new ValidatorSigningRecord(validatorsRoot).maySignBlock(validatorsRoot, blockSlot).orElseThrow();
final Path recordFile = tempDir.resolve(pubkey + ".yml");
Files.write(recordFile, signingRecord.toBytes().toArrayUnsafe());
final Optional<String> error = exporter.readSlashProtectionFile(recordFile.toFile(), LOG::debug);
assertThat(error).isEmpty();
assertThat(exportedFile).doesNotExist();
exporter.saveToFile(exportedFile.toString(), LOG::debug);
assertThat(exportedFile).exists();
final SlashingProtectionInterchangeFormat exportedRecords = jsonProvider.jsonToObject(Files.readString(exportedFile), SlashingProtectionInterchangeFormat.class);
assertThat(exportedRecords.data).hasSize(1);
final SigningHistory signingHistory = exportedRecords.data.get(0);
assertThat(signingHistory.signedBlocks).containsExactly(new SignedBlock(blockSlot, null));
assertThat(signingHistory.signedAttestations).isEmpty();
}
Aggregations