-
-
Notifications
You must be signed in to change notification settings - Fork 479
feat: update vc to submit beacon committee selections once per epoch #8669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,17 @@ export class AttestationDutiesService { | |
| for (const epoch of [currentEpoch, nextEpoch]) { | ||
| const epochDuties = this.dutiesByIndexByEpoch.get(epoch)?.dutiesByIndex; | ||
| if (epochDuties) { | ||
| if (this.opts?.distributedAggregationSelection) { | ||
| // Validator in distributed cluster only has a key share, not the full private key. | ||
| // The partial selection proofs must be exchanged for combined selection proofs by | ||
| // calling submitBeaconCommitteeSelections on the distributed validator middleware client. | ||
| // This is required to correctly determine if validator is aggregator and to produce | ||
| // a AggregateAndProof that can be threshold aggregated by the middleware client. | ||
| await this.runDistributedAggregationSelectionTasks(Array.from(epochDuties.values()), epoch).catch((e) => | ||
| this.logger.error("Error on attestation aggregation selection", {epoch}, e) | ||
| ); | ||
| } | ||
|
|
||
| for (const {duty, selectionProof} of epochDuties.values()) { | ||
| if (indexSet.has(duty.validatorIndex)) { | ||
| beaconCommitteeSubscriptions.push({ | ||
|
|
@@ -367,6 +378,12 @@ export class AttestationDutiesService { | |
| const epochDuties = this.dutiesByIndexByEpoch.get(dutyEpoch)?.dutiesByIndex; | ||
|
|
||
| if (epochDuties) { | ||
| if (this.opts?.distributedAggregationSelection) { | ||
| await this.runDistributedAggregationSelectionTasks(Array.from(epochDuties.values()), dutyEpoch).catch((e) => | ||
| this.logger.error("Error on attestation aggregation selection after duties reorg", logContext, e) | ||
| ); | ||
| } | ||
|
|
||
| for (const {duty, selectionProof} of epochDuties.values()) { | ||
| beaconCommitteeSubscriptions.push({ | ||
| validatorIndex: duty.validatorIndex, | ||
|
|
@@ -403,8 +420,8 @@ export class AttestationDutiesService { | |
| if (this.opts?.distributedAggregationSelection) { | ||
| // Validator in distributed cluster only has a key share, not the full private key. | ||
| // Passing a partial selection proof to `is_aggregator` would produce incorrect result. | ||
| // AttestationService will exchange partial for combined selection proofs retrieved from | ||
| // distributed validator middleware client and determine aggregators at beginning of every slot. | ||
| // Before subscribing to beacon committee subnets, aggregators are determined by exchanging | ||
| // partial for combined selection proofs retrieved from distributed validator middleware client. | ||
| return {duty, selectionProof: null, partialSelectionProof: selectionProof}; | ||
| } | ||
|
|
||
|
|
@@ -427,4 +444,47 @@ export class AttestationDutiesService { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Performs additional attestation aggregation tasks required if validator is part of distributed cluster | ||
| * | ||
| * 1. Exchange partial for combined selection proofs | ||
| * 2. Determine validators that should aggregate attestations | ||
| * 3. Mutate duty objects to set selection proofs for aggregators | ||
| */ | ||
| private async runDistributedAggregationSelectionTasks(duties: AttDutyAndProof[], epoch: Epoch): Promise<void> { | ||
| const partialSelections: routes.validator.BeaconCommitteeSelection[] = duties.map( | ||
| ({duty, partialSelectionProof}) => ({ | ||
| validatorIndex: duty.validatorIndex, | ||
| slot: duty.slot, | ||
| selectionProof: partialSelectionProof as BLSSignature, | ||
| }) | ||
| ); | ||
|
|
||
| this.logger.debug("Submitting partial beacon committee selection proofs", {epoch, count: partialSelections.length}); | ||
|
|
||
| const res = await this.api.validator.submitBeaconCommitteeSelections({selections: partialSelections}); | ||
|
nflaig marked this conversation as resolved.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we call this with duties for a whole epoch, could consider batching the request but generally assume vc and charon run on the same host without any proxy in-between that could cause issues due to large request body size |
||
|
|
||
| const combinedSelections = res.value(); | ||
| this.logger.debug("Received combined beacon committee selection proofs", {epoch, count: combinedSelections.length}); | ||
|
|
||
| for (const dutyAndProof of duties) { | ||
| const {slot, validatorIndex, committeeIndex, committeeLength} = dutyAndProof.duty; | ||
| const logCtxValidator = {slot, index: committeeIndex, validatorIndex}; | ||
|
|
||
| const combinedSelection = combinedSelections.find((s) => s.validatorIndex === validatorIndex && s.slot === slot); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional: we can create a map of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense to do it here since attestation duties can be quite a lot depending on validator count, see #8710 |
||
|
|
||
| if (!combinedSelection) { | ||
| this.logger.warn("Did not receive combined beacon committee selection proof", logCtxValidator); | ||
| continue; | ||
| } | ||
|
|
||
| const isAggregator = isAggregatorFromCommitteeLength(committeeLength, combinedSelection.selectionProof); | ||
|
|
||
| if (isAggregator) { | ||
| // Update selection proof by mutating duty object | ||
| dutyAndProof.selectionProof = combinedSelection.selectionProof; | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the google doc is no longer accessible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committee Aggregations with Distributed Validators describes the flow as well but I don't think it's necessary to reference it in the code (there are enough comments)