Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKiwi committed Apr 19, 2020
1 parent f0c8c5e commit e402645
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
41 changes: 23 additions & 18 deletions beacon-chain/rpc/validator/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,30 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth
}

idx, ok := s.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey))
if !ok {
// If the validator isn't in the beacon state, assume it is not active.
continue
}
ca, ok := committeeAssignments[idx]
if ok {
assignment.Committee = ca.Committee
assignment.Status = vs.assignmentStatus(idx, s)
assignment.ValidatorIndex = idx
assignment.PublicKey = pubKey
assignment.AttesterSlot = ca.AttesterSlot
assignment.ProposerSlots = proposerIndexToSlots[idx]
assignment.CommitteeIndex = ca.CommitteeIndex
committeeIDs = append(committeeIDs, ca.CommitteeIndex)
}
// Save the next epoch assignments.
ca, ok = nextCommitteeAssignments[idx]
if ok {
nextCommitteeIDs = append(nextCommitteeIDs, ca.CommitteeIndex)
ca, ok := committeeAssignments[idx]
if ok {
assignment.Committee = ca.Committee
assignment.Status = vs.assignmentStatus(idx, s)
assignment.ValidatorIndex = idx
assignment.PublicKey = pubKey
assignment.AttesterSlot = ca.AttesterSlot
assignment.ProposerSlots = proposerIndexToSlots[idx]
assignment.CommitteeIndex = ca.CommitteeIndex
committeeIDs = append(committeeIDs, ca.CommitteeIndex)
}
// Save the next epoch assignments.
ca, ok = nextCommitteeAssignments[idx]
if ok {
nextCommitteeIDs = append(nextCommitteeIDs, ca.CommitteeIndex)
}

} else {
vStatus, _, err := vs.retrieveStatusFromState(ctx, pubKey, s)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not retrieve status from state: %v", err)
}
assignment.Status = vStatus
}
validatorAssignments = append(validatorAssignments, assignment)
}
Expand Down
8 changes: 4 additions & 4 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +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))
}

if duty.Status != ethpb.ValidatorStatus_ACTIVE {
continue
}

lFields := logrus.Fields{
"pubKey": fmt.Sprintf("%#x", bytesutil.Trunc(duty.PublicKey)),
"validatorIndex": duty.ValidatorIndex,
Expand Down

0 comments on commit e402645

Please sign in to comment.