Skip to content

Commit

Permalink
Merge #11237: qt: Fixing division by zero in time remaining
Browse files Browse the repository at this point in the history
Summary:
c8d38ab Refactor tipUpdate as per style guide (MeshCollider)
3b69a08 Fix division by zero in time remaining (MeshCollider)

Pull request description:

  Fixes bitcoin/bitcoin#10291, bitcoin/bitcoin#11265

  progressDelta may be 0 (or even negative according to 11265), this checks for that and prints unknown if it is, because we cannot calculate an estimate for the time remaining (would be infinite or negative).

Tree-SHA512: bc5708e5ed6e4670d008219558c5fbb25709bd99a32c98ec39bb74f94a0b7fa058f3d03389ccdd39e6723e6b5b48e34b13ceee7c051c2db631e51d8ec3e1d68c

Backport of Core PR11237

https://github.com/bitcoin/bitcoin/pull/11237/files

Test Plan: `make check`

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D3376
  • Loading branch information
jasonbcox authored and jtoomim committed Jun 29, 2019
1 parent fc51db3 commit 4e154e1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/qt/modaloverlay.cpp
Expand Up @@ -73,7 +73,6 @@ void ModalOverlay::tipUpdate(int count, const QDateTime &blockDate,

// show progress speed if we have more then one sample
if (blockProcessTime.size() >= 2) {
double progressStart = blockProcessTime[0].second;
double progressDelta = 0;
double progressPerHour = 0;
qint64 timeDelta = 0;
Expand All @@ -85,11 +84,14 @@ void ModalOverlay::tipUpdate(int count, const QDateTime &blockDate,
// take first sample after 500 seconds or last available one
if (sample.first < (currentDate.toMSecsSinceEpoch() - 500 * 1000) ||
i == blockProcessTime.size() - 1) {
progressDelta = progressStart - sample.second;
progressDelta = blockProcessTime[0].second - sample.second;
timeDelta = blockProcessTime[0].first - sample.first;
progressPerHour =
progressDelta / (double)timeDelta * 1000 * 3600;
remainingMSecs = remainingProgress / progressDelta * timeDelta;
remainingMSecs =
(progressDelta > 0)
? remainingProgress / progressDelta * timeDelta
: -1;
break;
}
}
Expand All @@ -98,13 +100,18 @@ void ModalOverlay::tipUpdate(int count, const QDateTime &blockDate,
QString::number(progressPerHour * 100, 'f', 2) + "%");

// show expected remaining time
ui->expectedTimeLeft->setText(
GUIUtil::formatNiceTimeOffset(remainingMSecs / 1000.0));
if (remainingMSecs >= 0) {
ui->expectedTimeLeft->setText(
GUIUtil::formatNiceTimeOffset(remainingMSecs / 1000.0));
} else {
ui->expectedTimeLeft->setText(QObject::tr("unknown"));
}

static const int MAX_SAMPLES = 5000;
if (blockProcessTime.count() > MAX_SAMPLES)
if (blockProcessTime.count() > MAX_SAMPLES) {
blockProcessTime.remove(MAX_SAMPLES,
blockProcessTime.count() - MAX_SAMPLES);
}
}

// show the last block date
Expand Down

0 comments on commit 4e154e1

Please sign in to comment.