Skip to content

Commit

Permalink
Analyzer: add consensus participant and successes metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Oct 10, 2024
1 parent 45b9f3e commit 40a0360
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions internal/analyzer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ var CMD = &cobra.Command{
PrepareHighestDelay: r.PrepareHighestDelay,
PrepareMoreThanSec: strconv.FormatUint(uint64(r.PrepareDelayCount), 10) + "/" + strconv.FormatUint(uint64(r.PrepareCount), 10),
ConsensusTimeAvg: r.ConsensusTimeAvg,
ConsensusSuccessfulAttestationSubmissions: r.ConsensusSuccessfulAttestationSubmissions,
ConsensusParticipation: r.ConsensusParticipationCount,
})

if !isSet {
Expand Down
13 changes: 9 additions & 4 deletions internal/analyzer/parser/consensus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type (
}

Stats struct {
OperatorConsensusTimes map[parser.SignerID][]time.Duration
OperatorConsensusTimes map[parser.SignerID][]time.Duration
OperatorConsensusParticipation map[parser.SignerID]uint16
SuccessfullySubmittedAttestations uint16
}

Service struct {
Expand All @@ -53,7 +55,8 @@ func (s *Service) Analyze() (Stats, error) {

var (
stats Stats = Stats{
OperatorConsensusTimes: make(map[uint32][]time.Duration),
OperatorConsensusTimes: make(map[uint32][]time.Duration),
OperatorConsensusParticipation: make(map[uint32]uint16),
}
operatorConsensusParticipation = make(map[parser.DutyID]struct {
Signers []parser.SignerID
Expand All @@ -71,8 +74,8 @@ func (s *Service) Analyze() (Stats, error) {

if strings.Contains(entry.Message, partialSignatureLogRecord) {
/*
since there is no way to verify the round (given log record does not contain roundID filed) in this way we need
to make sure we save signers from the earliest round, meaning round 1
Since there is no way to verify the round (as the given log record does not contain the roundID field),
we need to ensure that we save signers from the earliest round, meaning round 1.
*/
if consensusRecord, hasRecordForDuty := operatorConsensusParticipation[entry.DutyID]; hasRecordForDuty {
if entry.Timestamp.Before(consensusRecord.Timestamp) {
Expand Down Expand Up @@ -114,10 +117,12 @@ func (s *Service) Analyze() (Stats, error) {
if exist {
for _, signerID := range signers.Signers {
stats.OperatorConsensusTimes[signerID] = append(stats.OperatorConsensusTimes[signerID], signerConsensusTime)
stats.OperatorConsensusParticipation[signerID]++
}
}
}

stats.SuccessfullySubmittedAttestations = uint16(len(consensusTimes))
return stats, nil
}

Expand Down
20 changes: 15 additions & 5 deletions internal/analyzer/report/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ var operatorHeaders = []string{
"Prepare: highest",
"Prepare: > 1sec",
"Consensus: avg",
"Consensus: \n operator participation",
"Consensus: \n successful attestation submissions",
}

type OperatorRecord struct {
OperatorID uint64
IsLogFileOwner bool
Score uint64
CommitDelayTotal time.Duration
OperatorID uint64
IsLogFileOwner bool
Score uint64
CommitDelayTotal time.Duration

PrepareDelayAvg time.Duration
PrepareHighestDelay time.Duration
PrepareMoreThanSec string
ConsensusTimeAvg time.Duration

ConsensusTimeAvg time.Duration
ConsensusSuccessfulAttestationSubmissions,
ConsensusParticipation uint16
}

type OperatorReport struct {
Expand Down Expand Up @@ -74,6 +80,8 @@ func (r *OperatorReport) AddRecord(record OperatorRecord) {
record.PrepareHighestDelay.String(),
record.PrepareMoreThanSec,
record.ConsensusTimeAvg.String(),
fmt.Sprint(record.ConsensusParticipation),
fmt.Sprint(record.ConsensusSuccessfulAttestationSubmissions),
)
return
}
Expand All @@ -86,6 +94,8 @@ func (r *OperatorReport) AddRecord(record OperatorRecord) {
record.PrepareHighestDelay.String(),
record.PrepareMoreThanSec,
record.ConsensusTimeAvg.String(),
fmt.Sprint(record.ConsensusParticipation),
fmt.Sprint(record.ConsensusSuccessfulAttestationSubmissions),
)
}

Expand Down
4 changes: 4 additions & 0 deletions internal/analyzer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type (
PrepareCount uint16

ConsensusTimeAvg time.Duration
ConsensusParticipationCount,
ConsensusSuccessfulAttestationSubmissions uint16
}

AnalyzerResult struct {
Expand Down Expand Up @@ -134,6 +136,8 @@ func (r *Service) Start() (AnalyzerResult, error) {
PrepareCount: prepareStats[operatorID].Count,

ConsensusTimeAvg: consensusDurationAvg,
ConsensusSuccessfulAttestationSubmissions: consensusStats.SuccessfullySubmittedAttestations,
ConsensusParticipationCount: consensusStats.OperatorConsensusParticipation[operatorID],
})
}

Expand Down

0 comments on commit 40a0360

Please sign in to comment.