github.com/prysmaticlabs/prysm@v1.4.4/validator/client/log.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "time" 6 7 types "github.com/prysmaticlabs/eth2-types" 8 "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" 9 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 10 "github.com/prysmaticlabs/prysm/shared/bytesutil" 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", "validator") 17 18 type attSubmitted struct { 19 data *ethpb.AttestationData 20 attesterIndices []types.ValidatorIndex 21 aggregatorIndices []types.ValidatorIndex 22 } 23 24 // LogAttestationsSubmitted logs info about submitted attestations. 25 func (v *validator) LogAttestationsSubmitted() { 26 v.attLogsLock.Lock() 27 defer v.attLogsLock.Unlock() 28 29 for _, attLog := range v.attLogs { 30 log.WithFields(logrus.Fields{ 31 "Slot": attLog.data.Slot, 32 "CommitteeIndex": attLog.data.CommitteeIndex, 33 "BeaconBlockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.BeaconBlockRoot)), 34 "SourceEpoch": attLog.data.Source.Epoch, 35 "SourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.Source.Root)), 36 "TargetEpoch": attLog.data.Target.Epoch, 37 "TargetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.Target.Root)), 38 "AttesterIndices": attLog.attesterIndices, 39 "AggregatorIndices": attLog.aggregatorIndices, 40 }).Info("Submitted new attestations") 41 } 42 43 v.attLogs = make(map[[32]byte]*attSubmitted) 44 } 45 46 // LogNextDutyTimeLeft logs the next duty info. 47 func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error { 48 if !v.logDutyCountDown { 49 return nil 50 } 51 if v.duties == nil { 52 return nil 53 } 54 55 var nextDutySlot types.Slot 56 attestingCounts := make(map[types.Slot]uint64) 57 proposingCounts := make(map[types.Slot]uint64) 58 for _, duty := range v.duties.CurrentEpochDuties { 59 attestingCounts[duty.AttesterSlot]++ 60 61 if duty.AttesterSlot > slot && (nextDutySlot > duty.AttesterSlot || nextDutySlot == 0) { 62 nextDutySlot = duty.AttesterSlot 63 } 64 for _, proposerSlot := range duty.ProposerSlots { 65 proposingCounts[proposerSlot]++ 66 67 if proposerSlot > slot && (nextDutySlot > proposerSlot || nextDutySlot == 0) { 68 nextDutySlot = proposerSlot 69 } 70 } 71 } 72 73 if nextDutySlot == 0 { 74 log.WithField("slotInEpoch", slot%params.BeaconConfig().SlotsPerEpoch).Info("No duty until next epoch") 75 } else { 76 nextDutyTime, err := helpers.SlotToTime(v.genesisTime, nextDutySlot) 77 if err != nil { 78 return err 79 } 80 timeLeft := time.Duration(nextDutyTime.Unix() - timeutils.Now().Unix()).Nanoseconds() 81 // There is not much value to log if time left is less than one slot. 82 if uint64(timeLeft) >= params.BeaconConfig().SecondsPerSlot { 83 log.WithFields( 84 logrus.Fields{ 85 "currentSlot": slot, 86 "dutySlot": nextDutySlot, 87 "attesting": attestingCounts[nextDutySlot], 88 "proposing": proposingCounts[nextDutySlot], 89 "slotInEpoch": slot % params.BeaconConfig().SlotsPerEpoch, 90 "secondsLeft": timeLeft, 91 }).Info("Next duty") 92 } 93 } 94 95 return nil 96 }