From 31ee4d2017c2593fa3ce733ae091938930482699 Mon Sep 17 00:00:00 2001 From: Adam Szkoda Date: Thu, 5 Dec 2024 12:19:35 +0100 Subject: [PATCH] Fix off-by-one bug in attestation distance calculation --- pkg/monitoring.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/monitoring.go b/pkg/monitoring.go index 6b997b5..cd12c11 100644 --- a/pkg/monitoring.go +++ b/pkg/monitoring.go @@ -353,6 +353,7 @@ func MonitorAttestationsAndProposals(ctx context.Context, beacon *beaconchain.Be }) prometheus.MustRegister(totalDelayedAttestationsOverToleranceCounter) + // https://www.attestant.io/posts/defining-attestation-effectiveness/ canonicalAttestationDistances := prometheus.NewHistogram(prometheus.HistogramOpts{ Namespace: "ETH2", Name: "canonicalAttestationDistances", @@ -477,9 +478,11 @@ func MonitorAttestationsAndProposals(ctx context.Context, beacon *beaconchain.Be continue } - attestationDistance := blockSlot - phase0.Slot(attestedSlot) - // Take skipped slots into account - for s := attestedSlot; s < uint64(blockSlot); s++ { + // https://www.attestant.io/posts/defining-attestation-effectiveness/ + earliestInclusionSlot := attestedSlot + 1 + attestationDistance := blockSlot - phase0.Slot(earliestInclusionSlot) + // Do not penalize the validator for skipped slots + for s := earliestInclusionSlot; s < uint64(blockSlot); s++ { if _, ok := epochBlocks[s]; !ok { attestationDistance-- }