|
13 | 13 | ModalOverlay::ModalOverlay(QWidget *parent) :
|
14 | 14 | QWidget(parent),
|
15 | 15 | ui(new Ui::ModalOverlay),
|
16 |
| -bestBlockHeight(0), |
| 16 | +bestHeaderHeight(0), |
| 17 | +bestHeaderDate(QDateTime()), |
17 | 18 | layerIsVisible(false),
|
18 | 19 | userClosed(false)
|
19 | 20 | {
|
@@ -65,14 +66,9 @@ bool ModalOverlay::event(QEvent* ev) {
|
65 | 66 |
|
66 | 67 | void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
|
67 | 68 | {
|
68 |
| - |
69 |
| - /* only update the blockheight if the headerschain-tip is not older then 30 days */ |
70 |
| - int64_t now = QDateTime::currentDateTime().toTime_t(); |
71 |
| - int64_t btime = blockDate.toTime_t(); |
72 |
| - if (btime+3600*24*30 > now) |
73 |
| - { |
74 |
| - if (count > bestBlockHeight) |
75 |
| - bestBlockHeight = count; |
| 69 | + if (count > bestHeaderHeight) { |
| 70 | + bestHeaderHeight = count; |
| 71 | + bestHeaderDate = blockDate; |
76 | 72 | }
|
77 | 73 | }
|
78 | 74 |
|
@@ -125,11 +121,21 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri
|
125 | 121 | ui->percentageProgress->setText(QString::number(nVerificationProgress*100, 'f', 2)+"%");
|
126 | 122 | ui->progressBar->setValue(nVerificationProgress*100);
|
127 | 123 |
|
| 124 | + if (!bestHeaderDate.isValid()) |
| 125 | + // not syncing |
| 126 | + return; |
| 127 | + |
| 128 | + // estimate the number of headers left based on nPowTargetSpacing |
| 129 | + // and check if the gui is not aware of the the best header (happens rarely) |
| 130 | + int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / 600; |
| 131 | + bool hasBestHeader = bestHeaderHeight >= count; |
| 132 | + |
128 | 133 | // show remaining number of blocks
|
129 |
| - if (bestBlockHeight > 0) |
130 |
| - ui->numberOfBlocksLeft->setText(QString::number(bestBlockHeight-count)); |
131 |
| - else |
| 134 | + if (estimateNumHeadersLeft < 24 && hasBestHeader) { |
| 135 | + ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count)); |
| 136 | + } else { |
132 | 137 | ui->expectedTimeLeft->setText(tr("Unknown. Syncing Headers..."));
|
| 138 | + } |
133 | 139 | }
|
134 | 140 |
|
135 | 141 | void ModalOverlay::showHide(bool hide, bool userRequested)
|
|
0 commit comments