MCPcopy Create free account
hub / github.com/LUX-Core/lux / BlockTipChanged

Function BlockTipChanged

src/qt/clientmodel.cpp:345–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex, bool fHeader)
346{
347 // Wallet mode checks
348 if(pIndex) {
349 int64_t secs = GetTime() - pIndex->GetBlockTime();
350 bool walletMode = secs >= 90*60 ? true : false;
351 if(walletMode) {
352 initialSync |= walletMode;
353 if(!fWalletProcessingMode) {
354 fWalletProcessingMode = true;
355 }
356 }
357 }
358
359 // lock free async UI updates in case we have a new block tip
360 // during initial sync, only update the UI if the last update
361 // was > 250ms (MODEL_UPDATE_DELAY) ago
362 int64_t now = 0;
363 if (initialSync)
364 now = GetTimeMillis();
365
366 int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
367
368 if (fHeader || (pIndex->nHeight % 100) == 0) {
369 // cache best headers time and height to reduce future cs_main locks
370 clientmodel->cachedBestHeaderHeight = pIndex->nHeight;
371 clientmodel->cachedBestHeaderTime = pIndex->GetBlockTime();
372
373 // refresh headers, the only height shown on modal overlay (fHeader seems never true on modaloverlay)
374 QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
375 Q_ARG(int, pIndex->nHeight),
376 Q_ARG(QDateTime, QDateTime::fromTime_t(pIndex->GetBlockTime())),
377 Q_ARG(double, clientmodel->getVerificationProgress(pIndex)),
378 Q_ARG(bool, true));
379 }
380
381 // if we are in-sync, update the UI regardless of last update time
382 if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
383 //pass a async signal to the UI thread
384 QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
385 Q_ARG(int, pIndex->nHeight),
386 Q_ARG(QDateTime, QDateTime::fromTime_t(pIndex->GetBlockTime())),
387 Q_ARG(double, clientmodel->getVerificationProgress(pIndex)),
388 Q_ARG(bool, fHeader));
389 if(!fHeader && !fWalletProcessingMode) {
390 QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection, Q_ARG(int, pIndex->nHeight));
391 }
392 nLastUpdateNotification = now;
393 }
394}
395
396static void NotifyAdditionalDataSyncProgressChanged(ClientModel *clientmodel, double nSyncProgress)
397{

Callers

nothing calls this directly

Calls 4

GetTimeFunction · 0.85
GetTimeMillisFunction · 0.85
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected