use of dsl.TestSlashingProtectionParameters in project web3signer by ConsenSys.
the class ReferenceTestRunner method setup.
public void setup() {
final TestDatabaseInfo testDatabaseInfo = DatabaseUtil.create();
final SlashingProtectionParameters slashingProtectionParameters = new TestSlashingProtectionParameters(testDatabaseInfo.databaseUrl(), USERNAME, PASSWORD);
slashingProtectionContext = SlashingProtectionContextFactory.create(slashingProtectionParameters);
slashingDatabase = testDatabaseInfo.getDb();
jdbi = testDatabaseInfo.getJdbi();
}
use of dsl.TestSlashingProtectionParameters in project web3signer by ConsenSys.
the class PruningIntegrationTest method dataUnchangedForNonRegisteredValidators.
@Test
void dataUnchangedForNonRegisteredValidators() {
final SlashingProtectionContext slashingProtectionContext = SlashingProtectionContextFactory.create(new TestSlashingProtectionParameters(databaseUrl, USERNAME, PASSWORD, 1, 1));
jdbi.withHandle(h -> validators.registerValidators(h, List.of(Bytes.of(1))));
createSlashingData(2, 2, 1);
insertValidatorAndCreateSlashingData(slashingProtectionContext.getRegisteredValidators(), 2, 2, 2);
slashingProtectionContext.getSlashingProtection().prune();
final List<SignedAttestation> attestationsForValidator1 = fetchAttestations(1);
assertThat(attestationsForValidator1).hasSize(2);
final List<SignedAttestation> attestationsForValidator2 = fetchAttestations(2);
assertThat(attestationsForValidator2).hasSize(1);
}
use of dsl.TestSlashingProtectionParameters in project web3signer by ConsenSys.
the class PruningIntegrationTest method prunesDataForRegisteredValidator.
@ParameterizedTest
@CsvSource({ "1, 1, 9, 9", "5, 1, 5, 5", "9, 1, 1, 1, 1", "10, 1, 0, 0", "20, 1, 0, 0", "1, 2, 9, 8", "3, 2, 7, 4" })
void prunesDataForRegisteredValidator(final int amountToKeep, final int slotsPerEpoch, final int expectedLowestPopulatedEpoch, final int expectedLowestPopulatedSlot) {
final SlashingProtectionContext slashingProtectionContext = SlashingProtectionContextFactory.create(new TestSlashingProtectionParameters(databaseUrl, USERNAME, PASSWORD, amountToKeep, slotsPerEpoch));
final int size = 10;
insertValidatorAndCreateSlashingData(slashingProtectionContext.getRegisteredValidators(), size, size, 1);
final List<SignedAttestation> allAttestations = fetchAttestations(1);
final List<SignedBlock> allBlocks = fetchBlocks(1);
slashingProtectionContext.getSlashingProtection().prune();
final List<SignedAttestation> expectedAttestations = allAttestations.subList(expectedLowestPopulatedEpoch, size);
final List<SignedAttestation> attestationsInDatabase = fetchAttestations(1);
assertThat(attestationsInDatabase).usingFieldByFieldElementComparator().isEqualTo(expectedAttestations);
final List<SignedBlock> expectedBlocks = allBlocks.subList(expectedLowestPopulatedSlot, size);
final List<SignedBlock> blocks = fetchBlocks(1);
assertThat(blocks).usingFieldByFieldElementComparator().isEqualTo(expectedBlocks);
assertThat(getWatermark(1)).isEqualToComparingFieldByField(new SigningWatermark(1, UInt64.valueOf(expectedLowestPopulatedSlot), UInt64.valueOf(expectedLowestPopulatedEpoch), UInt64.valueOf(expectedLowestPopulatedEpoch)));
}
use of dsl.TestSlashingProtectionParameters in project web3signer by ConsenSys.
the class PruningIntegrationTest method prunesForDataWithGaps.
@Test
void prunesForDataWithGaps() {
final SlashingProtectionContext slashingProtectionContext = SlashingProtectionContextFactory.create(new TestSlashingProtectionParameters(databaseUrl, USERNAME, PASSWORD, 5, 1));
slashingProtectionContext.getRegisteredValidators().registerValidators(List.of(Bytes.of(1)));
for (int i = 0; i < 2; i++) {
insertAttestationAt(UInt64.valueOf(i), UInt64.valueOf(i + 1), 1);
insertBlockAt(UInt64.valueOf(i), 1);
}
for (int i = 8; i < 10; i++) {
insertAttestationAt(UInt64.valueOf(i), UInt64.valueOf(i + 1), 1);
insertBlockAt(UInt64.valueOf(i), 1);
}
jdbi.useTransaction(h -> {
lowWatermarkDao.updateSlotWatermarkFor(h, 1, UInt64.ZERO);
lowWatermarkDao.updateEpochWatermarksFor(h, 1, UInt64.ZERO, UInt64.ZERO);
});
slashingProtectionContext.getSlashingProtection().prune();
assertThat(fetchAttestations(1)).hasSize(2);
assertThat(fetchBlocks(1)).hasSize(2);
assertThat(getWatermark(1).getSlot()).isEqualTo(UInt64.valueOf(8));
assertThat(getWatermark(1).getSourceEpoch()).isEqualTo(UInt64.valueOf(8));
assertThat(getWatermark(1).getTargetEpoch()).isEqualTo(UInt64.valueOf(9));
}
use of dsl.TestSlashingProtectionParameters in project web3signer by ConsenSys.
the class PruningRunnerIntegrationTest method prunesValidatorsForScheduledRunAreRunPeriodically.
@Test
void prunesValidatorsForScheduledRunAreRunPeriodically() {
final SlashingProtectionParameters slashingProtectionParameters = new TestSlashingProtectionParameters(databaseUrl, USERNAME, PASSWORD, 5, 1, 1);
final TestSlashingProtection testSlashingProtection = new TestSlashingProtection(pruningSlashingProtectionContext.getSlashingProtection(), createPrunerRunnerThatFailsOnFirstRun());
final DbPrunerRunner dbPrunerRunner = new DbPrunerRunner(slashingProtectionParameters, testSlashingProtection, scheduledExecutorService);
dbPrunerRunner.schedule();
final List<PruningStat> pruningStats = testSlashingProtection.getPruningStats();
waitForPruningToFinish(pruningStats, 3);
assertThat(pruningStats.stream().allMatch(ps -> ps.getThread().getName().equals(PRUNING_THREAD_NAME))).isTrue();
final LocalDateTime firstPruningStartTime = pruningStats.get(0).getStartTime();
assertThat(pruningStats.get(1).getStartTime()).isEqualToIgnoringNanos(firstPruningStartTime.plusSeconds(1));
assertThat(pruningStats.get(2).getStartTime()).isEqualToIgnoringNanos(firstPruningStartTime.plusSeconds(2));
assertThat(fetchAttestations(1)).hasSize(5);
assertThat(fetchBlocks(1)).hasSize(5);
}
Aggregations