From b996824446ec811a4320f4f5be8f246accf74022 Mon Sep 17 00:00:00 2001 From: Potuz Date: Tue, 3 Nov 2020 20:47:12 -0300 Subject: [PATCH] call LogValidatorGainsAndLosses at end of epoch (#7708) * call LogValidatorGainsAndLosses at end of epoch * Reviewer fixes Co-authored-by: terence tsao --- validator/client/metrics.go | 5 +++-- validator/client/runner.go | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/validator/client/metrics.go b/validator/client/metrics.go index 27a7591a9..cc27fe39d 100644 --- a/validator/client/metrics.go +++ b/validator/client/metrics.go @@ -7,6 +7,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" + "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/sirupsen/logrus" @@ -122,8 +123,8 @@ var ( // and penalties over time, percentage gain/loss, and gives the end user a better idea // of how the validator performs with respect to the rest. func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) error { - if slot%params.BeaconConfig().SlotsPerEpoch != 0 || slot <= params.BeaconConfig().SlotsPerEpoch { - // Do nothing unless we are at the start of the epoch, and not in the first epoch. + if !helpers.IsEpochEnd(slot) || slot <= params.BeaconConfig().SlotsPerEpoch { + // Do nothing unless we are at the end of the epoch, and not in the first epoch. return nil } if !v.logValidatorBalances { diff --git a/validator/client/runner.go b/validator/client/runner.go index 92af44532..cbe994815 100644 --- a/validator/client/runner.go +++ b/validator/client/runner.go @@ -114,12 +114,9 @@ func run(ctx context.Context, v Validator) { deadline := v.SlotDeadline(slot) slotCtx, cancel := context.WithDeadline(ctx, deadline) - // Report this validator client's rewards and penalties throughout its lifecycle. + log := log.WithField("slot", slot) log.WithField("deadline", deadline).Debug("Set deadline for proposals and attestations") - if err := v.LogValidatorGainsAndLosses(slotCtx, slot); err != nil { - log.WithError(err).Error("Could not report validator's rewards/penalties") - } // Keep trying to update assignments if they are nil or if we are past an // epoch transition in the beacon node's state. @@ -176,6 +173,10 @@ func run(ctx context.Context, v Validator) { if err := v.SaveProtections(ctx); err != nil { log.WithError(err).Error("Could not save validator protection") } + // Log this client performance in the previous epoch + if err := v.LogValidatorGainsAndLosses(slotCtx, slot); err != nil { + log.WithError(err).Error("Could not report validator's rewards/penalties") + } span.End() }() }