Skip to content

Commit

Permalink
Render consensus average duration
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Oct 9, 2024
1 parent e82a4d9 commit 45b9f3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/analyzer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var CMD = &cobra.Command{

var (
isSet bool
consensusResponseTimeAvg time.Duration
consensusClientResponseTimeAvg time.Duration
consensusClientResponseTimeDelayed string
)

Expand All @@ -112,17 +112,18 @@ var CMD = &cobra.Command{
PrepareDelayAvg: r.PrepareDelayAvg,
PrepareHighestDelay: r.PrepareHighestDelay,
PrepareMoreThanSec: strconv.FormatUint(uint64(r.PrepareDelayCount), 10) + "/" + strconv.FormatUint(uint64(r.PrepareCount), 10),
ConsensusTimeAvg: r.ConsensusTimeAvg,
})

if !isSet {
consensusResponseTimeAvg = r.AttestationTimeAverage
consensusClientResponseTimeAvg = r.AttestationTimeAverage
consensusClientResponseTimeDelayed = strconv.FormatUint(uint64(r.AttestationDelayCount), 10) + "/" + strconv.FormatUint(uint64(r.AttestationTimeCount), 10)
isSet = true
}
}

consensusReport.AddRecord(report.ConsensusRecord{
ConsensusClientResponseTimeAvg: consensusResponseTimeAvg,
ConsensusClientResponseTimeAvg: consensusClientResponseTimeAvg,
ConsensusClientResponseTimeDelayed: consensusClientResponseTimeDelayed,
})

Expand Down
7 changes: 6 additions & 1 deletion internal/analyzer/report/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var operatorHeaders = []string{
"Commit: Total Delay",
"Prepare: avg",
"Prepare: highest",
"Prepare: > 1sec"}
"Prepare: > 1sec",
"Consensus: avg",
}

type OperatorRecord struct {
OperatorID uint64
Expand All @@ -26,6 +28,7 @@ type OperatorRecord struct {
PrepareDelayAvg time.Duration
PrepareHighestDelay time.Duration
PrepareMoreThanSec string
ConsensusTimeAvg time.Duration
}

type OperatorReport struct {
Expand Down Expand Up @@ -70,6 +73,7 @@ func (r *OperatorReport) AddRecord(record OperatorRecord) {
record.PrepareDelayAvg.String(),
record.PrepareHighestDelay.String(),
record.PrepareMoreThanSec,
record.ConsensusTimeAvg.String(),
)
return
}
Expand All @@ -81,6 +85,7 @@ func (r *OperatorReport) AddRecord(record OperatorRecord) {
record.PrepareDelayAvg.String(),
record.PrepareHighestDelay.String(),
record.PrepareMoreThanSec,
record.ConsensusTimeAvg.String(),
)
}

Expand Down
16 changes: 16 additions & 0 deletions internal/analyzer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type (
PrepareHighestDelay time.Duration
PrepareDelayCount,
PrepareCount uint16

ConsensusTimeAvg time.Duration
}

AnalyzerResult struct {
Expand Down Expand Up @@ -103,6 +105,18 @@ func (r *Service) Start() (AnalyzerResult, error) {
commitSignerScore := commitStats[operatorID].Score
commitTotalDelay := commitStats[operatorID].Delay

consensusDurations := consensusStats.OperatorConsensusTimes[operatorID]
var (
consensusDurationsTotal, consensusDurationAvg time.Duration
consensusDurationLen int = len(consensusDurations)
)
for _, duration := range consensusDurations {
consensusDurationsTotal += duration
}
if consensusDurationLen > 0 {
consensusDurationAvg = consensusDurationsTotal / time.Duration(consensusDurationLen)
}

result.OperatorStats = append(result.OperatorStats, OperatorStats{
OperatorID: uint64(operatorID),
IsLogFileOwner: uint64(operatorID) == uint64(operatorStats.Owner),
Expand All @@ -118,6 +132,8 @@ func (r *Service) Start() (AnalyzerResult, error) {
PrepareHighestDelay: prepareStats[operatorID].HighestDelay,
PrepareDelayCount: prepareStats[operatorID].MoreSecondDelay,
PrepareCount: prepareStats[operatorID].Count,

ConsensusTimeAvg: consensusDurationAvg,
})
}

Expand Down

0 comments on commit 45b9f3e

Please sign in to comment.