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);
}
}
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));
}
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")));
}
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();
}
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")));
}
Aggregations