From b18da766aa34151243c1c20d22018f1d764743d3 Mon Sep 17 00:00:00 2001 From: gg Date: Sun, 18 Jan 2026 17:12:50 -0500 Subject: [PATCH] better blocks behind and mempool scan logic --- src/MainWindow.cpp | 11 +---------- src/libwalletqt/Wallet.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6db6671d..148fb21c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -888,16 +888,7 @@ void MainWindow::updateSyncStatusToolTip() { 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)); diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index f15b8dcb..79d9ee01 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -522,20 +522,23 @@ void Wallet::startRefreshThread() 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; } -- 2.52.0