Skip to content

Commit

Permalink
Better comments for aggregator functions (#9053)
Browse files Browse the repository at this point in the history
* Better comments for aggregator functions

* Naming returned value
  • Loading branch information
terencechain committed Jun 17, 2021
1 parent e953804 commit 4d1b5f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions validator/client/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot types.Slot
v.aggregatedSlotCommitteeIDCache.Add(k, true)
v.aggregatedSlotCommitteeIDCacheLock.Unlock()

slotSig, err := v.signSlot(ctx, pubKey, slot)
slotSig, err := v.signSlotWithSelectionProof(ctx, pubKey, slot)
if err != nil {
log.Errorf("Could not sign slot: %v", err)
if v.emitAccountMetrics {
Expand Down Expand Up @@ -115,9 +115,8 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot types.Slot

}

// This implements selection logic outlined in:
// https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
func (v *validator) signSlot(ctx context.Context, pubKey [48]byte, slot types.Slot) ([]byte, error) {
// Signs input slot with domain selection proof. This is used to create the signature for aggregator selection.
func (v *validator) signSlotWithSelectionProof(ctx context.Context, pubKey [48]byte, slot types.Slot) (signature []byte, error error) {
domain, err := v.domainData(ctx, helpers.SlotToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:])
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,15 @@ func (v *validator) GetKeymanager() keymanager.IKeymanager {
return v.keyManager
}

// isAggregator checks if a validator is an aggregator of a given slot, it uses the selection algorithm outlined in:
// https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
// isAggregator checks if a validator is an aggregator of a given slot and committee,
// it uses a modulo calculated by validator count in committee and samples randomness around it.
func (v *validator) isAggregator(ctx context.Context, committee []types.ValidatorIndex, slot types.Slot, pubKey [48]byte) (bool, error) {
modulo := uint64(1)
if len(committee)/int(params.BeaconConfig().TargetAggregatorsPerCommittee) > 1 {
modulo = uint64(len(committee)) / params.BeaconConfig().TargetAggregatorsPerCommittee
}

slotSig, err := v.signSlot(ctx, pubKey, slot)
slotSig, err := v.signSlotWithSelectionProof(ctx, pubKey, slot)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 4d1b5f4

Please sign in to comment.