prysm-pulse/beacon-chain/blockchain/forkchoice/log.go
Preston Van Loon 27e7be6279
Add & use FinalizedCheckpointEpoch() to state (#4766)
* Add and use FinalizedCheckpointEpoch() to state
* comment
2020-02-06 03:26:15 +00:00

52 lines
1.7 KiB
Go

package forkchoice
import (
"fmt"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
)
var log = logrus.WithField("prefix", "forkchoice")
// logs epoch related data during epoch boundary.
func logEpochData(beaconState *stateTrie.BeaconState) {
var prevJustifiedEpoch uint64
var currJustifiedEpoch uint64
finalizedEpoch := beaconState.FinalizedCheckpointEpoch()
prevJustifiedCpt := beaconState.PreviousJustifiedCheckpoint()
if prevJustifiedCpt != nil {
prevJustifiedEpoch = prevJustifiedCpt.Epoch
}
currJustifiedCpt := beaconState.CurrentJustifiedCheckpoint()
if currJustifiedCpt != nil {
currJustifiedEpoch = currJustifiedCpt.Epoch
}
log.WithFields(logrus.Fields{
"epoch": helpers.CurrentEpoch(beaconState),
"finalizedEpoch": finalizedEpoch,
"justifiedEpoch": currJustifiedEpoch,
"previousJustifiedEpoch": prevJustifiedEpoch,
}).Info("Starting next epoch")
activeVals, err := helpers.ActiveValidatorIndices(beaconState, helpers.CurrentEpoch(beaconState))
if err != nil {
log.WithError(err).Error("Could not get active validator indices")
return
}
log.WithFields(logrus.Fields{
"totalValidators": beaconState.NumValidators(),
"activeValidators": len(activeVals),
"averageBalance": fmt.Sprintf("%.5f ETH", averageBalance(beaconState.Balances())),
}).Info("Validator registry information")
}
func averageBalance(balances []uint64) float64 {
total := uint64(0)
for i := 0; i < len(balances); i++ {
total += balances[i]
}
return float64(total) / float64(len(balances)) / float64(params.BeaconConfig().GweiPerEth)
}