use of dsl.InterchangeV5Format in project web3signer by ConsenSys.
the class InterchangeExportIntegrationTestBase method onlyExportBlocksWithSlotEqualToOrGreaterThanEpoch.
@Test
void onlyExportBlocksWithSlotEqualToOrGreaterThanEpoch() throws IOException {
final int TOTAL_BLOCKS_SIGNED = 6;
final UInt64 BLOCK_SLOT_WATER_MARK = UInt64.valueOf(3);
final Bytes validatorPublicKey = Bytes.of(1);
slashingProtectionContext.getRegisteredValidators().registerValidators(List.of(validatorPublicKey));
for (int b = 0; b < TOTAL_BLOCKS_SIGNED; b++) {
insertBlockAt(UInt64.valueOf(b), 1);
}
jdbi.useTransaction(h -> lowWatermarkDao.updateSlotWatermarkFor(h, 1, BLOCK_SLOT_WATER_MARK));
final InterchangeV5Format outputObject = getExportObjectFromDatabase();
assertThat(outputObject.getSignedArtifacts()).hasSize(1);
assertThat(outputObject.getSignedArtifacts().get(0).getSignedBlocks()).hasSize(TOTAL_BLOCKS_SIGNED - BLOCK_SLOT_WATER_MARK.intValue());
final Optional<UInt64> minBlockSlotInExport = outputObject.getSignedArtifacts().get(0).getSignedBlocks().stream().map(SignedBlock::getSlot).min(UInt64::compareTo);
assertThat(minBlockSlotInExport).isNotEmpty();
assertThat(minBlockSlotInExport.get()).isEqualTo(BLOCK_SLOT_WATER_MARK);
}
use of dsl.InterchangeV5Format in project web3signer by ConsenSys.
the class SlashingExportAcceptanceTest method slashingDataIsExported.
@Test
void slashingDataIsExported(@TempDir Path testDirectory) throws IOException {
setupSigner(testDirectory, true);
final Eth2SigningRequestBody request = createAttestationRequest(5, 6, UInt64.ZERO);
final Response initialResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), request);
assertThat(initialResponse.getStatusCode()).isEqualTo(200);
assertThat(signer.getMetricsMatching(blockSlashingMetrics)).containsOnly(blockSlashingMetrics.get(0) + " 1.0", blockSlashingMetrics.get(1) + " 0.0");
final Path exportFile = testDirectory.resolve("dbExport.json");
final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
builder.withMode("eth2");
builder.withSlashingEnabled(true);
builder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
builder.withSlashingProtectionDbUsername("postgres");
builder.withSlashingProtectionDbPassword("postgres");
builder.withKeyStoreDirectory(testDirectory);
builder.withSlashingExportPath(exportFile);
// prevent wait for Ports file in AT
builder.withHttpPort(12345);
final Signer exportSigner = new Signer(builder.build(), null);
exportSigner.start();
waitFor(() -> assertThat(exportSigner.isRunning()).isFalse());
final ObjectMapper mapper = new InterchangeJsonProvider().getJsonMapper();
final InterchangeV5Format mappedData = mapper.readValue(exportFile.toFile(), InterchangeV5Format.class);
assertThat(mappedData.getMetadata().getFormatVersion()).isEqualTo("5");
assertThat(mappedData.getMetadata().getGenesisValidatorsRoot()).isEqualTo(Bytes.fromHexString(GENESIS_VALIDATORS_ROOT));
assertThat(mappedData.getSignedArtifacts()).hasSize(1);
final SignedArtifacts artifacts = mappedData.getSignedArtifacts().get(0);
assertThat(artifacts.getSignedBlocks()).hasSize(0);
assertThat(artifacts.getSignedAttestations()).hasSize(1);
final SignedAttestation attestation = artifacts.getSignedAttestations().get(0);
assertThat(attestation.getSourceEpoch().toLong()).isEqualTo(request.getAttestation().source.epoch.longValue());
assertThat(attestation.getTargetEpoch().toLong()).isEqualTo(request.getAttestation().target.epoch.longValue());
assertThat(attestation.getSigningRoot()).isNotNull();
}
use of dsl.InterchangeV5Format in project web3signer by ConsenSys.
the class SlashingImportAcceptanceTest method slashingDataIsImported.
@Test
void slashingDataIsImported(@TempDir Path testDirectory) throws URISyntaxException, IOException {
setupSigner(testDirectory, true);
final Path importFile = new File(Resources.getResource("slashing/slashingImport.json").toURI()).toPath();
final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
builder.withMode("eth2");
builder.withSlashingEnabled(true);
builder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
builder.withSlashingProtectionDbUsername("postgres");
builder.withSlashingProtectionDbPassword("postgres");
builder.withKeyStoreDirectory(testDirectory);
builder.withSlashingImportPath(importFile);
// prevent wait for Ports file in AT
builder.withHttpPort(12345);
final Signer importSigner = new Signer(builder.build(), null);
importSigner.start();
waitFor(() -> assertThat(importSigner.isRunning()).isFalse());
final InterchangeV5Format interchangeData = objectMapper.readValue(importFile.toFile(), InterchangeV5Format.class);
final Jdbi jdbi = Jdbi.create(signer.getSlashingDbUrl(), DB_USERNAME, DB_PASSWORD);
final int validatorId = 1;
final Map<String, Object> metadata = jdbi.withHandle(h -> h.select("SELECT * from metadata").mapToMap().one());
assertThat(metadata.get("id")).isEqualTo(validatorId);
assertThat(metadata.get("genesis_validators_root")).isEqualTo(interchangeData.getMetadata().getGenesisValidatorsRoot().toArray());
final SignedArtifacts artifacts = interchangeData.getSignedArtifacts().get(0);
final List<Map<String, Object>> validators = jdbi.withHandle(h -> h.select("SELECT * from validators").mapToMap().list());
assertThat(validators).hasSize(1);
assertThat(validators.get(0).get("id")).isEqualTo(validatorId);
assertThat(validators.get(0).get("public_key")).isEqualTo(Bytes.fromHexString(artifacts.getPublicKey()).toArray());
final List<Map<String, Object>> signedAttestations = jdbi.withHandle(h -> h.select("SELECT * from signed_attestations").mapToMap().list());
final SignedAttestation attestation = artifacts.getSignedAttestations().get(0);
assertThat(signedAttestations).hasSize(1);
assertThat(signedAttestations.get(0).get("validator_id")).isEqualTo(validatorId);
assertThat(signedAttestations.get(0).get("source_epoch")).isEqualTo(BigDecimal.valueOf(attestation.getSourceEpoch().toLong()));
assertThat(signedAttestations.get(0).get("target_epoch")).isEqualTo(BigDecimal.valueOf(attestation.getTargetEpoch().toLong()));
assertThat(signedAttestations.get(0).get("signing_root")).isEqualTo(attestation.getSigningRoot().toArray());
final List<Map<String, Object>> signedBlocks = jdbi.withHandle(h -> h.select("SELECT * from signed_blocks").mapToMap().list());
final SignedBlock block = artifacts.getSignedBlocks().get(0);
assertThat(signedBlocks).hasSize(1);
assertThat(signedBlocks.get(0).get("validator_id")).isEqualTo(validatorId);
assertThat(signedBlocks.get(0).get("slot")).isEqualTo(BigDecimal.valueOf(block.getSlot().toLong()));
assertThat(signedBlocks.get(0).get("signing_root")).isEqualTo(block.getSigningRoot().toArray());
}
use of dsl.InterchangeV5Format in project web3signer by ConsenSys.
the class InterchangeExportIntegrationTestBase method onlyAttestationsWhichAreAboveBothSourceAndTargetWatermarksAreImportedTargetOnly.
@Test
void onlyAttestationsWhichAreAboveBothSourceAndTargetWatermarksAreImportedTargetOnly() throws IOException {
final Bytes validatorPublicKey = Bytes.of(1);
slashingProtectionContext.getRegisteredValidators().registerValidators(List.of(validatorPublicKey));
final int TOTAL_ATTESTATIONS_SIGNED = 6;
final int EPOCH_OFFSET = 10;
final UInt64 ATTESTATION_SLOT_WATER_MARK = UInt64.valueOf(12);
for (int a = 0; a < TOTAL_ATTESTATIONS_SIGNED; a++) {
insertAttestationAt(UInt64.valueOf(a), UInt64.valueOf(a + EPOCH_OFFSET), 1);
}
// this is an illegal watermark, but means no checks will fail against the source epoch.
jdbi.useTransaction(h -> lowWatermarkDao.updateEpochWatermarksFor(h, 1, UInt64.valueOf(0), ATTESTATION_SLOT_WATER_MARK));
final InterchangeV5Format outputObject = getExportObjectFromDatabase();
assertThat(outputObject.getSignedArtifacts()).hasSize(1);
assertThat(outputObject.getSignedArtifacts().get(0).getSignedAttestations()).hasSize(TOTAL_ATTESTATIONS_SIGNED + EPOCH_OFFSET - ATTESTATION_SLOT_WATER_MARK.intValue());
}
use of dsl.InterchangeV5Format in project web3signer by ConsenSys.
the class InterchangeExportIntegrationTestBase method onlyAttestationsWhichAreAboveBothSourceAndTargetWatermarksAreImported.
@Test
void onlyAttestationsWhichAreAboveBothSourceAndTargetWatermarksAreImported() throws IOException {
final Bytes validatorPublicKey = Bytes.of(1);
slashingProtectionContext.getRegisteredValidators().registerValidators(List.of(validatorPublicKey));
final int TOTAL_ATTESTATIONS_SIGNED = 6;
final int EPOCH_OFFSET = 10;
final UInt64 ATTESTATION_SLOT_WATER_MARK = UInt64.valueOf(3);
for (int a = 0; a < TOTAL_ATTESTATIONS_SIGNED; a++) {
insertAttestationAt(UInt64.valueOf(a), UInt64.valueOf(a + EPOCH_OFFSET), 1);
}
// this is an illegal watermark, but means no checks will fail against the target epoch.
jdbi.useTransaction(h -> lowWatermarkDao.updateEpochWatermarksFor(h, 1, ATTESTATION_SLOT_WATER_MARK, UInt64.valueOf(0)));
final InterchangeV5Format outputObject = getExportObjectFromDatabase();
assertThat(outputObject.getSignedArtifacts()).hasSize(1);
assertThat(outputObject.getSignedArtifacts().get(0).getSignedAttestations()).hasSize(TOTAL_ATTESTATIONS_SIGNED - ATTESTATION_SLOT_WATER_MARK.intValue());
}
Aggregations