use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class RemoteValidatorApiHandlerTest method getAttestationDuties_WhenFound_ReturnsDuties.
@Test
public void getAttestationDuties_WhenFound_ReturnsDuties() {
final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
final int validatorIndex = 472;
final int committeeLength = 2;
final int committeeIndex = 1;
final int validatorCommitteeIndex = 3;
final int committeesAtSlot = 15;
final tech.pegasys.teku.api.response.v1.validator.AttesterDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.AttesterDuty(new BLSPubKey(blsPublicKey), UInt64.valueOf(validatorIndex), UInt64.valueOf(committeeIndex), UInt64.valueOf(committeeLength), UInt64.valueOf(committeesAtSlot), UInt64.valueOf(validatorCommitteeIndex), UInt64.ZERO);
final AttesterDuty expectedValidatorDuties = new AttesterDuty(blsPublicKey, validatorIndex, committeeLength, committeeIndex, committeesAtSlot, validatorCommitteeIndex, UInt64.ZERO);
when(apiClient.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex))).thenReturn(Optional.of(new PostAttesterDutiesResponse(dataStructureUtil.randomBytes32(), List.of(schemaValidatorDuties))));
SafeFuture<Optional<AttesterDuties>> future = apiHandler.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex));
AttesterDuties validatorDuties = unwrapToValue(future);
assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldNotPerformDutiesForSameSlotTwice.
@Test
public void shouldNotPerformDutiesForSameSlotTwice() {
createDutySchedulerWithRealDuties();
final UInt64 attestationProductionSlot = UInt64.valueOf(5);
final int committeesAtSlot = 15;
final AttesterDuty validator1Duties = new AttesterDuty(VALIDATOR1_KEY, 5, 10, 3, committeesAtSlot, 6, attestationProductionSlot);
when(validatorApiChannel.getAttestationDuties(eq(ZERO), any())).thenReturn(completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties)))));
final AttestationProductionDuty attestationDuty = mock(AttestationProductionDuty.class);
when(attestationDuty.performDuty()).thenReturn(new SafeFuture<>());
when(attestationDutyFactory.createProductionDuty(attestationProductionSlot, validator1)).thenReturn(attestationDuty);
// Load duties
dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
verify(attestationDuty).addValidator(validator1, 3, 6, 5, 10);
// Execute
dutyScheduler.onAttestationCreationDue(attestationProductionSlot);
verify(attestationDuty).performDuty();
// Somehow we triggered the same slot again.
dutyScheduler.onAttestationCreationDue(attestationProductionSlot);
// But shouldn't produce another block and get ourselves slashed.
verifyNoMoreInteractions(attestationDuty);
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldScheduleAttestationDuties.
@Test
public void shouldScheduleAttestationDuties() {
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();
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class AttestationDutySchedulerTest method shouldScheduleAttestationDutiesWhenBlockIsImported.
@Test
public void shouldScheduleAttestationDutiesWhenBlockIsImported() {
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();
}
use of tech.pegasys.teku.validator.api.AttesterDuty in project teku by ConsenSys.
the class AttestationDutyLoaderTest method shouldSubscribeToSubnetWhenValidatorIsNotAggregator.
@Test
void shouldSubscribeToSubnetWhenValidatorIsNotAggregator() {
final UInt64 slot = UInt64.ONE;
final Integer validatorIndex = VALIDATOR_INDICES.get(0);
final int committeeLength = 10000000;
final int committeeIndex = 3;
final int committeesAtSlot = 4;
final AttesterDuty duty = new AttesterDuty(validatorKey, validatorIndex, committeeLength, committeeIndex, committeesAtSlot, 0, slot);
when(validatorApiChannel.getAttestationDuties(UInt64.ONE, VALIDATOR_INDICES)).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(duty)))));
when(scheduledDuties.scheduleProduction(any(), any(), any())).thenReturn(new SafeFuture<>());
when(signer.signAggregationSlot(slot, forkInfo)).thenReturn(SafeFuture.completedFuture(dataStructureUtil.randomSignature()));
final SafeFuture<Optional<SlotBasedScheduledDuties<?, ?>>> result = dutyLoader.loadDutiesForEpoch(UInt64.ONE);
assertThat(result).isCompleted();
verify(beaconCommitteeSubscriptions).subscribeToBeaconCommittee(new CommitteeSubscriptionRequest(validatorIndex, committeeIndex, UInt64.valueOf(committeesAtSlot), slot, false));
verify(beaconCommitteeSubscriptions).sendRequests();
}
Aggregations