Revert "gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged"

This reverts commit 0933a37078 from
https://github.com/bitcoin/bitcoin/pull/18160 which no longer an optimization
since commit "gui: Avoid wallet tryGetBalances calls before TransactionChanged
or BlockTip notifications".
This commit is contained in:
Russell Yanofsky 2020-04-02 07:55:14 -04:00
parent bf0a510981
commit d3a56be77a
3 changed files with 13 additions and 14 deletions

View File

@ -351,14 +351,13 @@ public:
} }
return result; return result;
} }
bool tryGetBalances(WalletBalances& balances, int& num_blocks, bool force, int cached_num_blocks) override bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
{ {
TRY_LOCK(m_wallet->cs_wallet, locked_wallet); TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
if (!locked_wallet) { if (!locked_wallet) {
return false; return false;
} }
num_blocks = m_wallet->GetLastBlockHeight(); num_blocks = m_wallet->GetLastBlockHeight();
if (!force && num_blocks == cached_num_blocks) return false;
balances = getBalances(); balances = getBalances();
return true; return true;
} }

View File

@ -201,11 +201,8 @@ public:
//! Get balances. //! Get balances.
virtual WalletBalances getBalances() = 0; virtual WalletBalances getBalances() = 0;
//! Get balances if possible without waiting for chain and wallet locks. //! Get balances if possible without blocking.
virtual bool tryGetBalances(WalletBalances& balances, virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
int& num_blocks,
bool force,
int cached_num_blocks) = 0;
//! Get balance. //! Get balance.
virtual CAmount getBalance() = 0; virtual CAmount getBalance() = 0;

View File

@ -95,18 +95,21 @@ void WalletModel::pollBalanceChanged()
// rescan. // rescan.
interfaces::WalletBalances new_balances; interfaces::WalletBalances new_balances;
int numBlocks = -1; int numBlocks = -1;
if (!m_wallet->tryGetBalances(new_balances, numBlocks, fForceCheckBalanceChanged, cachedNumBlocks)) { if (!m_wallet->tryGetBalances(new_balances, numBlocks)) {
return; return;
} }
fForceCheckBalanceChanged = false; if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
{
fForceCheckBalanceChanged = false;
// Balance and number of transactions might have changed // Balance and number of transactions might have changed
cachedNumBlocks = numBlocks; cachedNumBlocks = numBlocks;
checkBalanceChanged(new_balances); checkBalanceChanged(new_balances);
if(transactionTableModel) if(transactionTableModel)
transactionTableModel->updateConfirmations(); transactionTableModel->updateConfirmations();
}
} }
void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances) void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)