Skip to content

Commit acd432b

Browse files
committed
[Qt] Prevent balloon-spam after rescan
1 parent e8d4cb8 commit acd432b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/qt/walletmodel.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
3535
cachedEncryptionStatus(Unencrypted),
3636
cachedNumBlocks(0)
3737
{
38+
fProcessingQueuedTransactions = false;
39+
3840
addressTableModel = new AddressTableModel(wallet, this);
3941
transactionTableModel = new TransactionTableModel(wallet, this);
4042
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
@@ -492,8 +494,15 @@ static void ShowProgress(WalletModel *walletmodel, const std::string &title, int
492494
if (nProgress == 100)
493495
{
494496
fQueueNotifications = false;
495-
BOOST_FOREACH(const PAIRTYPE(uint256, ChangeType)& notification, vQueueNotifications)
496-
NotifyTransactionChanged(walletmodel, NULL, notification.first, notification.second);
497+
if (vQueueNotifications.size() > 10) // prevent balloon spam, show maximum 10 balloons
498+
QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
499+
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
500+
{
501+
if (vQueueNotifications.size() - i <= 10)
502+
QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
503+
504+
NotifyTransactionChanged(walletmodel, NULL, vQueueNotifications[i].first, vQueueNotifications[i].second);
505+
}
497506
std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
498507
}
499508
}

src/qt/walletmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class WalletModel : public QObject
133133
qint64 getWatchImmatureBalance() const;
134134
int getNumTransactions() const;
135135
EncryptionStatus getEncryptionStatus() const;
136+
bool processingQueuedTransactions() { return fProcessingQueuedTransactions; }
136137

137138
// Check address for validity
138139
bool validateAddress(const QString &address);
@@ -196,6 +197,7 @@ class WalletModel : public QObject
196197

197198
private:
198199
CWallet *wallet;
200+
bool fProcessingQueuedTransactions;
199201

200202
// Wallet has an options model for wallet-specific options
201203
// (transaction fee, for example)
@@ -256,6 +258,8 @@ public slots:
256258
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
257259
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
258260
void pollBalanceChanged();
261+
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
262+
void setProcessingQueuedTransactions(bool value) { fProcessingQueuedTransactions = value; }
259263
};
260264

261265
#endif // WALLETMODEL_H

src/qt/walletview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void WalletView::setWalletModel(WalletModel *walletModel)
137137
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
138138
{
139139
// Prevent balloon-spam when initial block download is in progress
140-
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
140+
if (!walletModel || walletModel->processingQueuedTransactions() || !clientModel || clientModel->inInitialBlockDownload())
141141
return;
142142

143143
TransactionTableModel *ttm = walletModel->getTransactionTableModel();

0 commit comments

Comments
 (0)