quint64 walletHeight = m_wallet->blockChainHeight();
quint64 daemonHeight = m_wallet->daemonBlockChainHeight();
- quint64 blocksBehind = daemonHeigh - walletHeight;
-
- // Use time-estimation if we don't have a live connection
- if (isPaused || m_wallet->connectionStatus() == Wallet::ConnectionStatus_Disconnected) {
- QDateTime lastSync = m_wallet->lastSyncTime();
- if (lastSync.isValid()) {
- qint64 secs = lastSync.secsTo(QDateTime::currentDateTime());
- if (secs > 0) blocksBehind = secs / 120; // 120s per block
- }
- }
+ quint64 blocksBehind = (daemonHeight > walletHeight) ? (daemonHeight - walletHeight) : 0;
// Build tooltip
QString tooltip = tr("Daemon Height: %1").arg(QLocale().toString(daemonHeight));
const auto elapsed = now - last;
if (elapsed >= std::chrono::seconds(m_refreshInterval) || m_refreshNow)
{
- // Scan mempool if paused and user has enabled it (low-bandwidth query)
if (m_syncPaused) {
- if (m_refreshNow || conf()->get(Config::scanMempoolWhenPaused).toBool()) {
+ bool shouldScanMempool = m_refreshNow || conf()->get(Config::scanMempoolWhenPaused).toBool();
+
+ if (shouldScanMempool) {
qDebug() << "[SYNC PAUSED] Scanning mempool because scans are enabled";
- if (m_scheduler.stopping()) return; // TODO: do we need this?
+ if (m_scheduler.stopping()) return;
scanMempool();
+ }
- // Update network stats
+ // Update network stats if we just scanned OR if we don't have stats yet (startup recovery)
+ if (shouldScanMempool || m_daemonBlockChainHeight == 0) {
quint64 daemonHeight = m_walletImpl->daemonBlockChainHeight();
quint64 targetHeight = (daemonHeight > 0) ? m_walletImpl->daemonBlockChainTargetHeight() : 0;
emit heightsRefreshed(daemonHeight > 0, daemonHeight, targetHeight);
-
- m_refreshNow = false;
}
+
+ m_refreshNow = false;
last = std::chrono::steady_clock::now();
continue;
}