2020-07-02 17:50:05 +00:00
|
|
|
package client
|
2020-01-02 17:04:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-12-10 18:56:18 +00:00
|
|
|
"time"
|
2020-01-02 17:04:07 +00:00
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-12-10 18:56:18 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
2020-01-02 17:04:07 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
2020-12-10 18:56:18 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
2020-01-02 17:04:07 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type attSubmitted struct {
|
2020-01-02 23:45:48 +00:00
|
|
|
data *ethpb.AttestationData
|
|
|
|
attesterIndices []uint64
|
|
|
|
aggregatorIndices []uint64
|
2020-01-02 17:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *validator) LogAttestationsSubmitted() {
|
|
|
|
v.attLogsLock.Lock()
|
|
|
|
defer v.attLogsLock.Unlock()
|
|
|
|
|
|
|
|
for _, attLog := range v.attLogs {
|
|
|
|
log.WithFields(logrus.Fields{
|
2020-01-02 23:45:48 +00:00
|
|
|
"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")
|
2020-01-02 17:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v.attLogs = make(map[[32]byte]*attSubmitted)
|
|
|
|
}
|
2020-12-10 18:56:18 +00:00
|
|
|
|
|
|
|
func (v *validator) LogNextDutyTimeLeft(slot uint64) error {
|
2020-12-18 21:12:57 +00:00
|
|
|
if !v.logDutyCountDown {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-10 18:56:18 +00:00
|
|
|
var nextDutySlot uint64
|
|
|
|
var role string
|
|
|
|
for _, duty := range v.duties.CurrentEpochDuties {
|
|
|
|
if duty.AttesterSlot > slot && (nextDutySlot > duty.AttesterSlot || nextDutySlot == 0) {
|
|
|
|
nextDutySlot = duty.AttesterSlot
|
|
|
|
role = "attester"
|
|
|
|
}
|
|
|
|
for _, proposerSlot := range duty.ProposerSlots {
|
|
|
|
if proposerSlot > slot && (nextDutySlot > proposerSlot || nextDutySlot == 0) {
|
|
|
|
nextDutySlot = proposerSlot
|
|
|
|
role = "proposer"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if nextDutySlot == 0 {
|
|
|
|
log.WithField("slotInEpoch", slot%params.BeaconConfig().SlotsPerEpoch).Info("No duty until next epoch")
|
|
|
|
} else {
|
|
|
|
nextDutyTime, err := helpers.SlotToTime(v.genesisTime, nextDutySlot)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
timeLeft := time.Duration(nextDutyTime.Unix() - timeutils.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{
|
|
|
|
"role": role,
|
|
|
|
"currentSlot": slot,
|
|
|
|
"dutySlot": nextDutySlot,
|
|
|
|
"slotInEpoch": slot % params.BeaconConfig().SlotsPerEpoch,
|
|
|
|
"secondsLeft": timeLeft,
|
|
|
|
}).Info("Next duty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|