Skip to content

Commit d8b062e

Browse files
committed
[Qt] only update "amount of blocks left" when the header chain is in-sync
1 parent e3245b4 commit d8b062e

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

src/qt/bitcoingui.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
500500
setTrayIconVisible(optionsModel->getHideTrayIcon());
501501
}
502502

503-
modalOverlay->setKnownBestHeight(clientModel->getHeaderHeight());
503+
modalOverlay->setKnownBestHeight(clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(clientModel->getHeaderTipTime()));
504504
} else {
505505
// Disable possibility to show main window via action
506506
toggleHideAction->setEnabled(false);
@@ -718,7 +718,10 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
718718
if (modalOverlay)
719719
{
720720
if (header)
721-
modalOverlay->setKnownBestHeight(count);
721+
{
722+
/* use clientmodels getHeaderTipHeight and getHeaderTipTime because the NotifyHeaderTip signal does not fire when updating the best header */
723+
modalOverlay->setKnownBestHeight(clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(clientModel->getHeaderTipTime()));
724+
}
722725
else
723726
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
724727
}

src/qt/clientmodel.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,22 @@ int ClientModel::getNumBlocks() const
6868
return chainActive.Height();
6969
}
7070

71-
int ClientModel::getHeaderHeight() const
71+
int ClientModel::getHeaderTipHeight() const
7272
{
7373
LOCK(cs_main);
7474
if (!pindexBestHeader)
7575
return 0;
7676
return pindexBestHeader->nHeight;
7777
}
7878

79+
int64_t ClientModel::getHeaderTipTime() const
80+
{
81+
LOCK(cs_main);
82+
if (!pindexBestHeader)
83+
return 0;
84+
return pindexBestHeader->GetBlockTime();
85+
}
86+
7987
quint64 ClientModel::getTotalBytesRecv() const
8088
{
8189
return CNode::GetTotalBytesRecv();

src/qt/clientmodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class ClientModel : public QObject
5151
//! Return number of connections, default is in- and outbound (total)
5252
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
5353
int getNumBlocks() const;
54-
int getHeaderHeight() const;
55-
54+
int getHeaderTipHeight() const;
55+
int64_t getHeaderTipTime() const;
5656
//! Return number of transactions in the mempool
5757
long getMempoolSize() const;
5858
//! Return the dynamic memory usage of the mempool

src/qt/forms/modaloverlay.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ QLabel { color: rgb(40,40,40); }</string>
8282
</property>
8383
<item>
8484
<widget class="QPushButton" name="warningIcon">
85+
<property name="enabled">
86+
<bool>false</bool>
87+
</property>
8588
<property name="text">
8689
<string/>
8790
</property>

src/qt/modaloverlay.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ bool ModalOverlay::event(QEvent* ev) {
6363
return QWidget::event(ev);
6464
}
6565

66-
void ModalOverlay::setKnownBestHeight(int count)
66+
void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
6767
{
68-
if (count > bestBlockHeight)
69-
bestBlockHeight = count;
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;
76+
}
7077
}
7178

7279
void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress)
@@ -122,6 +129,8 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri
122129
// show remaining amount of blocks
123130
if (bestBlockHeight > 0)
124131
ui->amountOfBlocksLeft->setText(QString::number(bestBlockHeight-count));
132+
else
133+
ui->expectedTimeLeft->setText(tr("Unknown. Syncing Headers..."));
125134
}
126135

127136
void ModalOverlay::showHide(bool hide, bool userRequested)

src/qt/modaloverlay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ModalOverlay : public QWidget
2323

2424
public Q_SLOTS:
2525
void tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress);
26-
void setKnownBestHeight(int count);
26+
void setKnownBestHeight(int count, const QDateTime& blockDate);
2727

2828
// will show or hide the modal layer
2929
void showHide(bool hide = false, bool userRequested = false);

0 commit comments

Comments
 (0)