Search in sources :

Example 1 with SignedBlock

use of tech.pegasys.web3signer.slashingprotection.dao.SignedBlock in project web3signer by ConsenSys.

the class BlockValidator method persist.

public void persist() {
    final SignedBlock signedBlock = new SignedBlock(validatorId, blockSlot, signingRoot);
    signedBlocksDao.insertBlockProposal(handle, signedBlock);
    // update the watermark if is otherwise blank
    if (watermarkSupplier.get().isEmpty() || (watermarkSupplier.get().get().getSlot() == null)) {
        lowWatermarkDao.updateSlotWatermarkFor(handle, validatorId, blockSlot);
    }
}
Also used : SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock)

Example 2 with SignedBlock

use of tech.pegasys.web3signer.slashingprotection.dao.SignedBlock in project web3signer by ConsenSys.

the class DbSlashingProtectionTest method blockCannotBeSignedIfMatchesBlockBelowWatermark.

@Test
public void blockCannotBeSignedIfMatchesBlockBelowWatermark() {
    final SignedBlock signedBlock = new SignedBlock(VALIDATOR_ID, SLOT, SIGNING_ROOT);
    when(lowWatermarkDao.findLowWatermarkForValidator(any(), anyInt())).thenReturn(Optional.of(new SigningWatermark(VALIDATOR_ID, SLOT.add(1L), null, null)));
    assertThat(dbSlashingProtection.maySignBlock(PUBLIC_KEY1, SIGNING_ROOT, SLOT, GVR)).isFalse();
    verify(signedBlocksDao, never()).insertBlockProposal(any(), refEq(signedBlock));
    verify(lowWatermarkDao).findLowWatermarkForValidator(any(), eq(VALIDATOR_ID));
}
Also used : SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock) Test(org.junit.jupiter.api.Test)

Example 3 with SignedBlock

use of tech.pegasys.web3signer.slashingprotection.dao.SignedBlock in project web3signer by ConsenSys.

the class InterchangeImportConflictsIntegrationTestBase method conflictingBlocksInSameSlotAreNotInsertedToDatabase.

@Test
void conflictingBlocksInSameSlotAreNotInsertedToDatabase() throws IOException {
    final URL importFile = Resources.getResource("interchange/conflictingBlocks.json");
    slashingProtectionContext.getSlashingProtection().importData(importFile.openStream());
    final List<SignedBlock> blocksInDb = findAllBlocks();
    assertThat(blocksInDb).hasSize(1);
    assertThat(blocksInDb.get(0).getSlot()).isEqualTo(UInt64.valueOf(12345));
    assertThat(blocksInDb.get(0).getValidatorId()).isEqualTo(1);
    assertThat(blocksInDb.get(0).getSigningRoot()).isEqualTo(Optional.of(Bytes.fromHexString("0x4ff6f743a43f3b4f95350831aeaf0a122a1a392922c45d804280284a69eb850b")));
}
Also used : URL(java.net.URL) SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock) Test(org.junit.jupiter.api.Test)

Example 4 with SignedBlock

use of tech.pegasys.web3signer.slashingprotection.dao.SignedBlock in project web3signer by ConsenSys.

the class InterchangeImportConflictsIntegrationTestBase method canLoadInterchangeFormatWithMissingSigningRootForBlock.

@Test
void canLoadInterchangeFormatWithMissingSigningRootForBlock() throws IOException {
    final URL importFile = Resources.getResource("interchange/multipleNullSigningRootBlock.json");
    slashingProtectionContext.getSlashingProtection().importData(importFile.openStream());
    final List<SignedBlock> blocksInDb = findAllBlocks();
    assertThat(blocksInDb).hasSize(2);
    assertThat(blocksInDb.get(0).getSlot()).isEqualTo(UInt64.valueOf(12345));
    assertThat(blocksInDb.get(0).getValidatorId()).isEqualTo(1);
    assertThat(blocksInDb.get(0).getSigningRoot()).isEmpty();
    assertThat(blocksInDb.get(1).getSlot()).isEqualTo(UInt64.valueOf(12346));
    assertThat(blocksInDb.get(1).getValidatorId()).isEqualTo(1);
    assertThat(blocksInDb.get(1).getSigningRoot()).isEmpty();
}
Also used : URL(java.net.URL) SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock) Test(org.junit.jupiter.api.Test)

Example 5 with SignedBlock

use of tech.pegasys.web3signer.slashingprotection.dao.SignedBlock in project web3signer by ConsenSys.

the class InterchangeImportConflictsIntegrationTestBase method duplicateEntriesAreNotInsertedToDatabase.

@Test
void duplicateEntriesAreNotInsertedToDatabase() throws IOException {
    final URL importFile = Resources.getResource("interchange/singleValidBlock.json");
    slashingProtectionContext.getSlashingProtection().importData(importFile.openStream());
    slashingProtectionContext.getSlashingProtection().importData(// attempt to reimport
    importFile.openStream());
    final List<SignedBlock> blocksInDb = findAllBlocks();
    assertThat(blocksInDb).hasSize(1);
    assertThat(blocksInDb.get(0).getSlot()).isEqualTo(UInt64.valueOf(12345));
    assertThat(blocksInDb.get(0).getValidatorId()).isEqualTo(1);
    assertThat(blocksInDb.get(0).getSigningRoot()).isEqualTo(Optional.of(Bytes.fromHexString("0x4ff6f743a43f3b4f95350831aeaf0a122a1a392922c45d804280284a69eb850b")));
}
Also used : URL(java.net.URL) SignedBlock(tech.pegasys.web3signer.slashingprotection.dao.SignedBlock) Test(org.junit.jupiter.api.Test)

Aggregations

SignedBlock (tech.pegasys.web3signer.slashingprotection.dao.SignedBlock)11 Test (org.junit.jupiter.api.Test)9 URL (java.net.URL)6 SigningWatermark (tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark)4 TestSlashingProtectionParameters (dsl.TestSlashingProtectionParameters)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 SignedAttestation (tech.pegasys.web3signer.slashingprotection.dao.SignedAttestation)1