Skip to content

Commit

Permalink
Refactor correctness measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Sep 3, 2024
1 parent b4b4b5c commit c070339
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions internal/benchmark/metrics/consensus/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,26 @@ func (a *AttestationMetric) fetchAttestationBlockRoot(ctx context.Context, slot
}

func (a *AttestationMetric) AggregateResults() string {
var missedAttestations, freshAttestations, missedBlocks, receivedBlocks, unreadyBlocks, correctness float64
var (
latestCorrectnessMeasurement time.Time
missedAttestations, freshAttestations, missedBlocks, receivedBlocks, unreadyBlocks, correctness float64
)

for _, point := range a.DataPoints {
missedAttestations += point.Values[MissedAttestationMeasurement]
missedBlocks += point.Values[MissedBlockMeasurement]
freshAttestations += point.Values[FreshAttestationMeasurement]
receivedBlocks += point.Values[ReceivedBlockMeasurement]
unreadyBlocks += point.Values[UnreadyBlockMeasurement]
}

correctness = freshAttestations / receivedBlocks * 100
val, ok := point.Values[CorrectnessMeasurement]
if ok {
if latestCorrectnessMeasurement.Before(point.Timestamp) {
correctness = val
latestCorrectnessMeasurement = point.Timestamp
}
}
}

return fmt.Sprintf(
"missed_attestations=%.0f, unready_blocks_%d_ms=%.0f, missed_blocks=%.0f \n fresh_attestations=%.0f received_blocks=%.0f, correctness=%.2f %%",
Expand All @@ -184,23 +193,6 @@ func (a *AttestationMetric) AggregateResults() string {
func (a *AttestationMetric) calculateMeasurements(slot phase0.Slot) {
eventBlockRoot, ok := a.eventBlockRoots.Load(slot)

var freshAttestations, receivedBlocks float64

for _, point := range a.DataPoints {
freshAttestations += point.Values[FreshAttestationMeasurement]
receivedBlocks += point.Values[ReceivedBlockMeasurement]
}

correctness := freshAttestations / receivedBlocks * 100

a.AddDataPoint(map[string]float64{
CorrectnessMeasurement: correctness,
})

logger.WriteMetric(metric.ConsensusGroup, a.Name, map[string]any{
CorrectnessMeasurement: correctness,
})

if !ok {
a.AddDataPoint(map[string]float64{
MissedBlockMeasurement: 1,
Expand All @@ -212,34 +204,55 @@ func (a *AttestationMetric) calculateMeasurements(slot phase0.Slot) {
return
}

a.AddDataPoint(map[string]float64{
ReceivedBlockMeasurement: 1,
})
logger.WriteMetric(metric.ConsensusGroup, a.Name, map[string]any{
ReceivedBlockMeasurement: 1,
})

attestationBlockRoot, ok := a.attestationBlockRoots.Load(slot)
if !ok {
a.AddDataPoint(map[string]float64{
MissedAttestationMeasurement: 1,
ReceivedBlockMeasurement: 1,
})

logger.WriteMetric(metric.ConsensusGroup, a.Name, map[string]any{
MissedAttestationMeasurement: 1,
ReceivedBlockMeasurement: 1,
})

a.calculateCorrectness()

return
}

if attestationBlockRoot == eventBlockRoot.(SlotData).RootBlock {
a.AddDataPoint(map[string]float64{
FreshAttestationMeasurement: 1,
ReceivedBlockMeasurement: 1,
})

logger.WriteMetric(metric.ConsensusGroup, a.Name, map[string]any{
FreshAttestationMeasurement: 1,
ReceivedBlockMeasurement: 1,
})
}

a.calculateCorrectness()
}

func (a *AttestationMetric) calculateCorrectness() {
var freshAttestations, receivedBlocks float64

for _, point := range a.DataPoints {
freshAttestations += point.Values[FreshAttestationMeasurement]
receivedBlocks += point.Values[ReceivedBlockMeasurement]
}

correctness := freshAttestations / receivedBlocks * 100

a.AddDataPoint(map[string]float64{
CorrectnessMeasurement: correctness,
})

logger.WriteMetric(metric.ConsensusGroup, a.Name, map[string]any{
CorrectnessMeasurement: correctness,
})
}

func slotTime(genesisTime time.Time, slot phase0.Slot) time.Time {
Expand Down

0 comments on commit c070339

Please sign in to comment.