Skip to content

Commit

Permalink
[GUI] Do not update the GUI so often when reindex/import is being exe…
Browse files Browse the repository at this point in the history
…cuted.
  • Loading branch information
Liquid369 committed Apr 17, 2020
1 parent 97d2bcc commit b938577
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ std::condition_variable g_best_block_cv;
uint256 g_best_block;

int nScriptCheckThreads = 0;
bool fImporting = false;
bool fReindex = false;
std::atomic<bool> fImporting{false};
std::atomic<bool> fReindex{false};
bool fTxIndex = true;
bool fIsBareMultisigStd = true;
bool fCheckBlockIndex = false;
Expand Down Expand Up @@ -5287,7 +5287,7 @@ bool static LoadBlockIndexDB(string& strError)
// Check whether we need to continue reindexing
bool fReindexing = false;
pblocktree->ReadReindexing(fReindexing);
fReindex |= fReindexing;
if(fReindexing) fReindex = true;

// Check whether we have a transaction index
pblocktree->ReadFlag("txindex", fTxIndex);
Expand Down
5 changes: 3 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "undo.h"

#include <algorithm>
#include <atomic>
#include <exception>
#include <map>
#include <set>
Expand Down Expand Up @@ -153,8 +154,8 @@ extern CWaitableCriticalSection g_best_block_mutex;
extern std::condition_variable g_best_block_cv;
extern uint256 g_best_block;

extern bool fImporting;
extern bool fReindex;
extern std::atomic<bool> fImporting;
extern std::atomic<bool> fReindex;
extern int nScriptCheckThreads;
extern bool fTxIndex;
extern bool fIsBareMultisigStd;
Expand Down
17 changes: 15 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,20 @@ bool WalletModel::isWalletUnlocked() const {
return status == Unencrypted || status == Unlocked;
}

bool IsImportingOrReindexing() {
return fImporting || fReindex;
}

void WalletModel::pollBalanceChanged()
{
// Wait a little bit more when the wallet is reindexing and/or importing, no need to lock cs_main so often.
if (IsImportingOrReindexing()) {
static uint8_t waitLonger = 0;
waitLonger++;
if (waitLonger < 10) // 10 seconds
return;
waitLonger = 0;
}
// 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.
Expand All @@ -186,11 +198,12 @@ void WalletModel::pollBalanceChanged()
if (!lockWallet)
return;

if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks || nZeromintPercentage != cachedZeromintPercentage || cachedTxLocks != nCompleteTXLocks) {
int chainHeight = chainActive.Height();
if (fForceCheckBalanceChanged || chainHeight != cachedNumBlocks) {
fForceCheckBalanceChanged = false;

// Balance and number of transactions might have changed
cachedNumBlocks = chainActive.Height();
cachedNumBlocks = chainHeight;
cachedZeromintPercentage = nZeromintPercentage;

checkBalanceChanged();
Expand Down

0 comments on commit b938577

Please sign in to comment.