2021-11-24 01:56:34 +00:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
2021-11-24 01:56:34 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-12-15 20:42:20 +00:00
|
|
|
// processSyncCommitteeContribution logs the event when tracked validators' aggregated sync contribution has been processed.
|
|
|
|
// TODO: We do not log if a sync contribution was included in an aggregate (we log them when they are included in blocks)
|
2021-11-24 01:56:34 +00:00
|
|
|
func (s *Service) processSyncCommitteeContribution(contribution *ethpb.SignedContributionAndProof) {
|
|
|
|
idx := contribution.Message.AggregatorIndex
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
if s.trackedIndex(idx) {
|
|
|
|
aggPerf := s.aggregatedPerformance[idx]
|
2022-08-03 18:47:30 +00:00
|
|
|
aggPerf.totalSyncCommitteeAggregations++
|
2021-11-24 01:56:34 +00:00
|
|
|
s.aggregatedPerformance[idx] = aggPerf
|
|
|
|
|
2024-02-22 22:40:36 +00:00
|
|
|
log.WithField("validatorIndex", contribution.Message.AggregatorIndex).Info("Sync committee aggregation processed")
|
2021-11-24 01:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 20:42:20 +00:00
|
|
|
// processSyncAggregate logs the event when tracked validators is a sync-committee member and its contribution has been included
|
2023-02-09 09:23:32 +00:00
|
|
|
func (s *Service) processSyncAggregate(state state.BeaconState, blk interfaces.ReadOnlyBeaconBlock) {
|
2021-11-24 01:56:34 +00:00
|
|
|
if blk == nil || blk.Body() == nil {
|
|
|
|
return
|
|
|
|
}
|
2023-06-09 05:00:36 +00:00
|
|
|
if blk.Version() == version.Phase0 {
|
|
|
|
return
|
|
|
|
}
|
2021-11-24 01:56:34 +00:00
|
|
|
bits, err := blk.Body().SyncAggregate()
|
|
|
|
if err != nil {
|
2021-12-15 20:42:20 +00:00
|
|
|
log.WithError(err).Error("Could not get SyncAggregate")
|
2021-11-24 01:56:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
for validatorIdx, committeeIndices := range s.trackedSyncCommitteeIndices {
|
|
|
|
if len(committeeIndices) > 0 {
|
|
|
|
contrib := 0
|
|
|
|
for _, idx := range committeeIndices {
|
|
|
|
if bits.SyncCommitteeBits.BitAt(uint64(idx)) {
|
|
|
|
contrib++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
balance, err := state.BalanceAtIndex(validatorIdx)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Could not get balance")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
latestPerf := s.latestPerformance[validatorIdx]
|
|
|
|
balanceChg := int64(balance - latestPerf.balance)
|
|
|
|
latestPerf.balanceChange = balanceChg
|
|
|
|
latestPerf.balance = balance
|
|
|
|
s.latestPerformance[validatorIdx] = latestPerf
|
|
|
|
|
|
|
|
aggPerf := s.aggregatedPerformance[validatorIdx]
|
2022-08-03 18:47:30 +00:00
|
|
|
aggPerf.totalSyncCommitteeContributions += uint64(contrib)
|
2021-11-24 01:56:34 +00:00
|
|
|
s.aggregatedPerformance[validatorIdx] = aggPerf
|
|
|
|
|
|
|
|
syncCommitteeContributionCounter.WithLabelValues(
|
|
|
|
fmt.Sprintf("%d", validatorIdx)).Add(float64(contrib))
|
|
|
|
|
|
|
|
log.WithFields(logrus.Fields{
|
2024-02-22 22:40:36 +00:00
|
|
|
"validatorIndex": validatorIdx,
|
|
|
|
"expectedContribCount": len(committeeIndices),
|
|
|
|
"contribCount": contrib,
|
|
|
|
"newBalance": balance,
|
|
|
|
"balanceChange": balanceChg,
|
2021-11-24 01:56:34 +00:00
|
|
|
}).Info("Sync committee contribution included")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|