Search in sources :

Example 1 with BlockValidator

use of tech.pegasys.web3signer.slashingprotection.validator.BlockValidator in project web3signer by ConsenSys.

the class DbSlashingProtection method maySignBlock.

@Override
public boolean maySignBlock(final Bytes publicKey, final Bytes signingRoot, final UInt64 blockSlot, final Bytes32 genesisValidatorsRoot) {
    final int validatorId = registeredValidators.mustGetValidatorIdForPublicKey(publicKey);
    if (!gvrValidator.checkGenesisValidatorsRootAndInsertIfEmpty(genesisValidatorsRoot)) {
        return false;
    }
    return jdbi.inTransaction(READ_COMMITTED, h -> {
        lockForValidator(h, LockType.BLOCK, validatorId);
        if (!isEnabled(h, validatorId)) {
            LOG.warn("Signing attempted for disabled validator {}. To sign with this validator" + " you must import the validator keystore using the key manager import API", publicKey);
            return false;
        }
        final BlockValidator blockValidator = new BlockValidator(h, signingRoot, blockSlot, validatorId, signedBlocksDao, lowWatermarkDao);
        if (blockValidator.isOlderThanWatermark() || blockValidator.directlyConflictsWithExistingEntry()) {
            return false;
        }
        if (!blockValidator.alreadyExists()) {
            blockValidator.persist();
        }
        return true;
    });
}
Also used : BlockValidator(tech.pegasys.web3signer.slashingprotection.validator.BlockValidator)

Example 2 with BlockValidator

use of tech.pegasys.web3signer.slashingprotection.validator.BlockValidator in project web3signer by ConsenSys.

the class BlockImporter method importFrom.

public void importFrom(final ArrayNode signedBlocksNode) throws JsonProcessingException {
    for (int i = 0; i < signedBlocksNode.size(); i++) {
        final SignedBlock jsonBlock = mapper.treeToValue(signedBlocksNode.get(i), SignedBlock.class);
        final BlockValidator blockValidator = new BlockValidator(handle, jsonBlock.getSigningRoot(), jsonBlock.getSlot(), validator.getId(), signedBlocksDao, lowWatermarkDao);
        final String blockIdentifierString = String.format("Block with index %d for validator %s", i, validator.getPublicKey());
        if (jsonBlock.getSigningRoot() == null) {
            if (nullBlockAlreadyExistsInSlot(jsonBlock.getSlot())) {
                LOG.warn("{} - already exists in database, not imported", blockIdentifierString);
            } else {
                persist(jsonBlock);
            }
        } else {
            if (blockValidator.directlyConflictsWithExistingEntry()) {
                LOG.warn("{} - conflicts with an existing entry, not imported", blockIdentifierString);
            } else if (blockValidator.alreadyExists()) {
                LOG.debug("{} - already exists in database, not imported", blockIdentifierString);
            } else {
                persist(jsonBlock);
            }
        }
    }
    final Optional<SigningWatermark> watermark = lowWatermarkDao.findLowWatermarkForValidator(handle, validator.getId());
    if (minSlotTracker.compareTrackedValueTo(watermark.map(SigningWatermark::getSlot)) > 0) {
        LOG.warn("Updating Block slot low watermark to {}", minSlotTracker.getTrackedMinValue().get());
        lowWatermarkDao.updateSlotWatermarkFor(handle, validator.getId(), minSlotTracker.getTrackedMinValue().get());
    }
}
Also used : SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) BlockValidator(tech.pegasys.web3signer.slashingprotection.validator.BlockValidator) SignedBlock(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedBlock)

Aggregations

BlockValidator (tech.pegasys.web3signer.slashingprotection.validator.BlockValidator)2 SigningWatermark (tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark)1 SignedBlock (tech.pegasys.web3signer.slashingprotection.interchange.model.SignedBlock)1