github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/blockchain/log.go (about) 1 package blockchain 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 "time" 7 8 "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" 9 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 10 "github.com/prysmaticlabs/prysm/proto/interfaces" 11 "github.com/prysmaticlabs/prysm/shared/params" 12 "github.com/prysmaticlabs/prysm/shared/timeutils" 13 "github.com/sirupsen/logrus" 14 ) 15 16 var log = logrus.WithField("prefix", "blockchain") 17 18 // logs state transition related data every slot. 19 func logStateTransitionData(b interfaces.BeaconBlock) { 20 log := log.WithField("slot", b.Slot) 21 if len(b.Body().Attestations()) > 0 { 22 log = log.WithField("attestations", len(b.Body().Attestations())) 23 } 24 if len(b.Body().Deposits()) > 0 { 25 log = log.WithField("deposits", len(b.Body().Deposits())) 26 } 27 if len(b.Body().AttesterSlashings()) > 0 { 28 log = log.WithField("attesterSlashings", len(b.Body().AttesterSlashings())) 29 } 30 if len(b.Body().ProposerSlashings()) > 0 { 31 log = log.WithField("proposerSlashings", len(b.Body().ProposerSlashings())) 32 } 33 if len(b.Body().VoluntaryExits()) > 0 { 34 log = log.WithField("voluntaryExits", len(b.Body().VoluntaryExits())) 35 } 36 log.Info("Finished applying state transition") 37 } 38 39 func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error { 40 startTime, err := helpers.SlotToTime(genesisTime, block.Slot()) 41 if err != nil { 42 return err 43 } 44 log.WithFields(logrus.Fields{ 45 "slot": block.Slot(), 46 "slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch, 47 "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), 48 "epoch": helpers.SlotToEpoch(block.Slot()), 49 "finalizedEpoch": finalized.Epoch, 50 "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), 51 }).Info("Synced new block") 52 log.WithFields(logrus.Fields{ 53 "slot": block.Slot, 54 "sinceSlotStartTime": timeutils.Now().Sub(startTime), 55 "chainServiceProcessedTime": timeutils.Now().Sub(receivedTime), 56 }).Debug("Sync new block times") 57 return nil 58 }