use of tech.pegasys.teku.validator.api.AttesterDuty 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.AttesterDuty in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldScheduleAggregationDuties.
@Test
public void shouldScheduleAggregationDuties() {
createDutySchedulerWithRealDuties();
final UInt64 attestationSlot = UInt64.valueOf(13);
final int validator1Index = 5;
final int validator1Committee = 3;
final int validator1CommitteePosition = 9;
// Guaranteed to be an aggregator
final int validator1CommitteeSize = 1;
final int validator2Index = 6;
final int validator2Committee = 4;
final int validator2CommitteePosition = 8;
// Won't be an aggregator
final int validator2CommitteeSize = 1000000000;
final int committeesAtSlot = 15;
final AttesterDuty validator1Duties = new AttesterDuty(VALIDATOR1_KEY, validator1Index, validator1CommitteeSize, validator1Committee, committeesAtSlot, validator1CommitteePosition, attestationSlot);
final AttesterDuty validator2Duties = new AttesterDuty(VALIDATOR2_KEY, validator2Index, validator2CommitteeSize, validator2Committee, committeesAtSlot, validator2CommitteePosition, attestationSlot);
when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties, validator2Duties)))));
final BLSSignature validator1Signature = dataStructureUtil.randomSignature();
when(validator1.getSigner().signAggregationSlot(attestationSlot, fork)).thenReturn(completedFuture(validator1Signature));
when(validator2.getSigner().signAggregationSlot(attestationSlot, fork)).thenReturn(completedFuture(dataStructureUtil.randomSignature()));
final SafeFuture<Optional<AttestationData>> unsignedAttestationFuture = new SafeFuture<>();
final AggregationDuty aggregationDuty = mock(AggregationDuty.class);
final AttestationProductionDuty attestationDuty = mock(AttestationProductionDuty.class);
when(attestationDutyFactory.createProductionDuty(attestationSlot, validator1)).thenReturn(attestationDuty);
when(attestationDutyFactory.createAggregationDuty(attestationSlot, validator1)).thenReturn(aggregationDuty);
when(aggregationDuty.performDuty()).thenReturn(new SafeFuture<>());
when(attestationDuty.addValidator(validator1, validator1Committee, validator1CommitteePosition, validator1Index, validator1CommitteeSize)).thenReturn(unsignedAttestationFuture);
// Load duties
final UInt64 epochStartSlot = spec.computeStartSlotAtEpoch(ONE);
dutyScheduler.onSlot(epochStartSlot);
// Only validator1 should have had an aggregation duty created for it
verify(attestationDutyFactory).createAggregationDuty(attestationSlot, validator1);
// And should have added validator1 to each duty
verify(aggregationDuty).addValidator(validator1, validator1Index, validator1Signature, validator1Committee, unsignedAttestationFuture);
verifyNoMoreInteractions(aggregationDuty);
// Perform the duties
dutyScheduler.onAttestationAggregationDue(attestationSlot);
verify(aggregationDuty).performDuty();
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldNotScheduleAttestationDutiesTwice.
@Test
public void shouldNotScheduleAttestationDutiesTwice() {
createDutySchedulerWithRealDuties();
final UInt64 attestationSlot = UInt64.valueOf(5);
final int validator1Index = 5;
final int validator1Committee = 3;
final int validator1CommitteePosition = 9;
final int validator1CommitteeSize = 10;
final int validator2Index = 6;
final int validator2Committee = 4;
final int validator2CommitteePosition = 8;
final int validator2CommitteeSize = 11;
final int committeesAtSlot = 15;
final AttesterDuty validator1Duties = new AttesterDuty(VALIDATOR1_KEY, validator1Index, validator1CommitteeSize, validator1Committee, committeesAtSlot, validator1CommitteePosition, attestationSlot);
final AttesterDuty validator2Duties = new AttesterDuty(VALIDATOR2_KEY, validator2Index, validator2CommitteeSize, validator2Committee, committeesAtSlot, validator2CommitteePosition, attestationSlot);
when(validatorApiChannel.getAttestationDuties(eq(ZERO), any())).thenReturn(completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties, validator2Duties)))));
final AttestationProductionDuty attestationDuty = mock(AttestationProductionDuty.class);
when(attestationDuty.performDuty()).thenReturn(new SafeFuture<>());
when(attestationDutyFactory.createProductionDuty(attestationSlot, validator1)).thenReturn(attestationDuty);
// Load duties
dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
// Both validators should be scheduled to create an attestation in the same slot
verify(attestationDuty).addValidator(validator1, validator1Committee, validator1CommitteePosition, validator1Index, validator1CommitteeSize);
verify(attestationDuty).addValidator(validator2, validator2Committee, validator2CommitteePosition, validator2Index, validator2CommitteeSize);
// Execute
dutyScheduler.onAttestationCreationDue(attestationSlot);
verify(attestationDuty).performDuty();
dutyScheduler.onAttestationCreationDue(attestationSlot);
verifyNoMoreInteractions(attestationDuty);
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getAttestationDuties_shouldReturnDutiesAndSkipMissingValidators.
@Test
public void getAttestationDuties_shouldReturnDutiesAndSkipMissingValidators() {
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(ONE));
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.AttesterDuty in project teku by ConsenSys.
the class ValidatorDataProviderTest method getAttesterDuties_shouldReturnDutiesForKnownValidator.
@TestTemplate
public void getAttesterDuties_shouldReturnDutiesForKnownValidator() {
AttesterDuty v1 = new AttesterDuty(BLSTestUtil.randomPublicKey(0), 1, 2, 3, 15, 4, ONE);
AttesterDuty v2 = new AttesterDuty(BLSTestUtil.randomPublicKey(1), 11, 12, 13, 15, 14, ZERO);
when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(v1, v2)))));
final SafeFuture<Optional<PostAttesterDutiesResponse>> future = provider.getAttesterDuties(ONE, IntList.of(1, 11));
assertThat(future).isCompleted();
final Optional<PostAttesterDutiesResponse> maybeList = future.join();
final PostAttesterDutiesResponse list = maybeList.orElseThrow();
assertThat(list.data).containsExactlyInAnyOrder(asAttesterDuty(v1), asAttesterDuty(v2));
}
Aggregations