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));
}
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);
}
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)));
}
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);
}
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");
}
Aggregations