diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index eeef9a68de..8d922dc42c 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -229,8 +229,11 @@ public: //! Get balances. virtual WalletBalances getBalances() = 0; - //! Get balances if possible without blocking. - virtual bool tryGetBalances(WalletBalances& balances, uint256& block_hash) = 0; + //! Get balances if possible without waiting for chain and wallet locks. + virtual bool tryGetBalances(WalletBalances& balances, + uint256& block_hash, + bool force, + const uint256& cached_last_update_tip) = 0; //! Get balance. virtual CAmount getBalance() = 0; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index faadbdaaaf..831fb68f87 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -101,22 +101,19 @@ void WalletModel::pollBalanceChanged() // rescan. interfaces::WalletBalances new_balances; uint256 block_hash; - if (!m_wallet->tryGetBalances(new_balances, block_hash)) { + if (!m_wallet->tryGetBalances(new_balances, block_hash, fForceCheckBalanceChanged, m_cached_last_update_tip)) { return; } - if (fForceCheckBalanceChanged || block_hash != m_cached_last_update_tip || node().coinJoinOptions().getRounds() != cachedCoinJoinRounds) - { - fForceCheckBalanceChanged = false; + fForceCheckBalanceChanged = false; - // Balance and number of transactions might have changed - m_cached_last_update_tip = block_hash; - cachedCoinJoinRounds = node().coinJoinOptions().getRounds(); + // Balance and number of transactions might have changed + m_cached_last_update_tip = block_hash; + cachedCoinJoinRounds = node().coinJoinOptions().getRounds(); - checkBalanceChanged(new_balances); - if(transactionTableModel) - transactionTableModel->updateConfirmations(); - } + checkBalanceChanged(new_balances); + if(transactionTableModel) + transactionTableModel->updateConfirmations(); } void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances) diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 200bf3e831..1fbb75ce74 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -434,13 +434,14 @@ public: } return result; } - bool tryGetBalances(WalletBalances& balances, uint256& block_hash) override + bool tryGetBalances(WalletBalances& balances, uint256& block_hash, bool force, const uint256& cached_last_update_tip) override { + block_hash = m_wallet->GetLastBlockHash(); + if (!force && block_hash == cached_last_update_tip) return false; TRY_LOCK(m_wallet->cs_wallet, locked_wallet); if (!locked_wallet) { return false; } - block_hash = m_wallet->GetLastBlockHash(); balances = getBalances(); return true; }