From 4b7ae93b70876a45ccbbcc1fd24f6f40489dceaa Mon Sep 17 00:00:00 2001 From: Dmytro Vovk Date: Mon, 17 Mar 2025 08:01:59 +0400 Subject: [PATCH] diagnostics: fix dividing by 0 (#14168) --- erigon-lib/diagnostics/snapshots_indexing.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/erigon-lib/diagnostics/snapshots_indexing.go b/erigon-lib/diagnostics/snapshots_indexing.go index 4ed032fd380..09218b2f4fe 100644 --- a/erigon-lib/diagnostics/snapshots_indexing.go +++ b/erigon-lib/diagnostics/snapshots_indexing.go @@ -87,12 +87,23 @@ func (d *DiagnosticClient) UpdateIndexingStatus() (indexingFinished bool) { } func (d *DiagnosticClient) updateIndexingStatus() (indexingFinished bool) { + segments := d.syncStats.SnapshotIndexing.Segments + if len(segments) == 0 { + // If there are no segments, update progress as 0% and return false. + d.updateSnapshotStageStats(SyncStageStats{ + TimeElapsed: SecondsToHHMMString(uint64(d.syncStats.SnapshotIndexing.TimeElapsed)), + TimeLeft: "unknown", + Progress: "0%", + }, "Indexing snapshots") + return false + } + totalProgressPercent := 0 - for _, seg := range d.syncStats.SnapshotIndexing.Segments { + for _, seg := range segments { totalProgressPercent += seg.Percent } - totalProgress := totalProgressPercent / len(d.syncStats.SnapshotIndexing.Segments) + totalProgress := totalProgressPercent / len(segments) d.updateSnapshotStageStats(SyncStageStats{ TimeElapsed: SecondsToHHMMString(uint64(d.syncStats.SnapshotIndexing.TimeElapsed)),