Skip to content

Commit cd3b6d0

Browse files
hebastoryanofsky
andcommitted
qt: Fix regression in TransactionTableModel
Since #17993 a crash is possible on exit. Co-authored-by: Russell Yanofsky <[email protected]>
1 parent dbd7a91 commit cd3b6d0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
664664
QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const
665665
{
666666
Q_UNUSED(parent);
667-
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->clientModel().getBestBlockHash(), row);
667+
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), row);
668668
if(data)
669669
{
670670
return createIndex(row, column, data);

src/qt/walletmodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void WalletModel::pollBalanceChanged()
8787
{
8888
// Avoid recomputing wallet balances unless a TransactionChanged or
8989
// BlockTip notification was received.
90-
if (!fForceCheckBalanceChanged && m_cached_last_update_tip == m_client_model->getBestBlockHash()) return;
90+
if (!fForceCheckBalanceChanged && m_cached_last_update_tip == getLastBlockProcessed()) return;
9191

9292
// Try to get balances and return early if locks can't be acquired. This
9393
// avoids the GUI from getting stuck on periodical polls if the core is
@@ -588,3 +588,8 @@ void WalletModel::refresh(bool pk_hash_only)
588588
{
589589
addressTableModel = new AddressTableModel(this, pk_hash_only);
590590
}
591+
592+
uint256 WalletModel::getLastBlockProcessed()
593+
{
594+
return m_client_model ? m_client_model->getBestBlockHash() : uint256{};
595+
}

src/qt/walletmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class WalletModel : public QObject
155155
AddressTableModel* getAddressTableModel() const { return addressTableModel; }
156156

157157
void refresh(bool pk_hash_only = false);
158+
159+
uint256 getLastBlockProcessed();
160+
158161
private:
159162
std::unique_ptr<interfaces::Wallet> m_wallet;
160163
std::unique_ptr<interfaces::Handler> m_handler_unload;

0 commit comments

Comments
 (0)