From fa29ed5b5eef69dcf7735734309f378852c61173 Mon Sep 17 00:00:00 2001 From: pasta Date: Fri, 6 Dec 2024 16:51:57 -0600 Subject: [PATCH] Merge #6456: fix(qt): allow refreshing wallet data without crashing d296005194c7bd8c65006ddf1b25052b2655c923 fix(qt): allow refreshing wallet data without crashing (UdjinM6) Pull request description: ## Issue being fixed or feature implemented We re-use `refreshWallet` method to optimise loading for huge wallets https://github.com/dashpay/dash/pull/5453. However gui121 backport (via 25f87b9434b98a524d38a97d9fe580acc0fa47ce) added a condition that prevents this logic. Fix it by allowing explicit wallet refresh (force=true). ## What was done? ## How Has This Been Tested? Open a wallet with 10k+ txes, do `rescanblockchain` via rpc console ## Breaking Changes ## Checklist: - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK d296005194c7bd8c65006ddf1b25052b2655c923; Tree-SHA512: d308b3fe9c4fbbfbf2e2339aa14c825aa6f69c72d1f04dab7a14dc1c8721138beca47c7b3801db9782d6cecf2c54023a19a6d22e04b84615f9bddb0b8ec1696c --- src/qt/transactiontablemodel.cpp | 16 +++++++++------- src/qt/transactiontablemodel.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 01de92c61d..3d2052d445 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -106,10 +106,11 @@ public: /* Query entire wallet anew from core. */ - void refreshWallet(interfaces::Wallet& wallet) + void refreshWallet(interfaces::Wallet& wallet, bool force = false) { parent->beginResetModel(); - assert(!m_loaded); + assert(!m_loaded || force); + cachedWallet.clear(); try { for (const auto& wtx : wallet.getWalletTxs()) { if (TransactionRecord::showTransaction()) { @@ -284,9 +285,9 @@ TransactionTableModel::~TransactionTableModel() delete priv; } -void TransactionTableModel::refreshWallet() +void TransactionTableModel::refreshWallet(bool force) { - priv->refreshWallet(walletModel->wallet()); + priv->refreshWallet(walletModel->wallet(), force); } /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */ @@ -846,12 +847,13 @@ void TransactionTablePriv::DispatchNotifications() vQueueNotifications[i].invoke(parent); } + vQueueNotifications.clear(); } else { - // it's much faster to just refresh the whole thing instead - bool invoked = QMetaObject::invokeMethod(parent, "refreshWallet", Qt::QueuedConnection); + // it's much faster to just drop all the queued notifications and refresh the whole thing instead + vQueueNotifications.clear(); + bool invoked = QMetaObject::invokeMethod(parent, "refreshWallet", Qt::QueuedConnection, Q_ARG(bool, true)); assert(invoked); } - vQueueNotifications.clear(); } void TransactionTableModel::subscribeToCoreSignals() diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index b1f933e255..630fec039f 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -114,7 +114,7 @@ private: public Q_SLOTS: /* Refresh the whole wallet, helpful for huge notification queues */ - void refreshWallet(); + void refreshWallet(bool foce = false); /* New transaction, or transaction changed status */ void updateTransaction(const QString &hash, int status, bool showTransaction); void updateAddressBook(const QString &address, const QString &label,