Skip to content

Commit 3c709aa

Browse files
committed
refactor: Remove Node::getReindex() call from GUI
1 parent 1dab574 commit 3c709aa

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/qt/clientmodel.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,6 @@ static void BannedListChanged(ClientModel *clientmodel)
237237

238238
static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_state, int height, int64_t blockTime, double verificationProgress, bool fHeader)
239239
{
240-
const bool initialSync = sync_state != SynchronizationState::POST_INIT;
241-
242-
// lock free async UI updates in case we have a new block tip
243-
// during initial sync, only update the UI if the last update
244-
// was > 250ms (MODEL_UPDATE_DELAY) ago
245-
int64_t now = 0;
246-
if (initialSync)
247-
now = GetTimeMillis();
248-
249-
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
250-
251240
if (fHeader) {
252241
// cache best headers time and height to reduce future cs_main locks
253242
clientmodel->cachedBestHeaderHeight = height;
@@ -256,17 +245,21 @@ static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_
256245
clientmodel->m_cached_num_blocks = height;
257246
}
258247

259-
// During initial sync, block notifications, and header notifications from reindexing are both throttled.
260-
if (!initialSync || (fHeader && !clientmodel->node().getReindex()) || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
261-
//pass an async signal to the UI thread
262-
bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
263-
Q_ARG(int, height),
264-
Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)),
265-
Q_ARG(double, verificationProgress),
266-
Q_ARG(bool, fHeader));
267-
assert(invoked);
268-
nLastUpdateNotification = now;
248+
// Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex.
249+
const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX;
250+
const int64_t now = throttle ? GetTimeMillis() : 0;
251+
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
252+
if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) {
253+
return;
269254
}
255+
256+
bool invoked = QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
257+
Q_ARG(int, height),
258+
Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)),
259+
Q_ARG(double, verificationProgress),
260+
Q_ARG(bool, fHeader));
261+
assert(invoked);
262+
nLastUpdateNotification = now;
270263
}
271264

272265
void ClientModel::subscribeToCoreSignals()

0 commit comments

Comments
 (0)