prysm-pulse/validator/client/validator_metrics.go
frederickalcantara 6ddb5fa81a Added flag to disable rewards/penatlty logging (#2319)
* Added flag to disable rewards/penatlty logging

* Added flag disable log info validator function

* Added flag to disable rewards/penatlty logging

* Changed value to not have it log when it is on and have it logged when it's off

* Added flag to disable rewards/penatlty logging

* Built for cli & types

* fixing flag issue

* Added ctxCli to the validator struct

* Accepted change

* Fixing conditionals and merge conflicts

* Added bracket

* fixed the return statement to its proper place

* Added validator conditional for logging penalties & rewards

* Added conditional for logging penality/reward info

* Making conditional command line log refactorable

* also part of the last commit

* Changed value variable to lowercase

* Fixed if conditional for penalty reward validation

* Synced with master

* Fixed bazel build

* Syncing with master

* Sync with master

* Added true values to logValidator Balances

* Changed values from true to false

* FIX WIP

* Added variables to the validators

* Added negation for logValidatorBalances variable

The name of the flag is DisablePenaltyRewardLogFlag. Since the name of the var is logValidatorBalances. We are assuming that the variable will have a positive. It makes more sense to negate the disable flag as a value rather than keep it positive.

Co-Authored-By: frederickalcantara <frederickaalcantara@gmail.com>

* fixed password

* Remove prevBalance line
2019-04-27 11:56:11 +08:00

79 lines
2.7 KiB
Go

package client
import (
"context"
"encoding/hex"
"fmt"
"strings"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
)
// LogValidatorGainsAndLosses logs important metrics related to this validator client's
// responsibilities throughout the beacon chain's lifecycle. It logs absolute accrued rewards
// 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 {
// Do nothing if we are not at the start of a new epoch.
return nil
}
epoch := slot / params.BeaconConfig().SlotsPerEpoch
if epoch == params.BeaconConfig().GenesisEpoch {
v.prevBalance = params.BeaconConfig().MaxDepositAmount
}
var totalPrevBalance uint64
reported := false
for _, pkey := range v.pubkeys {
req := &pb.ValidatorPerformanceRequest{
Slot: slot,
PublicKey: pkey,
}
resp, err := v.validatorClient.ValidatorPerformance(ctx, req)
if err != nil {
if strings.Contains(err.Error(), "could not get validator index") {
continue
}
return err
}
tpk := hex.EncodeToString(pkey)[:12]
if !reported {
log.WithFields(logrus.Fields{
"slot": slot - params.BeaconConfig().GenesisSlot,
"epoch": (slot / params.BeaconConfig().SlotsPerEpoch) - params.BeaconConfig().GenesisEpoch,
}).Info("Start of a new epoch!")
log.WithFields(logrus.Fields{
"totalValidators": resp.TotalValidators,
"numActiveValidators": resp.TotalActiveValidators,
}).Info("Validator registry information")
log.Info("Generating validator performance report from the previous epoch...")
avgBalance := resp.AverageValidatorBalance / float32(params.BeaconConfig().GweiPerEth)
log.WithField(
"averageEthBalance", fmt.Sprintf("%f", avgBalance),
).Info("Average eth balance per validator in the beacon chain")
reported = true
}
newBalance := float64(resp.Balance) / float64(params.BeaconConfig().GweiPerEth)
if v.prevBalance > 0 {
prevBalance := float64(v.prevBalance) / float64(params.BeaconConfig().GweiPerEth)
percentNet := (newBalance - prevBalance) / prevBalance
if v.logValidatorBalances {
log.WithFields(logrus.Fields{
"prevBalance": prevBalance,
"newBalance": newBalance,
"delta": fmt.Sprintf("%f", newBalance-prevBalance),
"percentChange": fmt.Sprintf("%.2f%%", percentNet*100),
"pubKey": tpk,
}).Info("Net gains/losses in eth")
}
}
totalPrevBalance += resp.Balance
}
v.prevBalance = totalPrevBalance
return nil
}