Skip to content

Commit

Permalink
Fix percent remaining, guard against div by 0
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Dec 4, 2024
1 parent 3bc005e commit 7fb96c9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/sidecar/blockIndexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error {
runningAvg := float64(0)
totalDurationMs := int64(0)

originalStartBlock := latestBlock

//nolint:all
lastBlockParsed := latestBlock

Expand All @@ -208,7 +210,13 @@ func (s *Sidecar) IndexFromCurrentToTip(ctx context.Context) error {
}
tip := currentTip.Load()
blocksRemaining := tip - uint64(latestBlock)
pctComplete := (float64(blocksProcessed) / float64(blocksRemaining)) * 100
totalBlocksToProcess := tip - uint64(originalStartBlock)

var pctComplete float64
if totalBlocksToProcess != 0 {
pctComplete = (float64(blocksProcessed) / float64(totalBlocksToProcess)) * 100
}

estTimeRemainingMs := runningAvg * float64(blocksRemaining)
estTimeRemainingHours := float64(estTimeRemainingMs) / 1000 / 60 / 60

Expand Down

0 comments on commit 7fb96c9

Please sign in to comment.