mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-23 22:15:54 +00:00
Make sure there are no negative numbers in the report
This commit is contained in:
parent
7ffe83e4f1
commit
38b211e260
@ -10,6 +10,10 @@ type ibdProgressReporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newIBDProgressReporter(lowDAAScore uint64, highDAAScore uint64, objectName string) *ibdProgressReporter {
|
func newIBDProgressReporter(lowDAAScore uint64, highDAAScore uint64, objectName string) *ibdProgressReporter {
|
||||||
|
if highDAAScore <= lowDAAScore {
|
||||||
|
// Avoid a zero or negative diff
|
||||||
|
highDAAScore = lowDAAScore + 1
|
||||||
|
}
|
||||||
return &ibdProgressReporter{
|
return &ibdProgressReporter{
|
||||||
lowDAAScore: lowDAAScore,
|
lowDAAScore: lowDAAScore,
|
||||||
highDAAScore: highDAAScore,
|
highDAAScore: highDAAScore,
|
||||||
@ -22,13 +26,17 @@ func newIBDProgressReporter(lowDAAScore uint64, highDAAScore uint64, objectName
|
|||||||
|
|
||||||
func (ipr *ibdProgressReporter) reportProgress(processedDelta int, highestProcessedDAAScore uint64) {
|
func (ipr *ibdProgressReporter) reportProgress(processedDelta int, highestProcessedDAAScore uint64) {
|
||||||
ipr.processed += processedDelta
|
ipr.processed += processedDelta
|
||||||
|
|
||||||
// Avoid exploding numbers in the percentage report, since the original `highDAAScore` might have been only a hint
|
// Avoid exploding numbers in the percentage report, since the original `highDAAScore` might have been only a hint
|
||||||
if highestProcessedDAAScore > ipr.highDAAScore {
|
if highestProcessedDAAScore > ipr.highDAAScore {
|
||||||
ipr.highDAAScore = highestProcessedDAAScore + 1 // + 1 for keeping it at 99%
|
ipr.highDAAScore = highestProcessedDAAScore + 1 // + 1 for keeping it at 99%
|
||||||
ipr.totalDAAScoreDifference = ipr.highDAAScore - ipr.lowDAAScore
|
ipr.totalDAAScoreDifference = ipr.highDAAScore - ipr.lowDAAScore
|
||||||
}
|
}
|
||||||
relativeDAAScore := highestProcessedDAAScore - ipr.lowDAAScore
|
relativeDAAScore := uint64(0)
|
||||||
|
if highestProcessedDAAScore > ipr.lowDAAScore {
|
||||||
|
// Avoid a negative diff
|
||||||
|
relativeDAAScore = highestProcessedDAAScore - ipr.lowDAAScore
|
||||||
|
}
|
||||||
progressPercent := int((float64(relativeDAAScore) / float64(ipr.totalDAAScoreDifference)) * 100)
|
progressPercent := int((float64(relativeDAAScore) / float64(ipr.totalDAAScoreDifference)) * 100)
|
||||||
if progressPercent > ipr.lastReportedProgressPercent {
|
if progressPercent > ipr.lastReportedProgressPercent {
|
||||||
log.Infof("IBD: Processed %d %s (%d%%)", ipr.processed, ipr.objectName, progressPercent)
|
log.Infof("IBD: Processed %d %s (%d%%)", ipr.processed, ipr.objectName, progressPercent)
|
||||||
|
|||||||
@ -10,6 +10,10 @@ type ibdProgressReporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newIBDProgressReporter(lowDAAScore uint64, highDAAScore uint64, objectName string) *ibdProgressReporter {
|
func newIBDProgressReporter(lowDAAScore uint64, highDAAScore uint64, objectName string) *ibdProgressReporter {
|
||||||
|
if highDAAScore <= lowDAAScore {
|
||||||
|
// Avoid a zero or negative diff
|
||||||
|
highDAAScore = lowDAAScore + 1
|
||||||
|
}
|
||||||
return &ibdProgressReporter{
|
return &ibdProgressReporter{
|
||||||
lowDAAScore: lowDAAScore,
|
lowDAAScore: lowDAAScore,
|
||||||
highDAAScore: highDAAScore,
|
highDAAScore: highDAAScore,
|
||||||
@ -28,7 +32,11 @@ func (ipr *ibdProgressReporter) reportProgress(processedDelta int, highestProces
|
|||||||
ipr.highDAAScore = highestProcessedDAAScore + 1 // + 1 for keeping it at 99%
|
ipr.highDAAScore = highestProcessedDAAScore + 1 // + 1 for keeping it at 99%
|
||||||
ipr.totalDAAScoreDifference = ipr.highDAAScore - ipr.lowDAAScore
|
ipr.totalDAAScoreDifference = ipr.highDAAScore - ipr.lowDAAScore
|
||||||
}
|
}
|
||||||
relativeDAAScore := highestProcessedDAAScore - ipr.lowDAAScore
|
relativeDAAScore := uint64(0)
|
||||||
|
if highestProcessedDAAScore > ipr.lowDAAScore {
|
||||||
|
// Avoid a negative diff
|
||||||
|
relativeDAAScore = highestProcessedDAAScore - ipr.lowDAAScore
|
||||||
|
}
|
||||||
progressPercent := int((float64(relativeDAAScore) / float64(ipr.totalDAAScoreDifference)) * 100)
|
progressPercent := int((float64(relativeDAAScore) / float64(ipr.totalDAAScoreDifference)) * 100)
|
||||||
if progressPercent > ipr.lastReportedProgressPercent {
|
if progressPercent > ipr.lastReportedProgressPercent {
|
||||||
log.Infof("IBD: Processed %d %s (%d%%)", ipr.processed, ipr.objectName, progressPercent)
|
log.Infof("IBD: Processed %d %s (%d%%)", ipr.processed, ipr.objectName, progressPercent)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user