Skip to content

Commit

Permalink
refactor: Remove Node::getReindex() call from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 18, 2020
1 parent 1dab574 commit 3c709aa
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/qt/clientmodel.cpp
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 3c709aa

Please sign in to comment.