[qt] sync-overlay: Don't block during reindex

This commit is contained in:
MarcoFalke 2016-09-26 18:58:51 +02:00
parent 2f71490d21
commit faa4de2a2a
3 changed files with 22 additions and 14 deletions

View file

@ -256,7 +256,7 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
// if we are in-sync, update the UI regardless of last update time // if we are in-sync, update the UI regardless of last update time
if (fHeader || !initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) { if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
//pass a async signal to the UI thread //pass a async signal to the UI thread
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
Q_ARG(int, pIndex->nHeight), Q_ARG(int, pIndex->nHeight),

View file

@ -13,7 +13,8 @@
ModalOverlay::ModalOverlay(QWidget *parent) : ModalOverlay::ModalOverlay(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::ModalOverlay), ui(new Ui::ModalOverlay),
bestBlockHeight(0), bestHeaderHeight(0),
bestHeaderDate(QDateTime()),
layerIsVisible(false), layerIsVisible(false),
userClosed(false) userClosed(false)
{ {
@ -65,14 +66,9 @@ bool ModalOverlay::event(QEvent* ev) {
void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate) void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
{ {
if (count > bestHeaderHeight) {
/* only update the blockheight if the headerschain-tip is not older then 30 days */ bestHeaderHeight = count;
int64_t now = QDateTime::currentDateTime().toTime_t(); bestHeaderDate = blockDate;
int64_t btime = blockDate.toTime_t();
if (btime+3600*24*30 > now)
{
if (count > bestBlockHeight)
bestBlockHeight = count;
} }
} }
@ -125,11 +121,22 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri
ui->percentageProgress->setText(QString::number(nVerificationProgress*100, 'f', 2)+"%"); ui->percentageProgress->setText(QString::number(nVerificationProgress*100, 'f', 2)+"%");
ui->progressBar->setValue(nVerificationProgress*100); ui->progressBar->setValue(nVerificationProgress*100);
if (!bestHeaderDate.isValid())
// not syncing
return;
// estimate the number of headers left based on nPowTargetSpacing
// and check if the gui is not aware of the the best header (happens rarely)
int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / 600;
bool hasBestHeader = bestHeaderHeight >= count;
// show remaining number of blocks // show remaining number of blocks
if (bestBlockHeight > 0) if (estimateNumHeadersLeft < 24 && hasBestHeader) {
ui->numberOfBlocksLeft->setText(QString::number(bestBlockHeight-count)); ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count));
else } else {
ui->numberOfBlocksLeft->setText("~" + QString::number(bestHeaderHeight + estimateNumHeadersLeft - count));
ui->expectedTimeLeft->setText(tr("Unknown. Syncing Headers...")); ui->expectedTimeLeft->setText(tr("Unknown. Syncing Headers..."));
}
} }
void ModalOverlay::showHide(bool hide, bool userRequested) void ModalOverlay::showHide(bool hide, bool userRequested)

View file

@ -35,7 +35,8 @@ protected:
private: private:
Ui::ModalOverlay *ui; Ui::ModalOverlay *ui;
int bestBlockHeight; //best known height (based on the headers) int bestHeaderHeight; //best known height (based on the headers)
QDateTime bestHeaderDate;
QVector<QPair<qint64, double> > blockProcessTime; QVector<QPair<qint64, double> > blockProcessTime;
bool layerIsVisible; bool layerIsVisible;
bool userClosed; bool userClosed;