Search in sources :

Example 1 with SyncAggregatorSelectionData

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData in project teku by ConsenSys.

the class SyncCommitteeAggregationDutyTest method withValidatorAggregatingSubnet.

private void withValidatorAggregatingSubnet(final Validator validator, final int subcommitteeIndex) {
    final SyncAggregatorSelectionData expectedSigningData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.valueOf(subcommitteeIndex));
    when(validator.getSigner().signSyncCommitteeSelectionProof(expectedSigningData, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregatorSignature));
    // Provide defaults to ensure the aggregation succeeds
    when(validatorApiChannel.createSyncCommitteeContribution(slot, subcommitteeIndex, beaconBlockRoot)).thenReturn(SafeFuture.completedFuture(Optional.of(contribution)));
    when(validator.getSigner().signContributionAndProof(contributionAndProof, forkInfo)).thenReturn(SafeFuture.completedFuture(contributionSignature));
}
Also used : SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData)

Example 2 with SyncAggregatorSelectionData

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData 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 3 with SyncAggregatorSelectionData

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData in project teku by ConsenSys.

the class SyncCommitteeAggregationDuty method performAggregationIfRequired.

private SafeFuture<AggregationResult> performAggregationIfRequired(final SyncCommitteeUtil syncCommitteeUtil, final ForkInfo forkInfo, final ValidatorAndCommitteeIndices assignment, final int subcommitteeIndex, final UInt64 slot, final Bytes32 beaconBlockRoot) {
    final SyncAggregatorSelectionData selectionData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.valueOf(subcommitteeIndex));
    final Validator validator = assignment.getValidator();
    return validator.getSigner().signSyncCommitteeSelectionProof(selectionData, forkInfo).thenCompose(selectionProof -> {
        if (syncCommitteeUtil.isSyncCommitteeAggregator(selectionProof)) {
            return performAggregation(syncCommitteeUtil, forkInfo, assignment, subcommitteeIndex, slot, beaconBlockRoot, selectionProof);
        } else {
            return SafeFuture.completedFuture(new AggregationResult(validator.getPublicKey(), DutyResult.NO_OP));
        }
    }).exceptionally(error -> new AggregationResult(validator.getPublicKey(), DutyResult.forError(validator.getPublicKey(), 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) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Validator(tech.pegasys.teku.validator.client.Validator)

Example 4 with SyncAggregatorSelectionData

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData in project web3signer by ConsenSys.

the class Eth2RequestUtils method createSyncCommitteeSelectionProofRequest.

private static Eth2SigningRequestBody createSyncCommitteeSelectionProofRequest() {
    final ForkInfo forkInfo = forkInfo();
    final UInt64 subcommitteeIndex = UInt64.ZERO;
    final SyncAggregatorSelectionData selectionData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, subcommitteeIndex);
    final Bytes signingRoot;
    try {
        signingRoot = signingRootFromSyncCommitteeUtils(slot, utils -> utils.getSyncAggregatorSelectionDataSigningRoot(selectionData, forkInfo.asInternalForkInfo())).get();
    } catch (final InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
    return new Eth2SigningRequestBody(ArtifactType.SYNC_COMMITTEE_SELECTION_PROOF, signingRoot, forkInfo, null, null, null, null, null, null, null, null, null, getSyncAggregatorSelectionData(slot, subcommitteeIndex), null);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) ForkInfo(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with SyncAggregatorSelectionData

use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData in project teku by ConsenSys.

the class ChainBuilder method createValidSignedContributionAndProofBuilder.

public SignedContributionAndProofTestBuilder createValidSignedContributionAndProofBuilder(final UInt64 slot, final Bytes32 beaconBlockRoot) {
    final SyncCommitteeUtil syncCommitteeUtil = spec.getSyncCommitteeUtilRequired(slot);
    final SignedBlockAndState latestBlockAndState = getLatestBlockAndState();
    final UInt64 epoch = syncCommitteeUtil.getEpochForDutiesAtSlot(slot);
    final Map<UInt64, SyncSubcommitteeAssignments> subcommitteeAssignments = syncCommitteeUtil.getSyncSubcommittees(latestBlockAndState.getState(), epoch);
    for (Map.Entry<UInt64, SyncSubcommitteeAssignments> entry : subcommitteeAssignments.entrySet()) {
        final UInt64 validatorIndex = entry.getKey();
        final Signer signer = getSigner(validatorIndex.intValue());
        final SyncSubcommitteeAssignments assignments = entry.getValue();
        for (int subcommitteeIndex : assignments.getAssignedSubcommittees()) {
            final SyncAggregatorSelectionData syncAggregatorSelectionData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.valueOf(subcommitteeIndex));
            final BLSSignature proof = signer.signSyncCommitteeSelectionProof(syncAggregatorSelectionData, latestBlockAndState.getState().getForkInfo()).join();
            if (syncCommitteeUtil.isSyncCommitteeAggregator(proof)) {
                return new SignedContributionAndProofTestBuilder().signerProvider(this::getSigner).syncCommitteeUtil(syncCommitteeUtil).spec(spec).state(latestBlockAndState.getState()).subcommitteeIndex(subcommitteeIndex).slot(slot).selectionProof(proof).beaconBlockRoot(beaconBlockRoot).aggregator(validatorIndex, signer);
            }
        }
    }
    throw new IllegalStateException("No valid sync subcommittee aggregators found");
}
Also used : SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) SignedContributionAndProofTestBuilder(tech.pegasys.teku.core.synccomittee.SignedContributionAndProofTestBuilder) Signer(tech.pegasys.teku.core.signatures.Signer) LocalSigner(tech.pegasys.teku.core.signatures.LocalSigner) SyncSubcommitteeAssignments(tech.pegasys.teku.spec.datastructures.util.SyncSubcommitteeAssignments) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Aggregations

SyncAggregatorSelectionData (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData)7 Test (org.junit.jupiter.api.Test)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)2 DutyResult (tech.pegasys.teku.validator.client.duties.DutyResult)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1