prysm-pulse/validator/client/log.go
Raul Jordan acfafd3f0d
Add More Visibility Into Sync Committee Message Participation (#10943)
* build

* granular time message

* timing

* log

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-06-27 23:01:24 +00:00

105 lines
3.4 KiB
Go

package client
import (
"fmt"
"sync/atomic"
"time"
"github.com/prysmaticlabs/prysm/config/params"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
prysmTime "github.com/prysmaticlabs/prysm/time"
"github.com/prysmaticlabs/prysm/time/slots"
"github.com/sirupsen/logrus"
)
var log = logrus.WithField("prefix", "validator")
type attSubmitted struct {
data *ethpb.AttestationData
attesterIndices []types.ValidatorIndex
aggregatorIndices []types.ValidatorIndex
}
// LogAttestationsSubmitted logs info about submitted attestations.
func (v *validator) LogAttestationsSubmitted() {
v.attLogsLock.Lock()
defer v.attLogsLock.Unlock()
for _, attLog := range v.attLogs {
log.WithFields(logrus.Fields{
"Slot": attLog.data.Slot,
"CommitteeIndex": attLog.data.CommitteeIndex,
"BeaconBlockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.BeaconBlockRoot)),
"SourceEpoch": attLog.data.Source.Epoch,
"SourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.Source.Root)),
"TargetEpoch": attLog.data.Target.Epoch,
"TargetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.Target.Root)),
"AttesterIndices": attLog.attesterIndices,
"AggregatorIndices": attLog.aggregatorIndices,
}).Info("Submitted new attestations")
}
v.attLogs = make(map[[32]byte]*attSubmitted)
}
// LogSyncCommitteeMessagesSubmitted logs info about submitted sync committee messages.
func (v *validator) LogSyncCommitteeMessagesSubmitted() {
log.WithField("messages", v.syncCommitteeStats.totalMessagesSubmitted).Debug("Submitted sync committee messages successfully to beacon node")
// Reset the amount.
atomic.StoreUint64(&v.syncCommitteeStats.totalMessagesSubmitted, 0)
}
// LogNextDutyTimeLeft logs the next duty info.
func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error {
if !v.logDutyCountDown {
return nil
}
if v.duties == nil {
return nil
}
var nextDutySlot types.Slot
attestingCounts := make(map[types.Slot]uint64)
proposingCounts := make(map[types.Slot]uint64)
for _, duty := range v.duties.CurrentEpochDuties {
attestingCounts[duty.AttesterSlot]++
if duty.AttesterSlot > slot && (nextDutySlot > duty.AttesterSlot || nextDutySlot == 0) {
nextDutySlot = duty.AttesterSlot
}
for _, proposerSlot := range duty.ProposerSlots {
proposingCounts[proposerSlot]++
if proposerSlot > slot && (nextDutySlot > proposerSlot || nextDutySlot == 0) {
nextDutySlot = proposerSlot
}
}
}
if nextDutySlot == 0 {
log.WithField("slotInEpoch", slot%params.BeaconConfig().SlotsPerEpoch).Info("No duty until next epoch")
} else {
nextDutyTime, err := slots.ToTime(v.genesisTime, nextDutySlot)
if err != nil {
return err
}
timeLeft := time.Duration(nextDutyTime.Unix() - prysmTime.Now().Unix()).Nanoseconds()
// There is not much value to log if time left is less than one slot.
if uint64(timeLeft) >= params.BeaconConfig().SecondsPerSlot {
log.WithFields(
logrus.Fields{
"currentSlot": slot,
"dutySlot": nextDutySlot,
"attesting": attestingCounts[nextDutySlot],
"proposing": proposingCounts[nextDutySlot],
"slotInEpoch": slot % params.BeaconConfig().SlotsPerEpoch,
"secondsLeft": timeLeft,
}).Info("Next duty")
}
}
return nil
}