Skip to content

Commit

Permalink
Cleanup validator runner function
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKiwi committed Apr 19, 2020
1 parent 4eedcdc commit f0c8c5e
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ func (v *validator) UpdateDuties(ctx context.Context, slot uint64) error {
alreadySubscribed := make(map[[64]byte]bool)

for _, duty := range v.duties.Duties {
if duty.Status != ethpb.ValidatorStatus_ACTIVE {
continue
}

if v.emitAccountMetrics {
fmtKey := fmt.Sprintf("%#x", duty.PublicKey[:])
validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status))
}

lFields := logrus.Fields{
"pubKey": fmt.Sprintf("%#x", bytesutil.Trunc(duty.PublicKey)),
"validatorIndex": duty.ValidatorIndex,
Expand All @@ -303,37 +312,30 @@ func (v *validator) UpdateDuties(ctx context.Context, slot uint64) error {
"status": duty.Status,
}

if v.emitAccountMetrics {
fmtKey := fmt.Sprintf("%#x", duty.PublicKey[:])
validatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status))
}
attesterSlot := duty.AttesterSlot
committeeIndex := duty.CommitteeIndex

if duty.Status == ethpb.ValidatorStatus_ACTIVE {
attesterSlot := duty.AttesterSlot
committeeIndex := duty.CommitteeIndex

if len(duty.ProposerSlots) > 0 {
lFields["proposerSlots"] = duty.ProposerSlots
}
lFields["attesterSlot"] = attesterSlot
if len(duty.ProposerSlots) > 0 {
lFields["proposerSlots"] = duty.ProposerSlots
}
lFields["attesterSlot"] = attesterSlot

alreadySubscribedKey := validatorSubscribeKey(attesterSlot, committeeIndex)
if _, ok := alreadySubscribed[alreadySubscribedKey]; ok {
continue
}
alreadySubscribedKey := validatorSubscribeKey(attesterSlot, committeeIndex)
if _, ok := alreadySubscribed[alreadySubscribedKey]; ok {
continue
}

aggregator, err := v.isAggregator(ctx, duty.Committee, attesterSlot, bytesutil.ToBytes48(duty.PublicKey))
if err != nil {
return errors.Wrap(err, "could not check if a validator is an aggregator")
}
if aggregator {
alreadySubscribed[alreadySubscribedKey] = true
}
subscribeSlots = append(subscribeSlots, attesterSlot)
subscribeCommitteeIDs = append(subscribeCommitteeIDs, committeeIndex)
subscribeIsAggregator = append(subscribeIsAggregator, aggregator)
log.WithFields(lFields).Info("New assignment")
aggregator, err := v.isAggregator(ctx, duty.Committee, attesterSlot, bytesutil.ToBytes48(duty.PublicKey))
if err != nil {
return errors.Wrap(err, "could not check if a validator is an aggregator")
}
if aggregator {
alreadySubscribed[alreadySubscribedKey] = true
}
subscribeSlots = append(subscribeSlots, attesterSlot)
subscribeCommitteeIDs = append(subscribeCommitteeIDs, committeeIndex)
subscribeIsAggregator = append(subscribeIsAggregator, aggregator)
log.WithFields(lFields).Info("New assignment")
}

// Notify beacon node to subscribe to the attester and aggregator subnets for the next epoch.
Expand Down

0 comments on commit f0c8c5e

Please sign in to comment.