Search in sources :

Example 1 with DutyResult

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);
}
Also used : DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) Test(org.junit.jupiter.api.Test)

Example 2 with DutyResult

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);
}
Also used : DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 3 with DutyResult

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

Example 4 with DutyResult

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);
}
Also used : SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) Test(org.junit.jupiter.api.Test)

Example 5 with DutyResult

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));
}
Also used : ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Collection(java.util.Collection) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Collectors(java.util.stream.Collectors) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) Validator(tech.pegasys.teku.validator.client.Validator) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)

Aggregations

DutyResult (tech.pegasys.teku.validator.client.duties.DutyResult)8 Test (org.junit.jupiter.api.Test)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 SyncAggregatorSelectionData (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData)3 Validator (tech.pegasys.teku.validator.client.Validator)3 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Stream (java.util.stream.Stream)2 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 ValidatorLogger (tech.pegasys.teku.infrastructure.logging.ValidatorLogger)2 Spec (tech.pegasys.teku.spec.Spec)2 ContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof)2 SignedContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof)2 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)2