2019-08-24 17:51:00 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
2020-01-27 21:48:16 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-11-27 05:08:18 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-01-27 21:48:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
2020-01-31 20:57:01 +00:00
|
|
|
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
2020-01-27 21:48:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2019-08-24 17:51:00 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var log = logrus.WithField("prefix", "blockchain")
|
|
|
|
|
|
|
|
// logs state transition related data every slot.
|
2020-01-07 23:45:29 +00:00
|
|
|
func logStateTransitionData(b *ethpb.BeaconBlock) {
|
2019-08-24 17:51:00 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"slot": b.Slot,
|
|
|
|
"attestations": len(b.Body.Attestations),
|
|
|
|
"deposits": len(b.Body.Deposits),
|
2019-10-01 20:05:17 +00:00
|
|
|
}).Info("Finished applying state transition")
|
2019-08-24 17:51:00 +00:00
|
|
|
}
|
2020-01-27 21:48:16 +00:00
|
|
|
|
2020-01-31 20:57:01 +00:00
|
|
|
func logEpochData(beaconState *stateTrie.BeaconState) {
|
2020-01-27 21:48:16 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"epoch": helpers.CurrentEpoch(beaconState),
|
2020-02-06 03:26:15 +00:00
|
|
|
"finalizedEpoch": beaconState.FinalizedCheckpointEpoch(),
|
2020-01-31 20:57:01 +00:00
|
|
|
"justifiedEpoch": beaconState.CurrentJustifiedCheckpoint().Epoch,
|
|
|
|
"previousJustifiedEpoch": beaconState.PreviousJustifiedCheckpoint().Epoch,
|
2020-01-27 21:48:16 +00:00
|
|
|
}).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{
|
2020-01-31 20:57:01 +00:00
|
|
|
"totalValidators": len(beaconState.Validators()),
|
2020-01-27 21:48:16 +00:00
|
|
|
"activeValidators": len(activeVals),
|
2020-01-31 20:57:01 +00:00
|
|
|
"averageBalance": fmt.Sprintf("%.5f ETH", averageBalance(beaconState.Balances())),
|
2020-01-27 21:48:16 +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)
|
|
|
|
}
|