eth/protocols/snap: add logs

This commit is contained in:
Gary Rong 2025-07-22 23:25:44 +08:00
parent 0a965ba99f
commit 93481b2843

View file

@ -503,6 +503,9 @@ type Syncer struct {
storageHealedBytes common.StorageSize // Number of raw storage bytes persisted to disk 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 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 logTime time.Time // Time instance when status was last reported
pend sync.WaitGroup // Tracks network request goroutines for graceful shutdown pend sync.WaitGroup // Tracks network request goroutines for graceful shutdown
@ -679,15 +682,16 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
bytecodeHealReqFails = make(chan *bytecodeHealRequest) bytecodeHealReqFails = make(chan *bytecodeHealRequest)
trienodeHealResps = make(chan *trienodeHealResponse) trienodeHealResps = make(chan *trienodeHealResponse)
bytecodeHealResps = make(chan *bytecodeHealResponse) bytecodeHealResps = make(chan *bytecodeHealResponse)
syncTime = time.Now()
) )
for { for {
// Remove all completed tasks and terminate sync if everything's done // Remove all completed tasks and terminate sync if everything's done
s.cleanStorageTasks() s.cleanStorageTasks()
s.cleanAccountTasks() s.cleanAccountTasks()
if len(s.tasks) == 0 && s.healer.scheduler.Pending() == 0 { if len(s.tasks) == 0 && s.healer.scheduler.Pending() == 0 {
// healing done s.healTimeOnce.Do(func() {
healTimeGauge.Update(int64(time.Since(syncTime))) healTimeGauge.Update(int64(time.Since(s.healStartTime)))
log.Info("State healing phase is completed", "elapsed", common.PrettyDuration(time.Since(s.healStartTime)))
})
return nil return nil
} }
// Assign all the data retrieval tasks to any free peers // 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 { if len(s.tasks) == 0 {
// Sync phase done, push elapsed time to metrics // Sync phase done, push elapsed time to metrics
s.syncTimeOnce.Do(func() {
syncTimeGauge.Update(int64(time.Since(s.startTime))) syncTimeGauge.Update(int64(time.Since(s.startTime)))
syncTime = time.Now() 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 // run heal phase
s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel) s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel)
s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel) s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel)