From cebb78979ca2806c5b39a02fcb2336923676d97f Mon Sep 17 00:00:00 2001 From: xiphon Date: Sat, 12 Dec 2020 11:20:34 +0000 Subject: [PATCH] Wallet: fix initialization flag handling --- src/libwalletqt/Wallet.cpp | 29 +++++++++++++++++++++-------- src/libwalletqt/Wallet.h | 4 +++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index c3bae144..010bb487 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -104,10 +104,7 @@ void Wallet::updateConnectionStatusAsync() setConnectionStatus(ConnectionStatus_Connecting); } ConnectionStatus newStatus = static_cast(m_walletImpl->connected()); - if (newStatus != m_connectionStatus || !m_initialized) { - m_initialized = true; - setConnectionStatus(newStatus); - } + setConnectionStatus(newStatus); // Release lock m_connectionStatusRunning = false; }); @@ -115,8 +112,13 @@ void Wallet::updateConnectionStatusAsync() Wallet::ConnectionStatus Wallet::connected(bool forceCheck) { + if (!m_initialized) + { + return ConnectionStatus_Connecting; + } + // cache connection status - if (forceCheck || !m_initialized || (m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl && !m_connectionStatusRunning) || m_connectionStatusTime.elapsed() > 30000) { + if (forceCheck || (m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl && !m_connectionStatusRunning) || m_connectionStatusTime.elapsed() > 30000) { qDebug() << "Checking connection status"; m_connectionStatusRunning = true; m_connectionStatusTime.restart(); @@ -277,14 +279,25 @@ void Wallet::initAsync( { qDebug() << "initAsync: " + daemonAddress; const auto future = m_scheduler.run([this, daemonAddress, trustedDaemon, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight, proxyAddress] { - bool success = init(daemonAddress, trustedDaemon, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight, proxyAddress); - if (success) + m_initialized = init( + daemonAddress, + trustedDaemon, + upperTransactionLimit, + isRecovering, + isRecoveringFromDevice, + restoreHeight, + proxyAddress); + if (m_initialized) { emit walletCreationHeightChanged(); qDebug() << "init async finished - starting refresh"; connected(true); startRefresh(); } + else + { + qCritical() << "Failed to initialize the wallet"; + } }); if (future.first) { @@ -1054,6 +1067,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent) , m_connectionStatus(Wallet::ConnectionStatus_Disconnected) , m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS) , m_disconnected(true) + , m_initialized(false) , m_currentSubaddressAccount(0) , m_subaddress(nullptr) , m_subaddressModel(nullptr) @@ -1074,7 +1088,6 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent) m_connectionStatusTime.start(); m_daemonBlockChainHeightTime.start(); m_daemonBlockChainTargetHeightTime.start(); - m_initialized = false; m_connectionStatusRunning = false; m_daemonUsername = ""; m_daemonPassword = ""; diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 42e30336..0f6d1353 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -29,6 +29,8 @@ #ifndef WALLET_H #define WALLET_H +#include + #include #include #include @@ -444,7 +446,7 @@ private: int m_connectionStatusTtl; mutable QElapsedTimer m_connectionStatusTime; bool m_disconnected; - mutable bool m_initialized; + std::atomic m_initialized; uint32_t m_currentSubaddressAccount; Subaddress * m_subaddress; mutable SubaddressModel * m_subaddressModel;