Skip to content

Commit d3a56be

Browse files
committed
Revert "gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged"
This reverts commit 0933a37 from bitcoin#18160 which no longer an optimization since commit "gui: Avoid wallet tryGetBalances calls before TransactionChanged or BlockTip notifications".
1 parent bf0a510 commit d3a56be

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/interfaces/wallet.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,13 @@ class WalletImpl : public Wallet
351351
}
352352
return result;
353353
}
354-
bool tryGetBalances(WalletBalances& balances, int& num_blocks, bool force, int cached_num_blocks) override
354+
bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
355355
{
356356
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
357357
if (!locked_wallet) {
358358
return false;
359359
}
360360
num_blocks = m_wallet->GetLastBlockHeight();
361-
if (!force && num_blocks == cached_num_blocks) return false;
362361
balances = getBalances();
363362
return true;
364363
}

src/interfaces/wallet.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,8 @@ class Wallet
201201
//! Get balances.
202202
virtual WalletBalances getBalances() = 0;
203203

204-
//! Get balances if possible without waiting for chain and wallet locks.
205-
virtual bool tryGetBalances(WalletBalances& balances,
206-
int& num_blocks,
207-
bool force,
208-
int cached_num_blocks) = 0;
204+
//! Get balances if possible without blocking.
205+
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
209206

210207
//! Get balance.
211208
virtual CAmount getBalance() = 0;

src/qt/walletmodel.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,21 @@ void WalletModel::pollBalanceChanged()
9595
// rescan.
9696
interfaces::WalletBalances new_balances;
9797
int numBlocks = -1;
98-
if (!m_wallet->tryGetBalances(new_balances, numBlocks, fForceCheckBalanceChanged, cachedNumBlocks)) {
98+
if (!m_wallet->tryGetBalances(new_balances, numBlocks)) {
9999
return;
100100
}
101101

102-
fForceCheckBalanceChanged = false;
102+
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
103+
{
104+
fForceCheckBalanceChanged = false;
103105

104-
// Balance and number of transactions might have changed
105-
cachedNumBlocks = numBlocks;
106+
// Balance and number of transactions might have changed
107+
cachedNumBlocks = numBlocks;
106108

107-
checkBalanceChanged(new_balances);
108-
if(transactionTableModel)
109-
transactionTableModel->updateConfirmations();
109+
checkBalanceChanged(new_balances);
110+
if(transactionTableModel)
111+
transactionTableModel->updateConfirmations();
112+
}
110113
}
111114

112115
void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)

0 commit comments

Comments
 (0)