Search in sources :

Example 1 with AttesterDuties

use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.

the class ValidatorApiHandlerTest method getAttestationDuties_shouldAllowOneEpochTolerance.

@Test
public void getAttestationDuties_shouldAllowOneEpochTolerance() {
    final BeaconState state = createStateWithActiveValidators();
    final BLSPublicKey validator1Key = BLSPublicKey.fromBytesCompressed(state.getValidators().get(1).getPubkeyBytes());
    when(chainDataClient.getStateAtSlotExact(PREVIOUS_EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
    when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(2));
    final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of(1, 32));
    final Optional<AttesterDuties> duties = assertCompletedSuccessfully(result);
    assertThat(duties.orElseThrow().getDuties()).containsExactly(new AttesterDuty(validator1Key, 1, 4, 0, 1, 1, UInt64.valueOf(108)));
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with AttesterDuties

use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.

the class ValidatorApiHandlerTest method getAttestationDuties_shouldUsePreviousDutyDependentRootWhenStateFromSameEpoch.

@Test
public void getAttestationDuties_shouldUsePreviousDutyDependentRootWhenStateFromSameEpoch() {
    final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
    when(chainDataClient.getStateAtSlotExact(any())).thenReturn(completedFuture(Optional.of(state)));
    when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(ONE));
    final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of());
    final AttesterDuties duties = assertCompletedSuccessfully(result).orElseThrow();
    assertThat(duties.getDependentRoot()).isEqualTo(spec.getPreviousDutyDependentRoot(state));
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with AttesterDuties

use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.

the class ValidatorApiHandler method getAttestationDuties.

@Override
public SafeFuture<Optional<AttesterDuties>> getAttestationDuties(final UInt64 epoch, final IntCollection validatorIndices) {
    if (isSyncActive()) {
        return NodeSyncingException.failedFuture();
    }
    if (epoch.isGreaterThan(combinedChainDataClient.getCurrentEpoch().plus(spec.getSpecConfig(epoch).getMinSeedLookahead() + DUTY_EPOCH_TOLERANCE))) {
        return SafeFuture.failedFuture(new IllegalArgumentException(String.format("Attestation duties were requested %s epochs ahead, only 1 epoch in future is supported.", epoch.minus(combinedChainDataClient.getCurrentEpoch()).toString())));
    }
    final UInt64 slot = spec.getEarliestQueryableSlotForBeaconCommitteeInTargetEpoch(epoch);
    LOG.trace("Retrieving attestation duties from epoch {} using state at slot {}", epoch, slot);
    return combinedChainDataClient.getStateAtSlotExact(slot).thenApply(optionalState -> optionalState.map(state -> getAttesterDutiesFromIndicesAndState(state, epoch, validatorIndices)));
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) BeaconPreparableProposer(tech.pegasys.teku.spec.datastructures.operations.versions.bellatrix.BeaconPreparableProposer) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) BiFunction(java.util.function.BiFunction) GENESIS_SLOT(tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Collectors.toMap(java.util.stream.Collectors.toMap) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) VALIDATOR_LOGGER(tech.pegasys.teku.infrastructure.logging.ValidatorLogger.VALIDATOR_LOGGER) Map(java.util.Map) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) ValidatorResponse(tech.pegasys.teku.api.response.v1.beacon.ValidatorResponse) Bytes32(org.apache.tuweni.bytes.Bytes32) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) IntSets(it.unimi.dsi.fastutil.ints.IntSets) SendSignedBlockResult(tech.pegasys.teku.validator.api.SendSignedBlockResult) BLSSignature(tech.pegasys.teku.bls.BLSSignature) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) Collection(java.util.Collection) Set(java.util.Set) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) List(java.util.List) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) Logger(org.apache.logging.log4j.Logger) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) NodeSyncingException(tech.pegasys.teku.validator.api.NodeSyncingException) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) HashMap(java.util.HashMap) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) IntCollection(it.unimi.dsi.fastutil.ints.IntCollection) SpecVersion(tech.pegasys.teku.spec.SpecVersion) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) ValidatorStatus(tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SubnetSubscription(tech.pegasys.teku.spec.datastructures.validator.SubnetSubscription) LogFormatter.formatBlock(tech.pegasys.teku.infrastructure.logging.LogFormatter.formatBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) CommitteeSubscriptionRequest(tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) PerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) Collectors.toList(java.util.stream.Collectors.toList) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) SyncStateProvider(tech.pegasys.teku.beacon.sync.events.SyncStateProvider) IntSet(it.unimi.dsi.fastutil.ints.IntSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 4 with AttesterDuties

use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.

the class AttestationDutySchedulerTest method shouldDelayExecutingDutiesUntilSchedulingIsComplete.

@Test
public void shouldDelayExecutingDutiesUntilSchedulingIsComplete() {
    createDutySchedulerWithMockDuties();
    final SafeFuture<Optional<AttesterDuties>> epoch0Duties = new SafeFuture<>();
    when(validatorApiChannel.getAttestationDuties(eq(ZERO), any())).thenReturn(epoch0Duties);
    when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), emptyList()))));
    dutyScheduler.onSlot(ZERO);
    dutyScheduler.onBlockProductionDue(ZERO);
    dutyScheduler.onAttestationCreationDue(ZERO);
    dutyScheduler.onAttestationAggregationDue(ZERO);
    // Duties haven't been loaded yet.
    verify(scheduledDuties, never()).performProductionDuty(ZERO);
    verify(scheduledDuties, never()).performAggregationDuty(ZERO);
    epoch0Duties.complete(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), emptyList())));
    verify(scheduledDuties).performProductionDuty(ZERO);
    verify(scheduledDuties).performAggregationDuty(ZERO);
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Test(org.junit.jupiter.api.Test)

Example 5 with AttesterDuties

use of tech.pegasys.teku.validator.api.AttesterDuties in project teku by ConsenSys.

the class AttestationDutySchedulerTest method shouldNotRefetchDutiesWhenHeadUpdateReceivedWithNoChangeInDependentRoots.

@Test
public void shouldNotRefetchDutiesWhenHeadUpdateReceivedWithNoChangeInDependentRoots() {
    createDutySchedulerWithRealDuties();
    final UInt64 currentEpoch = UInt64.valueOf(5);
    final UInt64 currentSlot = spec.computeStartSlotAtEpoch(currentEpoch);
    final UInt64 nextEpoch = currentEpoch.plus(1);
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    when(validatorApiChannel.getAttestationDuties(eq(currentEpoch), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(previousDutyDependentRoot, emptyList()))));
    when(validatorApiChannel.getAttestationDuties(eq(nextEpoch), any())).thenReturn(SafeFuture.completedFuture(Optional.of(new AttesterDuties(currentDutyDependentRoot, emptyList()))));
    dutyScheduler.onSlot(currentSlot);
    verify(validatorApiChannel).getAttestationDuties(currentEpoch, VALIDATOR_INDICES);
    verify(validatorApiChannel).getAttestationDuties(nextEpoch, VALIDATOR_INDICES);
    dutyScheduler.onHeadUpdate(currentSlot, previousDutyDependentRoot, currentDutyDependentRoot, dataStructureUtil.randomBytes32());
    verifyNoMoreInteractions(validatorApiChannel);
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Aggregations

AttesterDuties (tech.pegasys.teku.validator.api.AttesterDuties)21 Test (org.junit.jupiter.api.Test)18 Optional (java.util.Optional)12 AttesterDuty (tech.pegasys.teku.validator.api.AttesterDuty)12 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)11 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)5 AttestationProductionDuty (tech.pegasys.teku.validator.client.duties.attestations.AttestationProductionDuty)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 PostAttesterDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 CommitteeSubscriptionRequest (tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IntCollection (it.unimi.dsi.fastutil.ints.IntCollection)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 IntSets (it.unimi.dsi.fastutil.ints.IntSets)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1