From 93481b284348d72e277cbe36561eb5709b3f26e1 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 22 Jul 2025 23:25:44 +0800 Subject: [PATCH] eth/protocols/snap: add logs --- eth/protocols/snap/sync.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index 01034475a2..ed94123613 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -502,8 +502,11 @@ type Syncer struct { storageHealed uint64 // Number of storage slots downloaded during the healing stage storageHealedBytes common.StorageSize // Number of raw storage bytes persisted to disk during the healing stage - startTime time.Time // Time instance when snapshot sync started - logTime time.Time // Time instance when status was last reported + startTime time.Time // Time instance when snapshot sync started + healStartTime time.Time // Time instance when the state healing started + syncTimeOnce sync.Once // Ensure that the state sync time is uploaded only once + healTimeOnce sync.Once // Ensure that the state healing time is uploaded only once + logTime time.Time // Time instance when status was last reported pend sync.WaitGroup // Tracks network request goroutines for graceful shutdown lock sync.RWMutex // Protects fields that can change outside of sync (peers, reqs, root) @@ -679,15 +682,16 @@ 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))) + s.healTimeOnce.Do(func() { + healTimeGauge.Update(int64(time.Since(s.healStartTime))) + log.Info("State healing phase is completed", "elapsed", common.PrettyDuration(time.Since(s.healStartTime))) + }) return nil } // Assign all the data retrieval tasks to any free peers @@ -697,8 +701,13 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error { if len(s.tasks) == 0 { // Sync phase done, push elapsed time to metrics - syncTimeGauge.Update(int64(time.Since(s.startTime))) - syncTime = time.Now() + s.syncTimeOnce.Do(func() { + syncTimeGauge.Update(int64(time.Since(s.startTime))) + log.Info("State sync phase is completed", "elapsed", common.PrettyDuration(time.Since(s.startTime))) + }) + if s.healStartTime.IsZero() { + s.healStartTime = time.Now() + } // run heal phase s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel) s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel)