Search in sources :

Example 6 with AttesterDuty

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);
}
Also used : Optional(java.util.Optional) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Example 7 with AttesterDuty

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);
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 8 with AttesterDuty

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();
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 9 with AttesterDuty

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();
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 10 with AttesterDuty

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();
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) CommitteeSubscriptionRequest(tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

AttesterDuties (tech.pegasys.teku.validator.api.AttesterDuties)11 AttesterDuty (tech.pegasys.teku.validator.api.AttesterDuty)11 Test (org.junit.jupiter.api.Test)10 Optional (java.util.Optional)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 AttestationProductionDuty (tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty)5 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)3 PostAttesterDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 CommitteeSubscriptionRequest (tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest)2 TestTemplate (org.junit.jupiter.api.TestTemplate)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 AggregationDuty (tech.pegasys.teku.validator.client.duties.attestations.AggregationDuty)1