Search in sources :

Example 1 with OperationInvalidReason

use of tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason in project teku by ConsenSys.

the class AbstractBlockProcessor method processVoluntaryExitsNoValidation.

protected void processVoluntaryExitsNoValidation(MutableBeaconState state, SszList<SignedVoluntaryExit> exits) throws BlockProcessingException {
    safelyProcess(() -> {
        // For each exit in block.body.voluntaryExits:
        for (SignedVoluntaryExit signedExit : exits) {
            Optional<OperationInvalidReason> invalidReason = operationValidator.validateVoluntaryExit(state.getFork(), state, signedExit);
            checkArgument(invalidReason.isEmpty(), "process_voluntary_exits: %s", invalidReason.map(OperationInvalidReason::describe).orElse(""));
            // - Run initiate_validator_exit(state, exit.validator_index)
            beaconStateMutators.initiateValidatorExit(state, toIntExact(signedExit.getMessage().getValidatorIndex().longValue()));
        }
    });
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) OperationInvalidReason(tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason)

Example 2 with OperationInvalidReason

use of tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason in project teku by ConsenSys.

the class AbstractBlockProcessor method processProposerSlashingsNoValidation.

protected void processProposerSlashingsNoValidation(MutableBeaconState state, SszList<ProposerSlashing> proposerSlashings) throws BlockProcessingException {
    safelyProcess(() -> {
        // For each proposer_slashing in block.body.proposer_slashings:
        for (ProposerSlashing proposerSlashing : proposerSlashings) {
            Optional<OperationInvalidReason> invalidReason = operationValidator.validateProposerSlashing(state.getFork(), state, proposerSlashing);
            checkArgument(invalidReason.isEmpty(), "process_proposer_slashings: %s", invalidReason.map(OperationInvalidReason::describe).orElse(""));
            beaconStateMutators.slashValidator(state, toIntExact(proposerSlashing.getHeader_1().getMessage().getProposerIndex().longValue()));
        }
    });
}
Also used : OperationInvalidReason(tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)

Example 3 with OperationInvalidReason

use of tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason in project teku by ConsenSys.

the class AbstractBlockProcessor method assertAttestationValid.

protected void assertAttestationValid(final MutableBeaconState state, final Attestation attestation) {
    final AttestationData data = attestation.getData();
    final Optional<OperationInvalidReason> invalidReason = validateAttestation(state, data);
    checkArgument(invalidReason.isEmpty(), "process_attestations: %s", invalidReason.map(OperationInvalidReason::describe).orElse(""));
    IntList committee = beaconStateAccessors.getBeaconCommittee(state, data.getSlot(), data.getIndex());
    checkArgument(attestation.getAggregationBits().size() == committee.size(), "process_attestations: Attestation aggregation bits and committee don't have the same length");
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) OperationInvalidReason(tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason) IntList(it.unimi.dsi.fastutil.ints.IntList)

Example 4 with OperationInvalidReason

use of tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason in project teku by ConsenSys.

the class AbstractBlockProcessor method processAttesterSlashings.

@Override
public void processAttesterSlashings(MutableBeaconState state, SszList<AttesterSlashing> attesterSlashings) throws BlockProcessingException {
    safelyProcess(() -> {
        // For each attester_slashing in block.body.attester_slashings:
        for (AttesterSlashing attesterSlashing : attesterSlashings) {
            List<UInt64> indicesToSlash = new ArrayList<>();
            final Optional<OperationInvalidReason> invalidReason = operationValidator.validateAttesterSlashing(state.getFork(), state, attesterSlashing, indicesToSlash::add);
            checkArgument(invalidReason.isEmpty(), "process_attester_slashings: %s", invalidReason.map(OperationInvalidReason::describe).orElse(""));
            indicesToSlash.forEach(indexToSlash -> beaconStateMutators.slashValidator(state, toIntExact(indexToSlash.longValue())));
        }
    });
}
Also used : AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) OperationInvalidReason(tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason) ArrayList(java.util.ArrayList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Aggregations

OperationInvalidReason (tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason)4 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ArrayList (java.util.ArrayList)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)1 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)1 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)1 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)1