Skip to content

Commit 4946400

Browse files
author
MarcoFalke
committed
Merge #8: Fix regression in TransactionTableModel
d906aaa qt: Fix regression in TransactionTableModel (Hennadii Stepanov) Pull request description: Since bitcoin/bitcoin#17993 a crash is possible on exit. Steps to reproduce: - precondition: the old chain - start `bitcoin-qt` - wait until sync - on main window: Menu -> File -> Quit - crash This PR is based on ryanofsky's [suggestion](#7 (comment)). Fixes #7. ACKs for top commit: promag: Code review ACK d906aaa. ryanofsky: Code review ACK d906aaa. Only changes are squashing, adding assert and adding const vasild: ACK d906aaa Tree-SHA512: 99a475fd90dff50407a58537fdc6099a2a074018e9078452bf86defc1a4b9e546aa94f916d242355900b21638c6cfef845598a5282661a9343556c4514eb155f
2 parents 3bbd822 + d906aaa commit 4946400

4 files changed

+12
-3
lines changed

src/qt/transactionrecord.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, cons
234234

235235
bool TransactionRecord::statusUpdateNeeded(const uint256& block_hash) const
236236
{
237+
assert(!block_hash.IsNull());
237238
return status.m_cur_block_hash != block_hash || status.needsUpdate;
238239
}
239240

src/qt/transactiontablemodel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class TransactionTablePriv
192192
interfaces::WalletTxStatus wtx;
193193
int numBlocks;
194194
int64_t block_time;
195-
if (rec->statusUpdateNeeded(cur_block_hash) && wallet.tryGetTxStatus(rec->hash, wtx, numBlocks, block_time)) {
195+
if (!cur_block_hash.IsNull() && rec->statusUpdateNeeded(cur_block_hash) && wallet.tryGetTxStatus(rec->hash, wtx, numBlocks, block_time)) {
196196
rec->updateStatus(wtx, cur_block_hash, numBlocks, block_time);
197197
}
198198
return rec;
@@ -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

+6-1
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() const
593+
{
594+
return m_client_model ? m_client_model->getBestBlockHash() : uint256{};
595+
}

src/qt/walletmodel.h

+3
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() const;
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)