Search in sources :

Example 1 with AttestationValidator

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

the class DbSlashingProtection method maySignAttestation.

@Override
public boolean maySignAttestation(final Bytes publicKey, final Bytes signingRoot, final UInt64 sourceEpoch, final UInt64 targetEpoch, final Bytes32 genesisValidatorsRoot) {
    final int validatorId = registeredValidators.mustGetValidatorIdForPublicKey(publicKey);
    if (!gvrValidator.checkGenesisValidatorsRootAndInsertIfEmpty(genesisValidatorsRoot)) {
        return false;
    }
    return jdbi.inTransaction(READ_COMMITTED, handle -> {
        lockForValidator(handle, LockType.ATTESTATION, validatorId);
        if (!isEnabled(handle, 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 AttestationValidator attestationValidator = new AttestationValidator(handle, publicKey, signingRoot, sourceEpoch, targetEpoch, validatorId, signedAttestationsDao, lowWatermarkDao);
        if (attestationValidator.sourceGreaterThanTargetEpoch()) {
            return false;
        }
        if (attestationValidator.hasSourceOlderThanWatermark() || attestationValidator.hasTargetOlderThanWatermark() || attestationValidator.directlyConflictsWithExistingEntry() || attestationValidator.isSurroundedByExistingAttestation() || attestationValidator.surroundsExistingAttestation()) {
            return false;
        }
        if (!attestationValidator.alreadyExists()) {
            attestationValidator.persist();
        }
        return true;
    });
}
Also used : AttestationValidator(tech.pegasys.web3signer.slashingprotection.validator.AttestationValidator)

Example 2 with AttestationValidator

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

the class AttestationImporter method importFrom.

public void importFrom(final ArrayNode signedAttestationNode) throws JsonProcessingException {
    for (int i = 0; i < signedAttestationNode.size(); i++) {
        final SignedAttestation jsonAttestation = mapper.treeToValue(signedAttestationNode.get(i), SignedAttestation.class);
        final AttestationValidator attestationValidator = new AttestationValidator(handle, validator.getPublicKey(), jsonAttestation.getSigningRoot(), jsonAttestation.getSourceEpoch(), jsonAttestation.getTargetEpoch(), validator.getId(), signedAttestationsDao, lowWatermarkDao);
        final String attestationIdentifierString = String.format("Attestation with index %d for validator %s", i, validator.getPublicKey());
        if (attestationValidator.sourceGreaterThanTargetEpoch()) {
            LOG.warn("{} - source is greater than target epoch", attestationIdentifierString);
        }
        if (attestationValidator.isSurroundedByExistingAttestation()) {
            LOG.warn("{} - is surrounded by existing entries", attestationIdentifierString);
        }
        if (attestationValidator.surroundsExistingAttestation()) {
            LOG.warn("{} - surrounds an existing entry", attestationIdentifierString);
        }
        if (jsonAttestation.getSigningRoot() == null) {
            if (nullAttestationAlreadyExistsInTargetEpoch(jsonAttestation.getTargetEpoch())) {
                LOG.warn("{} - already exists in database, not imported", attestationIdentifierString);
            } else {
                persist(jsonAttestation);
            }
        } else {
            if (attestationValidator.directlyConflictsWithExistingEntry()) {
                LOG.warn("{} - conflicts with an existing entry, not imported", attestationIdentifierString);
            } else if (attestationValidator.alreadyExists()) {
                LOG.debug("{} - already exists in database, not imported", attestationIdentifierString);
            } else {
                persist(jsonAttestation);
            }
        }
    }
    persistAttestationWatermark(handle, validator, minSourceTracker, minTargetTracker);
}
Also used : AttestationValidator(tech.pegasys.web3signer.slashingprotection.validator.AttestationValidator) SignedAttestation(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation)

Aggregations

AttestationValidator (tech.pegasys.web3signer.slashingprotection.validator.AttestationValidator)2 SignedAttestation (tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation)1