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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations