From 0a965ba99f6de676100c1e4c2d7dc37b3eec7944 Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Tue, 22 Jul 2025 10:34:52 +0200 Subject: [PATCH] eth/protocols/snap: add healing and syncing metrics --- eth/protocols/snap/metrics.go | 3 +++ eth/protocols/snap/sync.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/eth/protocols/snap/metrics.go b/eth/protocols/snap/metrics.go index 6878e5b280..c5cc672cbf 100644 --- a/eth/protocols/snap/metrics.go +++ b/eth/protocols/snap/metrics.go @@ -66,4 +66,7 @@ var ( // discarded during the snap sync. largeStorageDiscardGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/discard", nil) largeStorageResumedGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/resume", nil) + + syncTimeGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/time", nil) + healTimeGauge = metrics.NewRegisteredGauge("eth/protocols/snap/heal/time", nil) ) diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index 84ceb9105e..01034475a2 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -679,12 +679,15 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error { bytecodeHealReqFails = make(chan *bytecodeHealRequest) trienodeHealResps = make(chan *trienodeHealResponse) bytecodeHealResps = make(chan *bytecodeHealResponse) + syncTime = time.Now() ) for { // Remove all completed tasks and terminate sync if everything's done s.cleanStorageTasks() s.cleanAccountTasks() if len(s.tasks) == 0 && s.healer.scheduler.Pending() == 0 { + // healing done + healTimeGauge.Update(int64(time.Since(syncTime))) return nil } // Assign all the data retrieval tasks to any free peers @@ -693,7 +696,10 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error { s.assignStorageTasks(storageResps, storageReqFails, cancel) if len(s.tasks) == 0 { - // Sync phase done, run heal phase + // Sync phase done, push elapsed time to metrics + syncTimeGauge.Update(int64(time.Since(s.startTime))) + syncTime = time.Now() + // run heal phase s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel) s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel) }