Skip to content

Commit

Permalink
ipc-bal # Revert "gui: Avoid Wallet::GetBalance in WalletModel::pollB…
Browse files Browse the repository at this point in the history
…alanceChanged"

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".
  • Loading branch information
ryanofsky committed May 1, 2020
1 parent 803fb13 commit a4bc125
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,13 @@ class WalletImpl : public Wallet
}
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);
if (!locked_wallet) {
return false;
}
num_blocks = m_wallet->GetLastBlockHeight();
if (!force && num_blocks == cached_num_blocks) return false;
balances = getBalances();
return true;
}
Expand Down
7 changes: 2 additions & 5 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,8 @@ class Wallet
//! Get balances.
virtual WalletBalances getBalances() = 0;

//! Get balances if possible without waiting for chain and wallet locks.
virtual bool tryGetBalances(WalletBalances& balances,
int& num_blocks,
bool force,
int cached_num_blocks) = 0;
//! Get balances if possible without blocking.
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;

//! Get balance.
virtual CAmount getBalance() = 0;
Expand Down
17 changes: 10 additions & 7 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ void WalletModel::pollBalanceChanged()
// rescan.
interfaces::WalletBalances new_balances;
int numBlocks = -1;
if (!m_wallet->tryGetBalances(new_balances, numBlocks, fForceCheckBalanceChanged, cachedNumBlocks)) {
if (!m_wallet->tryGetBalances(new_balances, numBlocks)) {
return;
}

fForceCheckBalanceChanged = false;
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
{
fForceCheckBalanceChanged = false;

// Balance and number of transactions might have changed
cachedNumBlocks = numBlocks;
// Balance and number of transactions might have changed
cachedNumBlocks = numBlocks;

checkBalanceChanged(new_balances);
if(transactionTableModel)
transactionTableModel->updateConfirmations();
checkBalanceChanged(new_balances);
if(transactionTableModel)
transactionTableModel->updateConfirmations();
}
}

void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)
Expand Down

0 comments on commit a4bc125

Please sign in to comment.