partial bitcoin#18587: Avoid wallet tryGetBalances calls in WalletModel::pollBalanceChanged

contains:
- 2bc9b92ed8b7736ad67876398a0bb8287f57e9b3
- bf0a510981ddc28c754881ca21c50ab18e5f2b59
This commit is contained in:
Kittywhiskers Van Gogh 2020-04-24 18:06:26 -04:00 committed by PastaPastaPasta
parent 4df5b1c637
commit 3b08a1c49a
3 changed files with 18 additions and 5 deletions

View File

@ -39,7 +39,7 @@
WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, QObject *parent) :
QObject(parent),
m_wallet(std::move(wallet)),
m_client_model(client_model),
m_client_model(&client_model),
m_node(client_model.node()),
optionsModel(client_model.getOptionsModel()),
addressTableModel(nullptr),
@ -47,7 +47,8 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel
recentRequestsTableModel(nullptr),
cachedEncryptionStatus(Unencrypted),
cachedNumISLocks(0),
cachedCoinJoinRounds(0)
cachedCoinJoinRounds(0),
timer(new QTimer(this))
{
fHaveWatchOnly = m_wallet->haveWatchOnly();
addressTableModel = new AddressTableModel(this);
@ -65,11 +66,16 @@ WalletModel::~WalletModel()
void WalletModel::startPollBalance()
{
// This timer will be fired repeatedly to update the balance
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged);
timer->start(MODEL_UPDATE_DELAY);
}
void WalletModel::setClientModel(ClientModel* client_model)
{
m_client_model = client_model;
if (!m_client_model) timer->stop();
}
void WalletModel::updateStatus()
{
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
@ -85,6 +91,10 @@ void WalletModel::pollBalanceChanged()
return;
}
// Avoid recomputing wallet balances unless a TransactionChanged or
// BlockTip notification was received.
if (!fForceCheckBalanceChanged && m_cached_last_update_tip == m_client_model->getBestBlockHash()) return;
// Try to get balances and return early if locks can't be acquired. This
// avoids the GUI from getting stuck on periodical polls if the core is
// holding the locks for a longer time - for example, during a wallet

View File

@ -198,7 +198,8 @@ public:
interfaces::Node& node() const { return m_node; }
interfaces::Wallet& wallet() const { return *m_wallet; }
ClientModel& clientModel() const { return m_client_model; }
void setClientModel(ClientModel* client_model);
ClientModel& clientModel() const { return *m_client_model; }
interfaces::CoinJoin::Client& coinJoin() const { return m_wallet->coinJoin(); }
QString getWalletName() const;
@ -218,7 +219,7 @@ private:
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
std::unique_ptr<interfaces::Handler> m_handler_watch_only_changed;
std::unique_ptr<interfaces::Handler> m_handler_can_get_addrs_changed;
ClientModel& m_client_model;
ClientModel* m_client_model;
interfaces::Node& m_node;
bool fHaveWatchOnly;
@ -235,6 +236,7 @@ private:
// Cache some values to be able to detect changes
interfaces::WalletBalances m_cached_balances;
EncryptionStatus cachedEncryptionStatus;
QTimer* timer;
int cachedNumISLocks;
int cachedCoinJoinRounds;

View File

@ -145,6 +145,7 @@ void WalletView::setClientModel(ClientModel *_clientModel)
if (settings.value("fShowGovernanceTab").toBool() && governanceListPage != nullptr) {
governanceListPage->setClientModel(_clientModel);
}
if (walletModel) walletModel->setClientModel(_clientModel);
}
void WalletView::setWalletModel(WalletModel *_walletModel)