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