Search in sources :

Example 1 with ProposerDuty

use of tech.pegasys.teku.validator.api.ProposerDuty in project teku by ConsenSys.

the class ValidatorApiHandler method getProposalSlotsForEpoch.

private List<ProposerDuty> getProposalSlotsForEpoch(final BeaconState state, final UInt64 epoch) {
    final UInt64 epochStartSlot = spec.computeStartSlotAtEpoch(epoch);
    final UInt64 startSlot = epochStartSlot.max(GENESIS_SLOT.increment());
    final UInt64 endSlot = epochStartSlot.plus(spec.slotsPerEpoch(epoch));
    final List<ProposerDuty> proposerSlots = new ArrayList<>();
    for (UInt64 slot = startSlot; slot.compareTo(endSlot) < 0; slot = slot.plus(UInt64.ONE)) {
        final int proposerIndex = spec.getBeaconProposerIndex(state, slot);
        final BLSPublicKey publicKey = spec.getValidatorPubKey(state, UInt64.valueOf(proposerIndex)).orElseThrow();
        proposerSlots.add(new ProposerDuty(publicKey, proposerIndex, slot));
    }
    return proposerSlots;
}
Also used : ArrayList(java.util.ArrayList) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey)

Example 2 with ProposerDuty

use of tech.pegasys.teku.validator.api.ProposerDuty in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method getProposerDuties_WhenFound_ReturnsDuties.

@Test
public void getProposerDuties_WhenFound_ReturnsDuties() {
    final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
    final int validatorIndex = 472;
    final tech.pegasys.teku.api.response.v1.validator.ProposerDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.ProposerDuty(new BLSPubKey(blsPublicKey), validatorIndex, UInt64.ZERO);
    final ProposerDuty expectedValidatorDuties = new ProposerDuty(blsPublicKey, validatorIndex, UInt64.ZERO);
    final GetProposerDutiesResponse response = new GetProposerDutiesResponse(Bytes32.fromHexString("0x1234"), List.of(schemaValidatorDuties));
    when(apiClient.getProposerDuties(UInt64.ONE)).thenReturn(Optional.of(response));
    SafeFuture<Optional<ProposerDuties>> future = apiHandler.getProposerDuties(UInt64.ONE);
    ProposerDuties validatorDuties = unwrapToValue(future);
    assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
    assertThat(validatorDuties.getDependentRoot()).isEqualTo(response.dependentRoot);
}
Also used : Optional(java.util.Optional) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) GetProposerDutiesResponse(tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Example 3 with ProposerDuty

use of tech.pegasys.teku.validator.api.ProposerDuty in project teku by ConsenSys.

the class BlockDutySchedulerTest method shouldNotPerformDutiesForSameSlotTwice.

@Test
public void shouldNotPerformDutiesForSameSlotTwice() {
    createDutySchedulerWithRealDuties();
    final UInt64 blockProposerSlot = UInt64.valueOf(5);
    final ProposerDuty validator1Duties = new ProposerDuty(VALIDATOR1_KEY, 5, blockProposerSlot);
    when(validatorApiChannel.getProposerDuties(eq(ZERO))).thenReturn(completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties, new ProposerDuty(dataStructureUtil.randomPublicKey(), 6, UInt64.valueOf(4)))))));
    final BlockProductionDuty blockCreationDuty = mock(BlockProductionDuty.class);
    when(blockCreationDuty.performDuty()).thenReturn(new SafeFuture<>());
    when(blockDutyFactory.createProductionDuty(blockProposerSlot, validator1)).thenReturn(blockCreationDuty);
    // Load duties
    dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
    // Execute
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    verify(blockCreationDuty).performDuty();
    // Somehow we triggered the same slot again.
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    // But shouldn't produce another block and get ourselves slashed.
    verifyNoMoreInteractions(blockCreationDuty);
}
Also used : BlockProductionDuty(tech.pegasys.teku.validator.client.duties.BlockProductionDuty) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 4 with ProposerDuty

use of tech.pegasys.teku.validator.api.ProposerDuty in project teku by ConsenSys.

the class BlockDutySchedulerTest method shouldScheduleBlockProposalDuty.

@Test
public void shouldScheduleBlockProposalDuty() {
    createDutySchedulerWithRealDuties();
    final UInt64 blockProposerSlot = UInt64.valueOf(5);
    final ProposerDuty validator1Duties = new ProposerDuty(VALIDATOR1_KEY, 5, blockProposerSlot);
    when(validatorApiChannel.getProposerDuties(ZERO)).thenReturn(completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties)))));
    final BlockProductionDuty blockCreationDuty = mock(BlockProductionDuty.class);
    when(blockCreationDuty.performDuty()).thenReturn(new SafeFuture<>());
    when(blockDutyFactory.createProductionDuty(blockProposerSlot, validator1)).thenReturn(blockCreationDuty);
    // Load duties
    dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
    // Execute
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    verify(blockCreationDuty).performDuty();
}
Also used : BlockProductionDuty(tech.pegasys.teku.validator.client.duties.BlockProductionDuty) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

ProposerDuty (tech.pegasys.teku.validator.api.ProposerDuty)4 Test (org.junit.jupiter.api.Test)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 ProposerDuties (tech.pegasys.teku.validator.api.ProposerDuties)3 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 BlockProductionDuty (tech.pegasys.teku.validator.client.duties.BlockProductionDuty)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 GetProposerDutiesResponse (tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1