From 1efc1fd3775994234c42eb8906dad01cd4a32de6 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 22 Jun 2020 23:35:48 +0300 Subject: [PATCH] qt: Fix regression in TransactionTableModel Summary: Since PR17993 a crash is possible on exit. Co-authored-by: Russell Yanofsky This is a backport of [[https://github.com/bitcoin-core/gui/pull/8 | core-gui#8]] Depends on D9254 Test Plan: start bitcoin-qt wait until sync on main window: Menu -> File -> Quit Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D9257 --- src/qt/transactionrecord.cpp | 1 + src/qt/transactiontablemodel.cpp | 8 ++++---- src/qt/walletmodel.cpp | 6 +++++- src/qt/walletmodel.h | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 2dfd45f81b..d27543edb1 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -214,6 +214,7 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus &wtx, } bool TransactionRecord::statusUpdateNeeded(const BlockHash &block_hash) const { + assert(!block_hash.IsNull()); return status.m_cur_block_hash != block_hash; } diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index d9605d72ad..5a05fe6a4e 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -186,7 +186,8 @@ class TransactionTablePriv { interfaces::WalletTxStatus wtx; int numBlocks; int64_t block_time; - if (rec->statusUpdateNeeded(cur_block_hash) && + if (!cur_block_hash.IsNull() && + rec->statusUpdateNeeded(cur_block_hash) && wallet.tryGetTxStatus(rec->txid, wtx, numBlocks, block_time)) { rec->updateStatus(wtx, cur_block_hash, numBlocks, block_time); } @@ -671,9 +672,8 @@ QVariant TransactionTableModel::headerData(int section, QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const { Q_UNUSED(parent); - TransactionRecord *data = - priv->index(walletModel->wallet(), - walletModel->clientModel().getBestBlockHash(), row); + TransactionRecord *data = priv->index( + walletModel->wallet(), walletModel->getLastBlockProcessed(), row); if (data) { return createIndex(row, column, data); } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index f309f16806..401ce7be88 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -72,7 +72,7 @@ void WalletModel::pollBalanceChanged() { // Avoid recomputing wallet balances unless a TransactionChanged or // BlockTip notification was received. if (!fForceCheckBalanceChanged && - m_cached_last_update_tip == m_client_model->getBestBlockHash()) { + m_cached_last_update_tip == getLastBlockProcessed()) { return; } @@ -531,3 +531,7 @@ bool WalletModel::isMultiwallet() { const CChainParams &WalletModel::getChainParams() const { return Params(); } + +BlockHash WalletModel::getLastBlockProcessed() const { + return m_client_model ? m_client_model->getBestBlockHash() : BlockHash{}; +} diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 6c99088c20..921b9fabb0 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -162,6 +162,8 @@ class WalletModel : public QObject { return addressTableModel; } + BlockHash getLastBlockProcessed() const; + private: std::unique_ptr m_wallet; std::unique_ptr m_handler_unload;