From dcc479c2c240609d66f14948bbb0db3e8d113895 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Thu, 17 Feb 2022 10:30:56 +0800 Subject: [PATCH] Updated the pollCheckBalance method to be more like upstream version (#933) * Updated the pollCheckBalance method to be more like upstream version * Moved check stakes logic into checkbalance function to make sure it always runs when check balance is called * Removed redundant call * Wrong expression for checking block count --- src/qt/walletmodel.cpp | 23 +++++++++++++---------- src/qt/walletmodel.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 6a4058641..cb22ede84 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -57,7 +57,6 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, Op cachedAmountExp(-1) { fHaveWatchOnly = wallet->HaveWatchOnly(); - fForceCheckBalanceChanged = true; addressTableModel = new AddressTableModel(wallet, this); transactionTableModel = new TransactionTableModel(platformStyle, wallet, this); @@ -75,8 +74,7 @@ void WalletModel::StartBalanceTimer() { // This timer will be fired repeatedly to update the balance pollTimer = new QTimer(this); - connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged(true))); - pollBalanceChanged(true); + connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged())); pollTimer->start(MODEL_UPDATE_DELAY); } @@ -160,8 +158,12 @@ void WalletModel::updateStatus() Q_EMIT encryptionStatusChanged(newEncryptionStatus); } -void WalletModel::pollBalanceChanged(bool calledByPoll) +void WalletModel::pollBalanceChanged() { + // Avoid recomputing wallet balances unless a TransactionChanged or + // BlockTip notification was received. + if (!fForceCheckBalanceChanged && chainActive.Height() == cachedNumBlocks) return; + // Get required locks upfront. 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 rescan. @@ -171,19 +173,18 @@ void WalletModel::pollBalanceChanged(bool calledByPoll) TRY_LOCK(wallet->cs_wallet, lockWallet); if(!lockWallet) return; - if(fForceCheckBalanceChanged || calledByPoll) - { + + if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks) { fForceCheckBalanceChanged = false; // Balance and number of transactions might have changed cachedNumBlocks = chainActive.Height(); checkBalanceChanged(); - checkStakesChanged(); - } - if(transactionTableModel && chainActive.Height() != cachedNumBlocks) - transactionTableModel->updateConfirmations(); + if(transactionTableModel) + transactionTableModel->updateConfirmations(); + } } void WalletModel::checkBalanceChanged() @@ -246,6 +247,8 @@ void WalletModel::checkBalanceChanged() newPrivateBalanceLocked ); } + + checkStakesChanged(); } void WalletModel::checkStakesChanged() diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index daab727cc..5361da967 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -314,7 +314,7 @@ public Q_SLOTS: /* Watch-only added */ void updateWatchOnlyFlag(bool fHaveWatchonly); /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */ - void pollBalanceChanged(bool calledByPoll = false); + void pollBalanceChanged(); }; #endif // NAVCOIN_QT_WALLETMODEL_H