Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions sync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type metrics struct {
requestRangeTimeHist metric.Float64Histogram
requestRangeStartTS time.Time

blockTime metric.Float64Histogram
prevHeader time.Time
blockTime metric.Float64Histogram
prevHeaderTs time.Time
}

func newMetrics() (*metrics, error) {
Expand Down Expand Up @@ -213,12 +213,18 @@ func (m *metrics) updateGetRangeRequestInfo(ctx context.Context, amount uint64,
})
}

func (m *metrics) newSubjectiveHead(ctx context.Context, height uint64, timestamp time.Time) {
func (m *metrics) newNetHead(ctx context.Context, height uint64, timestamp time.Time) {
m.observe(ctx, func(ctx context.Context) {
m.subjectiveHead.Store(height)

if !m.prevHeader.IsZero() {
m.blockTime.Record(ctx, timestamp.Sub(m.prevHeader).Seconds())
if timestamp.After(m.prevHeaderTs) {
if !m.prevHeaderTs.IsZero() {
m.blockTime.Record(ctx, timestamp.Sub(m.prevHeaderTs).Seconds(),
metric.WithAttributes(
otelattr.Uint64("height", height),
))
}
m.prevHeaderTs = time.Now()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for setting up a time.Now() as the original idea was to calculate how much time it takes to get the header through the network after it was produced.

}
})
}
Expand Down
2 changes: 1 addition & 1 deletion sync/syncer_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func (s *Syncer[H]) setLocalHead(ctx context.Context, netHead H) {
"hash", netHead.Hash().String(),
"err", err)
}
s.metrics.newSubjectiveHead(s.ctx, netHead.Height(), netHead.Time())

storeHead, err := s.store.Head(ctx)
if err == nil && storeHead.Height() >= netHead.Height() {
Expand All @@ -227,6 +226,7 @@ func (s *Syncer[H]) incomingNetworkHead(ctx context.Context, head H) error {
}

s.setLocalHead(ctx, head)
s.metrics.newNetHead(s.ctx, head.Height(), head.Time())
return nil
}

Expand Down