Skip to content

Commit

Permalink
fix: pass ctx where it is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Dec 15, 2023
1 parent 946fd44 commit 0110d1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions sync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,26 @@ func (m *metrics) recordTotalSynced(totalSynced int) {
m.totalSynced.Add(int64(totalSynced))
}

func (m *metrics) recordSyncLoopStarted() {
func (m *metrics) recordSyncLoopStarted(ctx context.Context) {
if m == nil {
return
}
m.syncLoopStarted.Add(context.Background(), 1)
m.syncLoopStarted.Add(ctx, 1)
}

func (m *metrics) recordTrustedPeersOutOfSync() {
func (m *metrics) recordTrustedPeersOutOfSync(ctx context.Context) {
if m == nil {
return
}
m.trustedPeersOutOfSync.Add(context.Background(), 1)
m.trustedPeersOutOfSync.Add(ctx, 1)
}

func (m *metrics) observeNewSubjectiveHead(height int64, timestamp time.Time) {
func (m *metrics) observeNewSubjectiveHead(ctx context.Context, height int64, timestamp time.Time) {
if m == nil {
return
}
m.subjectiveHead.Store(height)

ctx := context.Background()
if !m.prevHeader.IsZero() {
m.blockTime.Record(ctx, timestamp.Sub(m.prevHeader).Seconds())
}
Expand Down
2 changes: 1 addition & 1 deletion sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *Syncer[H]) syncLoop() {
for {
select {
case <-s.triggerSync:
s.metrics.recordSyncLoopStarted()
s.metrics.recordSyncLoopStarted(s.ctx)
s.sync(s.ctx)
case <-s.ctx.Done():
return
Expand Down
4 changes: 2 additions & 2 deletions sync/sync_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *Syncer[H]) subjectiveHead(ctx context.Context) (H, error) {
log.Warnw("subjective initialization with an old header", "height", trustHead.Height())
}
log.Warn("trusted peer is out of sync")
s.metrics.recordTrustedPeersOutOfSync()
s.metrics.recordTrustedPeersOutOfSync(s.ctx)
return trustHead, nil
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *Syncer[H]) setSubjectiveHead(ctx context.Context, netHead H) {
s.pending.Add(netHead)
s.wantSync()
log.Infow("new network head", "height", netHead.Height(), "hash", netHead.Hash())
s.metrics.observeNewSubjectiveHead(int64(netHead.Height()), netHead.Time())
s.metrics.observeNewSubjectiveHead(s.ctx, int64(netHead.Height()), netHead.Time())
}

// incomingNetworkHead processes new potential network headers.
Expand Down

0 comments on commit 0110d1f

Please sign in to comment.