use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getAttestationDuties_shouldAllowOneEpochTolerance.
@Test
public void getAttestationDuties_shouldAllowOneEpochTolerance() {
final BeaconState state = createStateWithActiveValidators();
final BLSPublicKey validator1Key = BLSPublicKey.fromBytesCompressed(state.getValidators().get(1).getPubkeyBytes());
when(chainDataClient.getStateAtSlotExact(PREVIOUS_EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(2));
final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of(1, 32));
final Optional<AttesterDuties> duties = assertCompletedSuccessfully(result);
assertThat(duties.orElseThrow().getDuties()).containsExactly(new AttesterDuty(validator1Key, 1, 4, 0, 1, 1, UInt64.valueOf(108)));
}
use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getAttestationDuties_shouldUsePreviousDutyDependentRootWhenStateFromSameEpoch.
@Test
public void getAttestationDuties_shouldUsePreviousDutyDependentRootWhenStateFromSameEpoch() {
final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
when(chainDataClient.getStateAtSlotExact(any())).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(ONE));
final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of());
final AttesterDuties duties = assertCompletedSuccessfully(result).orElseThrow();
assertThat(duties.getDependentRoot()).isEqualTo(spec.getPreviousDutyDependentRoot(state));
}
use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.
the class ValidatorApiHandler method getAttestationDuties.
@Override
public SafeFuture<Optional<AttesterDuties>> getAttestationDuties(final UInt64 epoch, final IntCollection validatorIndices) {
if (isSyncActive()) {
return NodeSyncingException.failedFuture();
}
if (epoch.isGreaterThan(combinedChainDataClient.getCurrentEpoch().plus(spec.getSpecConfig(epoch).getMinSeedLookahead() + DUTY_EPOCH_TOLERANCE))) {
return SafeFuture.failedFuture(new IllegalArgumentException(String.format("Attestation duties were requested %s epochs ahead, only 1 epoch in future is supported.", epoch.minus(combinedChainDataClient.getCurrentEpoch()).toString())));
}
final UInt64 slot = spec.getEarliestQueryableSlotForBeaconCommitteeInTargetEpoch(epoch);
LOG.trace("Retrieving attestation duties from epoch {} using state at slot {}", epoch, slot);
return combinedChainDataClient.getStateAtSlotExact(slot).thenApply(optionalState -> optionalState.map(state -> getAttesterDutiesFromIndicesAndState(state, epoch, validatorIndices)));
}
use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldDelayExecutingDutiesUntilSchedulingIsComplete.
@Test
public void shouldDelayExecutingDutiesUntilSchedulingIsComplete() {
createDutySchedulerWithMockDuties();
final SafeFuture<Optional<AttesterDuties>> epoch0Duties = new SafeFuture<>();
when(validatorApiChannel.getAttestationDuties(eq(ZERO), any())).thenReturn(epoch0Duties);
when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), emptyList()))));
dutyScheduler.onSlot(ZERO);
dutyScheduler.onBlockProductionDue(ZERO);
dutyScheduler.onAttestationCreationDue(ZERO);
dutyScheduler.onAttestationAggregationDue(ZERO);
// Duties haven't been loaded yet.
verify(scheduledDuties, never()).performProductionDuty(ZERO);
verify(scheduledDuties, never()).performAggregationDuty(ZERO);
epoch0Duties.complete(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), emptyList())));
verify(scheduledDuties).performProductionDuty(ZERO);
verify(scheduledDuties).performAggregationDuty(ZERO);
}
use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldNotRefetchDutiesWhenHeadUpdateReceivedWithNoChangeInDependentRoots.
@Test
public void shouldNotRefetchDutiesWhenHeadUpdateReceivedWithNoChangeInDependentRoots() {
createDutySchedulerWithRealDuties();
final UInt64 currentEpoch = UInt64.valueOf(5);
final UInt64 currentSlot = spec.computeStartSlotAtEpoch(currentEpoch);
final UInt64 nextEpoch = currentEpoch.plus(1);
final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
when(validatorApiChannel.getAttestationDuties(eq(currentEpoch), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(previousDutyDependentRoot, emptyList()))));
when(validatorApiChannel.getAttestationDuties(eq(nextEpoch), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(currentDutyDependentRoot, emptyList()))));
dutyScheduler.onSlot(currentSlot);
verify(validatorApiChannel).getAttestationDuties(currentEpoch, VALIDATOR_INDICES);
verify(validatorApiChannel).getAttestationDuties(nextEpoch, VALIDATOR_INDICES);
dutyScheduler.onHeadUpdate(currentSlot, previousDutyDependentRoot, currentDutyDependentRoot, dataStructureUtil.randomBytes32());
verifyNoMoreInteractions(validatorApiChannel);
}
Aggregations