Skip to content

Commit 42769b2

Browse files
Merge pull request #526 from mxaddict/patch-28
Added new progress ui for sync
2 parents 4ff2780 + 4e3159a commit 42769b2

17 files changed

+842
-35
lines changed

src/Makefile.qt.include

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ QT_FORMS_UI = \
9696
qt/forms/editaddressdialog.ui \
9797
qt/forms/helpmessagedialog.ui \
9898
qt/forms/intro.ui \
99+
qt/forms/modaloverlay.ui \
99100
qt/forms/openuridialog.ui \
100101
qt/forms/optionsdialog.ui \
101102
qt/forms/overviewpage.ui \
@@ -137,6 +138,7 @@ QT_MOC_CPP = \
137138
qt/moc_editaddressdialog.cpp \
138139
qt/moc_guiutil.cpp \
139140
qt/moc_intro.cpp \
141+
qt/moc_modaloverlay.cpp \
140142
qt/moc_macdockiconhandler.cpp \
141143
qt/moc_macnotificationhandler.cpp \
142144
qt/moc_navtechinit.cpp \
@@ -198,7 +200,7 @@ QT_MOC = \
198200
qt/communityfunddisplaypaymentrequestdetailed.moc \
199201
qt/communityfunddisplaydetailed.moc \
200202
qt/communityfundcreateproposaldialog.moc \
201-
qt/communityfundcreatepaymentrequestdialog.moc
203+
qt/communityfundcreatepaymentrequestdialog.moc
202204

203205
QT_QRC_CPP = qt/qrc_navcoin.cpp
204206
QT_QRC = qt/navcoin.qrc
@@ -234,6 +236,7 @@ NAVCOIN_QT_H = \
234236
qt/navtechitem.h \
235237
qt/navtechsetup.h \
236238
qt/getaddresstoreceive.h \
239+
qt/modaloverlay.h \
237240
qt/networkstyle.h \
238241
qt/notificator.h \
239242
qt/openuridialog.h \
@@ -401,6 +404,7 @@ NAVCOIN_QT_CPP += \
401404
qt/coincontroltreewidget.cpp \
402405
qt/coldstakingwizard.cpp \
403406
qt/editaddressdialog.cpp \
407+
qt/modaloverlay.cpp \
404408
qt/openuridialog.cpp \
405409
qt/overviewpage.cpp \
406410
qt/communityfundpage.cpp \
@@ -432,7 +436,7 @@ NAVCOIN_QT_CPP += \
432436
qt/walletview.cpp
433437
endif # ENABLE_WALLET
434438

435-
RES_IMAGES =
439+
RES_IMAGES =
436440

437441
RES_MOVIES = $(wildcard qt/res/movies/spinner-*.png)
438442

src/main.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,21 +4033,17 @@ static void NotifyHeaderTip() {
40334033
bool fNotify = false;
40344034
bool fInitialBlockDownload = false;
40354035
static CBlockIndex* pindexHeaderOld = NULL;
4036-
CBlockIndex* pindexHeader = NULL;
40374036
{
40384037
LOCK(cs_main);
4039-
if (!setBlockIndexCandidates.empty()) {
4040-
pindexHeader = *setBlockIndexCandidates.rbegin();
4041-
}
4042-
if (pindexHeader != pindexHeaderOld) {
4038+
if (pindexBestHeader != pindexHeaderOld) {
40434039
fNotify = true;
40444040
fInitialBlockDownload = IsInitialBlockDownload();
4045-
pindexHeaderOld = pindexHeader;
4041+
pindexHeaderOld = pindexBestHeader;
40464042
}
40474043
}
40484044
// Send block tip changed notifications without cs_main
40494045
if (fNotify) {
4050-
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
4046+
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexBestHeader);
40514047
}
40524048
}
40534049

@@ -4216,8 +4212,6 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex) {
42164212

42174213
CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
42184214
{
4219-
4220-
42214215
// Check for duplicate
42224216
uint256 hash = block.GetHash();
42234217
BlockMap::iterator it = mapBlockIndex.find(hash);
@@ -5963,7 +5957,7 @@ std::string GetWarnings(const std::string& strFor, bool fForStaking)
59635957
strGUI = _(strRPC.c_str());
59645958
}
59655959

5966-
if (!pwalletMain->GetStakeWeight())
5960+
if (!pwalletMain->GetStakeWeight())
59675961
{
59685962
strStatusBar = strRPC = "Warning: We don't appear to have mature coins.";
59695963
strGUI = _(strRPC.c_str());

src/qt/clientmodel.cpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
3434
banTableModel(0),
3535
pollTimer(0)
3636
{
37+
cachedBestHeaderHeight = -1;
38+
cachedBestHeaderTime = -1;
3739
peerTableModel = new PeerTableModel(this);
3840
banTableModel = new BanTableModel(this);
3941
pollTimer = new QTimer(this);
@@ -62,6 +64,45 @@ int ClientModel::getNumConnections(unsigned int flags) const
6264
return nNum;
6365
}
6466

67+
int ClientModel::getHeaderTipHeight() const
68+
{
69+
if (cachedBestHeaderHeight == -1) {
70+
// make sure we initially populate the cache via a cs_main lock
71+
// otherwise we need to wait for a tip update
72+
int height;
73+
int64_t blockTime;
74+
if (getHeaderTip(height, blockTime)) {
75+
cachedBestHeaderHeight = height;
76+
cachedBestHeaderTime = blockTime;
77+
}
78+
}
79+
return cachedBestHeaderHeight;
80+
}
81+
82+
int64_t ClientModel::getHeaderTipTime() const
83+
{
84+
if (cachedBestHeaderTime == -1) {
85+
int height;
86+
int64_t blockTime;
87+
if (getHeaderTip(height, blockTime)) {
88+
cachedBestHeaderHeight = height;
89+
cachedBestHeaderTime = blockTime;
90+
}
91+
}
92+
return cachedBestHeaderTime;
93+
}
94+
95+
bool ClientModel::getHeaderTip(int& height, int64_t& block_time) const
96+
{
97+
LOCK(cs_main);
98+
if (pindexBestHeader) {
99+
height = pindexBestHeader->nHeight;
100+
block_time = pindexBestHeader->GetBlockTime();
101+
return true;
102+
}
103+
return false;
104+
}
105+
65106
int ClientModel::getNumBlocks() const
66107
{
67108
LOCK(cs_main);
@@ -240,6 +281,7 @@ static void BannedListChanged(ClientModel *clientmodel)
240281
QMetaObject::invokeMethod(clientmodel, "updateBanlist", Qt::QueuedConnection);
241282
}
242283

284+
/* static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, int height, int64_t blockTime, double verificationProgress, bool fHeader) */
243285
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex, bool fHeader)
244286
{
245287
// lock free async UI updates in case we have a new block tip
@@ -251,12 +293,20 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
251293

252294
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
253295

254-
// if we are in-sync, update the UI regardless of last update time
255-
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
256-
//pass a async signal to the UI thread
296+
int height = pIndex->nHeight;
297+
int64_t blockTime = pIndex->GetBlockTime();
298+
299+
if (fHeader) {
300+
// cache best headers time and height to reduce future cs_main locks
301+
clientmodel->cachedBestHeaderHeight = height;
302+
clientmodel->cachedBestHeaderTime = blockTime;
303+
}
304+
// if we are in-sync or if we notify a header update, update the UI regardless of last update time
305+
if (fHeader || !initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
306+
//pass an async signal to the UI thread
257307
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
258-
Q_ARG(int, pIndex->nHeight),
259-
Q_ARG(QDateTime, QDateTime::fromTime_t(pIndex->GetBlockTime())),
308+
Q_ARG(int, height),
309+
Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)),
260310
Q_ARG(double, clientmodel->getVerificationProgress(pIndex)),
261311
Q_ARG(bool, fHeader));
262312
nLastUpdateNotification = now;

src/qt/clientmodel.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <QObject>
99
#include <QDateTime>
1010

11+
#include <atomic>
12+
1113
class AddressTableModel;
1214
class BanTableModel;
1315
class OptionsModel;
@@ -51,12 +53,15 @@ class ClientModel : public QObject
5153
//! Return number of connections, default is in- and outbound (total)
5254
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
5355
int getNumBlocks() const;
56+
bool getHeaderTip(int& height, int64_t& block_time) const;
57+
int getHeaderTipHeight() const;
58+
int64_t getHeaderTipTime() const;
5459

5560
//! Return number of transactions in the mempool
5661
long getMempoolSize() const;
5762
//! Return the dynamic memory usage of the mempool
5863
size_t getMempoolDynamicUsage() const;
59-
64+
6065
quint64 getTotalBytesRecv() const;
6166
quint64 getTotalBytesSent() const;
6267

@@ -78,6 +83,10 @@ class ClientModel : public QObject
7883
QString formatClientStartupTime() const;
7984
QString dataDir() const;
8085

86+
// caches for the best header
87+
mutable std::atomic<int> cachedBestHeaderHeight;
88+
mutable std::atomic<int64_t> cachedBestHeaderTime;
89+
8190
private:
8291
OptionsModel *optionsModel;
8392
PeerTableModel *peerTableModel;

0 commit comments

Comments
 (0)