2021-11-15 17:39:55 +00:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2021-11-19 01:14:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
2021-11-15 17:39:55 +00:00
|
|
|
)
|
|
|
|
|
2021-11-19 01:14:56 +00:00
|
|
|
// ValidatorLatestPerformance keeps track of the latest participation of the validator
|
|
|
|
type ValidatorLatestPerformance struct {
|
|
|
|
attestedSlot types.Slot
|
|
|
|
inclusionSlot types.Slot
|
|
|
|
timelySource bool
|
|
|
|
timelyTarget bool
|
|
|
|
timelyHead bool
|
|
|
|
balance uint64
|
|
|
|
balanceChange uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidatorAggregatedPerformance keeps track of the accumulated performance of
|
|
|
|
// the validator since launch
|
|
|
|
type ValidatorAggregatedPerformance struct {
|
|
|
|
totalAttestedCount uint64
|
|
|
|
totalRequestedCount uint64
|
|
|
|
totalDistance uint64
|
|
|
|
totalCorrectSource uint64
|
|
|
|
totalCorrectTarget uint64
|
|
|
|
totalCorrectHead uint64
|
2021-11-22 21:20:31 +00:00
|
|
|
totalProposedCount uint64
|
2021-11-19 01:14:56 +00:00
|
|
|
totalAggregations uint64
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:39:55 +00:00
|
|
|
// ValidatorMonitorConfig contains the list of validator indices that the
|
|
|
|
// monitor service tracks, as well as the event feed notifier that the
|
|
|
|
// monitor needs to subscribe.
|
|
|
|
type ValidatorMonitorConfig struct {
|
2021-11-19 01:14:56 +00:00
|
|
|
StateGen stategen.StateManager
|
2021-11-15 17:39:55 +00:00
|
|
|
TrackedValidators map[types.ValidatorIndex]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service is the main structure that tracks validators and reports logs and
|
|
|
|
// metrics of their performances throughout their lifetime.
|
|
|
|
type Service struct {
|
2021-11-19 01:14:56 +00:00
|
|
|
config *ValidatorMonitorConfig
|
|
|
|
latestPerformance map[types.ValidatorIndex]ValidatorLatestPerformance
|
|
|
|
aggregatedPerformance map[types.ValidatorIndex]ValidatorAggregatedPerformance
|
2021-11-15 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TrackedIndex returns if the given validator index corresponds to one of the
|
|
|
|
// validators we follow
|
|
|
|
func (s *Service) TrackedIndex(idx types.ValidatorIndex) bool {
|
|
|
|
_, ok := s.config.TrackedValidators[idx]
|
|
|
|
return ok
|
|
|
|
}
|