2019-08-20 18:26:43 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
2019-10-01 20:05:17 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
2020-01-31 20:57:01 +00:00
|
|
|
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
2019-08-20 18:26:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var log = logrus.WithField("prefix", "forkchoice")
|
|
|
|
|
|
|
|
// logs epoch related data during epoch boundary.
|
2020-01-31 20:57:01 +00:00
|
|
|
func logEpochData(beaconState *stateTrie.BeaconState) {
|
|
|
|
var finalizedEpoch uint64
|
|
|
|
var prevJustifiedEpoch uint64
|
|
|
|
var currJustifiedEpoch uint64
|
|
|
|
finalizedCpt := beaconState.FinalizedCheckpoint()
|
|
|
|
if finalizedCpt != nil {
|
|
|
|
finalizedEpoch = finalizedCpt.Epoch
|
|
|
|
}
|
|
|
|
prevJustifiedCpt := beaconState.PreviousJustifiedCheckpoint()
|
|
|
|
if prevJustifiedCpt != nil {
|
|
|
|
prevJustifiedEpoch = prevJustifiedCpt.Epoch
|
|
|
|
}
|
|
|
|
currJustifiedCpt := beaconState.CurrentJustifiedCheckpoint()
|
|
|
|
if currJustifiedCpt != nil {
|
|
|
|
currJustifiedEpoch = currJustifiedCpt.Epoch
|
|
|
|
}
|
2019-08-20 18:26:43 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
2019-10-01 20:05:17 +00:00
|
|
|
"epoch": helpers.CurrentEpoch(beaconState),
|
2020-01-31 20:57:01 +00:00
|
|
|
"finalizedEpoch": finalizedEpoch,
|
|
|
|
"justifiedEpoch": currJustifiedEpoch,
|
|
|
|
"previousJustifiedEpoch": prevJustifiedEpoch,
|
2019-08-20 18:26:43 +00:00
|
|
|
}).Info("Starting next epoch")
|
2019-10-01 20:05:17 +00:00
|
|
|
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{
|
2020-01-31 20:57:01 +00:00
|
|
|
"totalValidators": beaconState.NumValidators(),
|
2019-10-01 20:05:17 +00:00
|
|
|
"activeValidators": len(activeVals),
|
2020-01-31 20:57:01 +00:00
|
|
|
"averageBalance": fmt.Sprintf("%.5f ETH", averageBalance(beaconState.Balances())),
|
2019-10-01 20:05:17 +00:00
|
|
|
}).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)
|
2019-08-20 18:26:43 +00:00
|
|
|
}
|