MCPcopy Create free account
hub / github.com/ElementsProject/elements / tipUpdate

Method tipUpdate

src/qt/modaloverlay.cpp:90–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress)
91{
92 QDateTime currentDate = QDateTime::currentDateTime();
93
94 // keep a vector of samples of verification progress at height
95 blockProcessTime.push_front(qMakePair(currentDate.toMSecsSinceEpoch(), nVerificationProgress));
96
97 // show progress speed if we have more than one sample
98 if (blockProcessTime.size() >= 2) {
99 double progressDelta = 0;
100 double progressPerHour = 0;
101 qint64 timeDelta = 0;
102 qint64 remainingMSecs = 0;
103 double remainingProgress = 1.0 - nVerificationProgress;
104 for (int i = 1; i < blockProcessTime.size(); i++) {
105 QPair<qint64, double> sample = blockProcessTime[i];
106
107 // take first sample after 500 seconds or last available one
108 if (sample.first < (currentDate.toMSecsSinceEpoch() - 500 * 1000) || i == blockProcessTime.size() - 1) {
109 progressDelta = blockProcessTime[0].second - sample.second;
110 timeDelta = blockProcessTime[0].first - sample.first;
111 progressPerHour = (progressDelta > 0) ? progressDelta / (double)timeDelta * 1000 * 3600 : 0;
112 remainingMSecs = (progressDelta > 0) ? remainingProgress / progressDelta * timeDelta : -1;
113 break;
114 }
115 }
116 // show progress increase per hour
117 ui->progressIncreasePerH->setText(QString::number(progressPerHour * 100, 'f', 2)+"%");
118
119 // show expected remaining time
120 if(remainingMSecs >= 0) {
121 ui->expectedTimeLeft->setText(GUIUtil::formatNiceTimeOffset(remainingMSecs / 1000.0));
122 } else {
123 ui->expectedTimeLeft->setText(QObject::tr("unknown"));
124 }
125
126 static const int MAX_SAMPLES = 5000;
127 if (blockProcessTime.count() > MAX_SAMPLES) {
128 blockProcessTime.remove(MAX_SAMPLES, blockProcessTime.count() - MAX_SAMPLES);
129 }
130 }
131
132 // show the last block date
133 ui->newestBlockDate->setText(blockDate.toString());
134
135 // show the percentage done according to nVerificationProgress
136 ui->percentageProgress->setText(QString::number(nVerificationProgress*100, 'f', 2)+"%");
137
138 if (!bestHeaderDate.isValid())
139 // not syncing
140 return;
141
142 // estimate the number of headers left based on nPowTargetSpacing
143 // and check if the gui is not aware of the best header (happens rarely)
144 int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / Params().GetConsensus().nPowTargetSpacing;
145 bool hasBestHeader = bestHeaderHeight >= count;
146
147 // show remaining number of blocks

Callers 1

setNumBlocksMethod · 0.80

Calls 7

formatNiceTimeOffsetFunction · 0.85
setTextMethod · 0.80
countMethod · 0.80
ParamsClass · 0.50
sizeMethod · 0.45
removeMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected