Search in sources :

Example 1 with AttestationProductionDuty

use of tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty 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();
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AggregationDuty(tech.pegasys.teku.validator.client.duties.attestations.AggregationDuty) Optional(java.util.Optional) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) AttestationProductionDuty(tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 2 with AttestationProductionDuty

use of tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty 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);
}
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 3 with AttestationProductionDuty

use of tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty 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 4 with AttestationProductionDuty

use of tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty 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 5 with AttestationProductionDuty

use of tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty 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)

Aggregations

Test (org.junit.jupiter.api.Test)5 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 AttesterDuties (tech.pegasys.teku.validator.api.AttesterDuties)5 AttesterDuty (tech.pegasys.teku.validator.api.AttesterDuty)5 AttestationProductionDuty (tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty)5 Optional (java.util.Optional)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