Search in sources :

Example 1 with SyncCommitteeDuty

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

the class PostSyncDutiesIntegrationTest method shouldGetSyncCommitteeDuties.

@Test
void shouldGetSyncCommitteeDuties() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final SafeFuture<Optional<SyncCommitteeDuties>> out = SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(VALIDATOR_KEYS.get(1).getPublicKey(), 1, IntSet.of(11))))));
    when(syncService.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
    when(validatorApiChannel.getSyncCommitteeDuties(ONE, validators)).thenReturn(out);
    Response response = post(PostSyncDuties.ROUTE.replace("{epoch}", "1"), jsonProvider.objectToJSON(validators));
    Assertions.assertThat(response.code()).isEqualTo(SC_OK);
    final PostSyncDutiesResponse dutiesResponse = jsonProvider.jsonToObject(response.body().string(), PostSyncDutiesResponse.class);
    assertThat(dutiesResponse.data.get(0)).isEqualTo(new tech.pegasys.teku.api.response.v1.validator.SyncCommitteeDuty(new BLSPubKey(VALIDATOR_KEYS.get(1).getPublicKey()), ONE, IntSet.of(11)));
}
Also used : PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Response(okhttp3.Response) PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Optional(java.util.Optional) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with SyncCommitteeDuty

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

the class SyncCommitteeDutyLoaderTest method shouldRetrieveDuties.

@Test
void shouldRetrieveDuties() {
    final UInt64 epoch = UInt64.valueOf(56);
    final UInt64 untilEpoch = spec.getSyncCommitteeUtilRequired(UInt64.ZERO).computeFirstEpochOfNextSyncCommitteePeriod(epoch).minusMinZero(1);
    when(validatorApiChannel.getSyncCommitteeDuties(epoch, validatorIndices)).thenReturn(SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(validator1.getPublicKey(), validator1Index, IntSet.of(1, 6, 25)), new SyncCommitteeDuty(validator2.getPublicKey(), validator2Index, IntSet.of(7, 50, 38)))))));
    final SyncCommitteeScheduledDuties duties = loadDuties(epoch);
    assertThat(duties.countDuties()).isEqualTo(2);
    // And should trigger subscription to subnets
    verify(validatorApiChannel).subscribeToSyncCommitteeSubnets(Set.of(new SyncCommitteeSubnetSubscription(validator1Index, IntSet.of(1, 6, 25), untilEpoch.increment()), new SyncCommitteeSubnetSubscription(validator2Index, IntSet.of(7, 50, 38), untilEpoch.increment())));
}
Also used : SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 3 with SyncCommitteeDuty

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

the class ValidatorApiHandler method getSyncCommitteeDuty.

private Optional<SyncCommitteeDuty> getSyncCommitteeDuty(final BeaconState state, final UInt64 epoch, final int validatorIndex) {
    final Optional<SyncCommitteeUtil> syncCommitteeUtil = spec.atEpoch(epoch).getSyncCommitteeUtil();
    final IntSet duties = syncCommitteeUtil.map(util -> util.getCommitteeIndices(state, epoch, UInt64.valueOf(validatorIndex))).orElse(IntSets.emptySet());
    if (duties.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new SyncCommitteeDuty(state.getValidators().get(validatorIndex).getPublicKey(), validatorIndex, duties));
}
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) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) IntSet(it.unimi.dsi.fastutil.ints.IntSet) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty)

Aggregations

Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 SyncCommitteeDuties (tech.pegasys.teku.validator.api.SyncCommitteeDuties)2 SyncCommitteeDuty (tech.pegasys.teku.validator.api.SyncCommitteeDuty)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 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BiFunction (java.util.function.BiFunction)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Response (okhttp3.Response)1