Skip to content

Commit

Permalink
add correct progress where genesis block isn't 0 (#246)
Browse files Browse the repository at this point in the history
* add correct progress where genesis block isn't 0

* lint

* feedback
  • Loading branch information
shrimalmadhur authored Nov 9, 2021
1 parent 65879a3 commit d736900
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/results/data_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ func ComputeCheckDataProgress(
}
tipIndex := networkStatus.CurrentBlockIdentifier.Index

genesisBlockIndex := int64(0)
if networkStatus.GenesisBlockIdentifier != nil {
genesisBlockIndex = networkStatus.GenesisBlockIdentifier.Index
}

// Get current tip in the case that re-orgs occurred
// or a custom start index was provied.
headBlock, err := blockStorage.GetHeadBlockIdentifier(ctx)
Expand Down Expand Up @@ -357,11 +362,14 @@ func ComputeCheckDataProgress(
new(big.Float).SetInt(elapsedTime),
)
blocksPerSecondFloat, _ := blocksPerSecond.Float64()

// some blockchains don't start their genesis block from 0 height
// So take the height of genesis block and calculate sync percentage based on that
blocksSynced := new(
big.Float,
).Quo(
new(big.Float).SetInt64(headBlock.Index),
new(big.Float).SetInt64(tipIndex),
new(big.Float).SetInt64(headBlock.Index - genesisBlockIndex),
new(big.Float).SetInt64(tipIndex - genesisBlockIndex),
)
blocksSyncedFloat, _ := blocksSynced.Float64()

Expand Down

0 comments on commit d736900

Please sign in to comment.