libwalletqt: start wallet refresh worker lazily
What changed, and why it matters
This change moves the start of a background wallet refresh thread from object creation time to the first time refresh is actually requested. It is a performance and resource-management improvement, not a security fix. There is no indication in the commit that it addresses a vulnerability.
No security action required; treat as a normal code-quality/performance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch makes the wallet refresh worker thread lazy: instead of starting startRefreshThread() in the Wallet constructor, it now starts it inside startRefresh() only when m_refreshThreadStarted is false, using an atomic exchange to prevent double-start races. A new std::atomic<bool> m_refreshThreadStarted member tracks state. This avoids spawning a refresh thread for wallets that may never need it.
Changed components
src/libwalletqt/Wallet.cppsrc/libwalletqt/Wallet.hInspect captured patch +15 / −1
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp
index a5ac692..298db6e 100644
--- a/src/libwalletqt/Wallet.cpp
+++ b/src/libwalletqt/Wallet.cpp
@@ -620,6 +620,19 @@ void Wallet::startRefresh()
qDebug() << "Starting refresh";
m_refreshEnabled = true;
m_refreshNow = true;
+
+ if (!m_refreshThreadStarted.exchange(true))
+ {
+ try
+ {
+ startRefreshThread();
+ }
+ catch (...)
+ {
+ m_refreshThreadStarted.store(false);
+ throw;
+ }
+ }
}
void Wallet::pauseRefresh()
@@ -1182,6 +1195,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
, m_refreshNow(false)
, m_refreshEnabled(false)
, m_refreshing(false)
+ , m_refreshThreadStarted(false)
, m_scheduler(this)
{
m_walletListener = new WalletListenerImpl(this);
@@ -1195,7 +1209,6 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
m_daemonUsername = "";
m_daemonPassword = "";
- startRefreshThread();
}
Wallet::~Wallet()
diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h
index a5bb913..e41540e 100644
--- a/src/libwalletqt/Wallet.h
+++ b/src/libwalletqt/Wallet.h
@@ -493,6 +493,7 @@ private:
std::atomic<bool> m_refreshNow;
std::atomic<bool> m_refreshEnabled;
std::atomic<bool> m_refreshing;
+ std::atomic<bool> m_refreshThreadStarted;
WalletListenerImpl *m_walletListener;
FutureScheduler m_scheduler;
};
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.