mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
7a83acf46d
* improve validator logging significantly * warn validator not yet assigned to epoch * build added * report validator logs * validator performance logging * all logging improvements * validator attest better logs * improved attester logging * average balances * dont hash useless hashes * Update validator/client/validator_propose.go Co-Authored-By: rauljordan <raul@prysmaticlabs.com> * address some comments * standardize with block root hash32, renamings * gazelle * builds * improve average eth balance * eth net gains/losses * fix tests * spacing * goimports * avg balance * update pbs * addressed preston comments * imports * gazelle
62 lines
2.4 KiB
Go
62 lines
2.4 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
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
|
|
}
|
|
req := &pb.ValidatorPerformanceRequest{
|
|
Slot: slot,
|
|
PublicKey: v.key.PublicKey.Marshal(),
|
|
}
|
|
resp, err := v.validatorClient.ValidatorPerformance(ctx, req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
newBalance := float64(resp.Balance) / float64(params.BeaconConfig().GweiPerEth)
|
|
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,
|
|
}).Infof("Validator registry information")
|
|
log.Info("Generating validator performance report from the previous epoch...")
|
|
log.WithFields(logrus.Fields{
|
|
"ethBalance": newBalance,
|
|
}).Info("New validator balance")
|
|
avgBalance := resp.AverageValidatorBalance / float32(params.BeaconConfig().GweiPerEth)
|
|
if v.prevBalance > 0 {
|
|
prevBalance := float64(v.prevBalance) / float64(params.BeaconConfig().GweiPerEth)
|
|
percentNet := (newBalance - prevBalance) / prevBalance
|
|
log.WithField("prevEthBalance", prevBalance).Info("Previous validator balance")
|
|
log.WithFields(logrus.Fields{
|
|
"eth": fmt.Sprintf("%f", newBalance-prevBalance),
|
|
"percentChange": fmt.Sprintf("%.2f%%", percentNet*100),
|
|
}).Info("Net gains/losses in eth")
|
|
}
|
|
log.WithField(
|
|
"averageEthBalance", fmt.Sprintf("%f", avgBalance),
|
|
).Info("Average eth balance per validator in the beacon chain")
|
|
v.prevBalance = resp.Balance
|
|
return nil
|
|
}
|