Search in sources :

Example 1 with SignedVoluntaryExit

use of tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit in project teku by ConsenSys.

the class BlockOperationSelectorFactoryTest method shouldIncludeValidOperations.

@Test
void shouldIncludeValidOperations() {
    final UInt64 slot = UInt64.valueOf(2);
    final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(slot);
    final SignedVoluntaryExit voluntaryExit = dataStructureUtil.randomSignedVoluntaryExit();
    final ProposerSlashing proposerSlashing = dataStructureUtil.randomProposerSlashing();
    final AttesterSlashing attesterSlashing = dataStructureUtil.randomAttesterSlashing();
    final SignedContributionAndProof contribution = dataStructureUtil.randomSignedContributionAndProof(1, parentRoot);
    addToPool(voluntaryExitPool, voluntaryExit);
    addToPool(proposerSlashingPool, proposerSlashing);
    addToPool(attesterSlashingPool, attesterSlashing);
    assertThat(contributionPool.add(contribution)).isCompletedWithValue(ACCEPT);
    factory.createSelector(parentRoot, blockSlotState, randaoReveal, Optional.empty()).accept(bodyBuilder);
    assertThat(bodyBuilder.randaoReveal).isEqualTo(randaoReveal);
    assertThat(bodyBuilder.graffiti).isEqualTo(defaultGraffiti);
    assertThat(bodyBuilder.proposerSlashings).containsOnly(proposerSlashing);
    assertThat(bodyBuilder.attesterSlashings).containsOnly(attesterSlashing);
    assertThat(bodyBuilder.voluntaryExits).containsOnly(voluntaryExit);
    assertThat(bodyBuilder.syncAggregate).isEqualTo(spec.getSyncCommitteeUtilRequired(slot).createSyncAggregate(List.of(contribution.getMessage().getContribution())));
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with SignedVoluntaryExit

use of tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit in project teku by ConsenSys.

the class VoluntaryExitGenerator method create.

private SignedVoluntaryExit create(ForkInfo forkInfo, UInt64 epoch, int validatorIndex, boolean valid) {
    VoluntaryExit exit = new VoluntaryExit(epoch, UInt64.valueOf(validatorIndex));
    BLSSignature exitSignature = new LocalSigner(spec, getKeypair(validatorIndex, valid), SYNC_RUNNER).signVoluntaryExit(exit, forkInfo).join();
    return new SignedVoluntaryExit(exit, exitSignature);
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) LocalSigner(tech.pegasys.teku.core.signatures.LocalSigner) VoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 3 with SignedVoluntaryExit

use of tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit 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 4 with SignedVoluntaryExit

use of tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit in project teku by ConsenSys.

the class VoluntaryExitFuzzInputTest method createInput.

@Override
protected VoluntaryExitFuzzInput createInput() {
    final BeaconState state = dataStructureUtil.randomBeaconState();
    final SignedVoluntaryExit exit = dataStructureUtil.randomSignedVoluntaryExit();
    return new VoluntaryExitFuzzInput(spec, state, exit);
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 5 with SignedVoluntaryExit

use of tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit in project teku by ConsenSys.

the class FuzzUtil method fuzzVoluntaryExit.

public Optional<byte[]> fuzzVoluntaryExit(final byte[] input) {
    VoluntaryExitFuzzInput structuredInput = deserialize(input, VoluntaryExitFuzzInput.createSchema(spec.getGenesisSpec()));
    SszList<SignedVoluntaryExit> voluntaryExits = beaconBlockBodySchema.getVoluntaryExitsSchema().of(structuredInput.getExit());
    try {
        BeaconState postState = structuredInput.getState().updated(state -> spec.getBlockProcessor(state.getSlot()).processVoluntaryExits(state, voluntaryExits, signatureVerifier));
        Bytes output = postState.sszSerialize();
        return Optional.of(output.toArrayUnsafe());
    } catch (BlockProcessingException e) {
        // "expected error"
        return Optional.empty();
    }
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Bytes(org.apache.tuweni.bytes.Bytes) BlockProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException) VoluntaryExitFuzzInput(tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)18 Test (org.junit.jupiter.api.Test)11 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)7 Bytes (org.apache.tuweni.bytes.Bytes)5 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)4 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)4 ValidationResult (io.libp2p.core.pubsub.ValidationResult)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 VoluntaryExitFuzzInput (tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput)2 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)2 VoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit)2 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1