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