Search in sources :

Example 1 with TestSlashingProtectionParameters

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();
}
Also used : TestDatabaseInfo(db.DatabaseUtil.TestDatabaseInfo) TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters)

Example 2 with TestSlashingProtectionParameters

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);
}
Also used : TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TestSlashingProtectionParameters

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)));
}
Also used : SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) SignedAttestation(tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation) SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TestSlashingProtectionParameters

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));
}
Also used : TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TestSlashingProtectionParameters

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) TestSlashingProtectionParameters(dsl.TestSlashingProtectionParameters) Test(org.junit.jupiter.api.Test)

Aggregations

TestSlashingProtectionParameters (dsl.TestSlashingProtectionParameters)12 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 TestDatabaseInfo (db.DatabaseUtil.TestDatabaseInfo)3 LocalDateTime (java.time.LocalDateTime)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SignedAttestation (tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 SignedBlock (tech.pegasys.web3signer.slashingprotection.dao.SignedBlock)1 SigningWatermark (tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark)1