2019-08-24 17:51:00 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
2020-04-29 16:57:04 +00:00
|
|
|
"encoding/hex"
|
2020-01-27 21:48:16 +00:00
|
|
|
"fmt"
|
2021-02-15 16:33:38 +00:00
|
|
|
"time"
|
2020-01-27 21:48:16 +00:00
|
|
|
|
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-08-20 18:43:03 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2021-02-10 17:24:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
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) {
|
2021-02-18 19:08:27 +00:00
|
|
|
log := log.WithField("slot", b.Slot)
|
|
|
|
if len(b.Body.Attestations) > 0 {
|
|
|
|
log = log.WithField("attestations", len(b.Body.Attestations))
|
|
|
|
}
|
|
|
|
if len(b.Body.Deposits) > 0 {
|
|
|
|
log = log.WithField("deposits", len(b.Body.Deposits))
|
|
|
|
}
|
|
|
|
if len(b.Body.AttesterSlashings) > 0 {
|
|
|
|
log = log.WithField("attesterSlashings", len(b.Body.AttesterSlashings))
|
|
|
|
}
|
|
|
|
if len(b.Body.ProposerSlashings) > 0 {
|
|
|
|
log = log.WithField("proposerSlashings", len(b.Body.ProposerSlashings))
|
|
|
|
}
|
|
|
|
if len(b.Body.VoluntaryExits) > 0 {
|
|
|
|
log = log.WithField("voluntaryExits", len(b.Body.VoluntaryExits))
|
|
|
|
}
|
|
|
|
log.Info("Finished applying state transition")
|
2019-08-24 17:51:00 +00:00
|
|
|
}
|
2020-01-27 21:48:16 +00:00
|
|
|
|
2021-02-15 16:33:38 +00:00
|
|
|
func logBlockSyncStatus(block *ethpb.BeaconBlock, blockRoot [32]byte, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error {
|
2021-02-10 17:24:40 +00:00
|
|
|
startTime, err := helpers.SlotToTime(genesisTime, block.Slot)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-04-29 16:57:04 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
2021-02-15 16:33:38 +00:00
|
|
|
"slot": block.Slot,
|
|
|
|
"slotInEpoch": block.Slot % params.BeaconConfig().SlotsPerEpoch,
|
|
|
|
"block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]),
|
|
|
|
"epoch": helpers.SlotToEpoch(block.Slot),
|
|
|
|
"finalizedEpoch": finalized.Epoch,
|
|
|
|
"finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]),
|
|
|
|
"sinceSlotStartTime": timeutils.Now().Sub(startTime),
|
|
|
|
"chainServiceProcessedTime": timeutils.Now().Sub(receivedTime),
|
2020-04-29 16:57:04 +00:00
|
|
|
}).Info("Synced new block")
|
2021-02-10 17:24:40 +00:00
|
|
|
return nil
|
2020-04-29 16:57:04 +00:00
|
|
|
}
|