use of tech.pegasys.teku.validator.client.duties.DutyResult in project teku by ConsenSys.
the class PendingDutiesTest method shouldReportTotalNumberOfSuccessesAndFailuresToMetrics.
@Test
void shouldReportTotalNumberOfSuccessesAndFailuresToMetrics() {
final DutyResult result1 = DutyResult.success(Bytes32.ZERO);
final DutyResult result2 = DutyResult.success(Bytes32.ZERO);
final DutyResult result3 = DutyResult.forError(new Throwable("Oh no!"));
final DutyResult dutyResult = result1.combine(result2.combine(result3));
when(scheduledDuties.performProductionDuty(ZERO)).thenReturn(SafeFuture.completedFuture(dutyResult));
scheduledDutiesFuture.complete(scheduledDutiesOptional);
duties.onProductionDue(ZERO);
validateMetrics(PRODUCTION_TYPE, 2, 1);
}
use of tech.pegasys.teku.validator.client.duties.DutyResult in project teku by ConsenSys.
the class SyncCommitteeScheduledDutiesTest method shouldUseSameBlockRootForProductionAndAggregation.
@Test
void shouldUseSameBlockRootForProductionAndAggregation() {
final UInt64 slot = UInt64.valueOf(25);
final Bytes32 blockRoot = dataStructureUtil.randomBytes32();
when(chainHeadTracker.getCurrentChainHead(slot)).thenReturn(Optional.of(blockRoot)).thenReturn(Optional.of(dataStructureUtil.randomBytes32()));
final DutyResult expectedDutyResult = DutyResult.success(blockRoot);
when(productionDuty.produceMessages(slot, blockRoot)).thenReturn(SafeFuture.completedFuture(expectedDutyResult));
when(aggregationDuty.produceAggregates(slot, blockRoot)).thenReturn(SafeFuture.completedFuture(expectedDutyResult));
final SyncCommitteeScheduledDuties duties = createScheduledDutiesWithMocks(singleValidatorList);
assertThat(duties.performProductionDuty(slot)).isCompletedWithValue(expectedDutyResult);
assertThat(duties.performAggregationDuty(slot)).isCompletedWithValue(expectedDutyResult);
verify(productionDuty).produceMessages(slot, blockRoot);
verify(aggregationDuty).produceAggregates(slot, blockRoot);
}
use of tech.pegasys.teku.validator.client.duties.DutyResult in project teku by ConsenSys.
the class SyncCommitteeScheduledDutiesTest method shouldNotProduceSignaturesWhenChainHeadIsEmpty.
@Test
void shouldNotProduceSignaturesWhenChainHeadIsEmpty() {
final UInt64 slot = UInt64.valueOf(25);
when(chainHeadTracker.getCurrentChainHead(slot)).thenReturn(Optional.empty());
final Validator validator1 = createValidator();
final Validator validator2 = createValidator();
final SyncCommitteeScheduledDuties duties = validBuilder().committeeAssignment(validator1, 1, 1).committeeAssignment(validator2, 2, 2).build();
final SafeFuture<DutyResult> result = duties.performProductionDuty(slot);
reportDutyResult(slot, result);
verify(validatorLogger).dutyFailed(eq(TYPE), eq(slot), eq(Set.of(validator1.getPublicKey().toAbbreviatedString(), validator2.getPublicKey().toAbbreviatedString())), any(IllegalStateException.class));
}
use of tech.pegasys.teku.validator.client.duties.DutyResult in project teku by ConsenSys.
the class SyncCommitteeAggregationDutyTest method shouldDoNothingWhenNoValidatorsAreAggregators.
@Test
void shouldDoNothingWhenNoValidatorsAreAggregators() {
final SyncCommitteeAggregationDuty duty = createDuty(committeeAssignment(validator1, 11, 1));
final SyncAggregatorSelectionData expectedSigningData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.ZERO);
when(validator1.getSigner().signSyncCommitteeSelectionProof(expectedSigningData, forkInfo)).thenReturn(SafeFuture.completedFuture(nonAggregatorSignature));
final SafeFuture<DutyResult> result = duty.produceAggregates(slot, beaconBlockRoot);
assertThat(result).isCompletedWithValue(DutyResult.NO_OP);
}
use of tech.pegasys.teku.validator.client.duties.DutyResult in project teku by ConsenSys.
the class SyncCommitteeAggregationDuty method produceAggregates.
public SafeFuture<DutyResult> produceAggregates(final UInt64 slot, final Bytes32 beaconBlockRoot) {
final Optional<SyncCommitteeUtil> maybeSyncCommitteeUtils = spec.getSyncCommitteeUtil(slot);
if (assignments.isEmpty() || maybeSyncCommitteeUtils.isEmpty()) {
return SafeFuture.completedFuture(DutyResult.NO_OP);
}
final SyncCommitteeUtil syncCommitteeUtil = maybeSyncCommitteeUtils.get();
return forkProvider.getForkInfo(slot).thenCompose(forkInfo -> SafeFuture.collectAll(assignments.stream().flatMap(assignment -> performAggregationsForValidator(slot, beaconBlockRoot, syncCommitteeUtil, forkInfo, assignment)))).thenCompose(this::sendAggregates).exceptionally(error -> DutyResult.forError(assignments.stream().map(assignment -> assignment.getValidator().getPublicKey()).collect(Collectors.toSet()), error));
}
Aggregations