diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-03-04 21:35:08 +0200 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-05-19 02:49:48 +0300 |
commit | 3c709aa69d5bb5a1564c339a0e6a16bac8f02c98 (patch) | |
tree | 4aa5441621e2dfba81f1486a15233133df676643 /src/qt | |
parent | 1dab574edf57ccd6cdf5ec706ac328c62142d7a2 (diff) |
refactor: Remove Node::getReindex() call from GUI
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/clientmodel.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index abda980384..a6bf5e10aa 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -237,17 +237,6 @@ static void BannedListChanged(ClientModel *clientmodel) static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_state, int height, int64_t blockTime, double verificationProgress, bool fHeader) { - const bool initialSync = sync_state != SynchronizationState::POST_INIT; - - // lock free async UI updates in case we have a new block tip - // during initial sync, only update the UI if the last update - // was > 250ms (MODEL_UPDATE_DELAY) ago - int64_t now = 0; - if (initialSync) - now = GetTimeMillis(); - - int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; - if (fHeader) { // cache best headers time and height to reduce future cs_main locks clientmodel->cachedBestHeaderHeight = height; @@ -256,17 +245,21 @@ static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_ clientmodel->m_cached_num_blocks = height; } - // During initial sync, block notifications, and header notifications from reindexing are both throttled. - if (!initialSync || (fHeader && !clientmodel->node().getReindex()) || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) { - //pass an async signal to the UI thread - bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, - Q_ARG(int, height), - Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)), - Q_ARG(double, verificationProgress), - Q_ARG(bool, fHeader)); - assert(invoked); - nLastUpdateNotification = now; + // Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex. + const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX; + const int64_t now = throttle ? GetTimeMillis() : 0; + int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; + if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) { + return; } + + bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, + Q_ARG(int, height), + Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)), + Q_ARG(double, verificationProgress), + Q_ARG(bool, fHeader)); + assert(invoked); + nLastUpdateNotification = now; } void ClientModel::subscribeToCoreSignals() |