Search in sources :

Example 6 with ProposerDuties

use of tech.pegasys.teku.validator.api.ProposerDuties 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 7 with ProposerDuties

use of tech.pegasys.teku.validator.api.ProposerDuties 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 8 with ProposerDuties

use of tech.pegasys.teku.validator.api.ProposerDuties 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)

Example 9 with ProposerDuties

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

the class BlockDutySchedulerTest method shouldNotRefetchDutiesWhenHeadUpdateHasSameCurrentDependentRoot.

@Test
public void shouldNotRefetchDutiesWhenHeadUpdateHasSameCurrentDependentRoot() {
    createDutySchedulerWithRealDuties();
    final UInt64 currentEpoch = UInt64.valueOf(5);
    final UInt64 currentSlot = spec.computeStartSlotAtEpoch(currentEpoch);
    final Bytes32 previousDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDependentRoot = dataStructureUtil.randomBytes32();
    when(validatorApiChannel.getProposerDuties(any())).thenReturn(SafeFuture.completedFuture(Optional.of(new ProposerDuties(currentDependentRoot, emptyList()))));
    dutyScheduler.onSlot(currentSlot);
    verify(validatorApiChannel).getProposerDuties(currentEpoch);
    dutyScheduler.onHeadUpdate(currentSlot, previousDependentRoot, currentDependentRoot, dataStructureUtil.randomBytes32());
    verifyNoMoreInteractions(validatorApiChannel);
}
Also used : ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 10 with ProposerDuties

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

the class BlockDutySchedulerTest method shouldRefetchDutiesWhenHeadUpdateHasDifferentCurrentDependentRoot.

@Test
public void shouldRefetchDutiesWhenHeadUpdateHasDifferentCurrentDependentRoot() {
    createDutySchedulerWithRealDuties();
    final UInt64 currentEpoch = UInt64.valueOf(5);
    final UInt64 currentSlot = spec.computeStartSlotAtEpoch(currentEpoch);
    final Bytes32 previousDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDependentRoot = dataStructureUtil.randomBytes32();
    when(validatorApiChannel.getProposerDuties(any())).thenReturn(SafeFuture.completedFuture(Optional.of(new ProposerDuties(currentDependentRoot, emptyList()))));
    dutyScheduler.onSlot(currentSlot);
    verify(validatorApiChannel).getProposerDuties(currentEpoch);
    dutyScheduler.onHeadUpdate(currentSlot, previousDependentRoot, dataStructureUtil.randomBytes32(), dataStructureUtil.randomBytes32());
    verify(validatorApiChannel, times(2)).getProposerDuties(currentEpoch);
    verifyNoMoreInteractions(validatorApiChannel);
}
Also used : ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 ProposerDuties (tech.pegasys.teku.validator.api.ProposerDuties)10 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 Optional (java.util.Optional)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 ProposerDuty (tech.pegasys.teku.validator.api.ProposerDuty)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BlockProductionDuty (tech.pegasys.teku.validator.client.duties.BlockProductionDuty)2 GetProposerDutiesResponse (tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1