mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-05 10:29:30 +00:00
Fix behavior when switching nodes
- Improved synchronization when switching nodes - Avoid infinite "Connecting" loop - Pause refresh loop while switching, don't start until connected
This commit is contained in:
parent
57fefba386
commit
6f2aafdd6c
2 changed files with 22 additions and 8 deletions
|
@ -101,20 +101,30 @@ NetworkType::Type Wallet::nettype() const
|
||||||
void Wallet::updateConnectionStatusAsync()
|
void Wallet::updateConnectionStatusAsync()
|
||||||
{
|
{
|
||||||
m_scheduler.run([this] {
|
m_scheduler.run([this] {
|
||||||
|
qDebug() << "updateConnectionStatusAsync current status:" << m_connectionStatus;
|
||||||
if (m_connectionStatus == Wallet::ConnectionStatus_Disconnected)
|
if (m_connectionStatus == Wallet::ConnectionStatus_Disconnected)
|
||||||
{
|
{
|
||||||
setConnectionStatus(ConnectionStatus_Connecting);
|
setConnectionStatus(ConnectionStatus_Connecting);
|
||||||
}
|
}
|
||||||
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
||||||
|
qDebug() << "Newest wallet status:" << newStatus;
|
||||||
|
if (m_connectionStatus != newStatus)
|
||||||
|
{
|
||||||
setConnectionStatus(newStatus);
|
setConnectionStatus(newStatus);
|
||||||
|
if (newStatus == ConnectionStatus_Connected)
|
||||||
|
{
|
||||||
|
startRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
// Release lock
|
// Release lock
|
||||||
m_connectionStatusRunning = false;
|
m_connectionStatusRunning = false;
|
||||||
|
m_connectionStatusTime.restart();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
|
Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
|
||||||
{
|
{
|
||||||
if (!m_initialized)
|
if (!m_initialized || m_initializing)
|
||||||
{
|
{
|
||||||
return ConnectionStatus_Connecting;
|
return ConnectionStatus_Connecting;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +133,6 @@ Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
|
||||||
if (forceCheck || (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";
|
qDebug() << "Checking connection status";
|
||||||
m_connectionStatusRunning = true;
|
m_connectionStatusRunning = true;
|
||||||
m_connectionStatusTime.restart();
|
|
||||||
updateConnectionStatusAsync();
|
updateConnectionStatusAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,10 +165,9 @@ void Wallet::setConnectionStatus(ConnectionStatus value)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_connectionStatus = value;
|
m_connectionStatus = value;
|
||||||
emit connectionStatusChanged(m_connectionStatus);
|
emit connectionStatusChanged(value);
|
||||||
|
|
||||||
bool disconnected = m_connectionStatus == Wallet::ConnectionStatus_Connecting ||
|
bool disconnected = value != Wallet::ConnectionStatus_Connected;
|
||||||
m_connectionStatus == Wallet::ConnectionStatus_Disconnected;
|
|
||||||
|
|
||||||
if (m_disconnected != disconnected)
|
if (m_disconnected != disconnected)
|
||||||
{
|
{
|
||||||
|
@ -280,6 +288,8 @@ void Wallet::initAsync(
|
||||||
const QString &proxyAddress /* = "" */)
|
const QString &proxyAddress /* = "" */)
|
||||||
{
|
{
|
||||||
qDebug() << "initAsync: " + daemonAddress;
|
qDebug() << "initAsync: " + daemonAddress;
|
||||||
|
m_initializing = true;
|
||||||
|
pauseRefresh();
|
||||||
const auto future = m_scheduler.run([this, daemonAddress, trustedDaemon, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight, proxyAddress] {
|
const auto future = m_scheduler.run([this, daemonAddress, trustedDaemon, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight, proxyAddress] {
|
||||||
m_initialized = init(
|
m_initialized = init(
|
||||||
daemonAddress,
|
daemonAddress,
|
||||||
|
@ -289,12 +299,12 @@ void Wallet::initAsync(
|
||||||
isRecoveringFromDevice,
|
isRecoveringFromDevice,
|
||||||
restoreHeight,
|
restoreHeight,
|
||||||
proxyAddress);
|
proxyAddress);
|
||||||
|
m_initializing = false;
|
||||||
if (m_initialized)
|
if (m_initialized)
|
||||||
{
|
{
|
||||||
emit walletCreationHeightChanged();
|
emit walletCreationHeightChanged();
|
||||||
qDebug() << "init async finished - starting refresh";
|
qDebug() << "init async finished: " + daemonAddress;
|
||||||
connected(true);
|
connected(true);
|
||||||
startRefresh();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -544,12 +554,14 @@ bool Wallet::refresh(bool historyAndSubaddresses /* = true */)
|
||||||
|
|
||||||
void Wallet::startRefresh()
|
void Wallet::startRefresh()
|
||||||
{
|
{
|
||||||
|
qDebug() << "Starting refresh";
|
||||||
m_refreshEnabled = true;
|
m_refreshEnabled = true;
|
||||||
m_refreshNow = true;
|
m_refreshNow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wallet::pauseRefresh()
|
void Wallet::pauseRefresh()
|
||||||
{
|
{
|
||||||
|
qDebug() << "Pausing refresh";
|
||||||
m_refreshEnabled = false;
|
m_refreshEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1138,6 +1150,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
|
||||||
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
|
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
|
||||||
, m_disconnected(true)
|
, m_disconnected(true)
|
||||||
, m_initialized(false)
|
, m_initialized(false)
|
||||||
|
, m_initializing(false)
|
||||||
, m_currentSubaddressAccount(0)
|
, m_currentSubaddressAccount(0)
|
||||||
, m_subaddress(new Subaddress(m_walletImpl->subaddress(), this))
|
, m_subaddress(new Subaddress(m_walletImpl->subaddress(), this))
|
||||||
, m_subaddressModel(nullptr)
|
, m_subaddressModel(nullptr)
|
||||||
|
|
|
@ -461,6 +461,7 @@ private:
|
||||||
mutable QElapsedTimer m_connectionStatusTime;
|
mutable QElapsedTimer m_connectionStatusTime;
|
||||||
bool m_disconnected;
|
bool m_disconnected;
|
||||||
std::atomic<bool> m_initialized;
|
std::atomic<bool> m_initialized;
|
||||||
|
std::atomic<bool> m_initializing;
|
||||||
uint32_t m_currentSubaddressAccount;
|
uint32_t m_currentSubaddressAccount;
|
||||||
Subaddress * m_subaddress;
|
Subaddress * m_subaddress;
|
||||||
mutable SubaddressModel * m_subaddressModel;
|
mutable SubaddressModel * m_subaddressModel;
|
||||||
|
|
Loading…
Reference in a new issue