Skip to content

Commit

Permalink
qt: Fix regression in TransactionTableModel
Browse files Browse the repository at this point in the history
Summary:
Since PR17993 a crash is possible on exit.

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>

This is a backport of [[bitcoin-core/gui#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
  • Loading branch information
hebasto authored and PiRK committed Feb 23, 2021
1 parent 1730a74 commit 1efc1fd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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{};
}
2 changes: 2 additions & 0 deletions src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class WalletModel : public QObject {
return addressTableModel;
}

BlockHash getLastBlockProcessed() const;

private:
std::unique_ptr<interfaces::Wallet> m_wallet;
std::unique_ptr<interfaces::Handler> m_handler_unload;
Expand Down

0 comments on commit 1efc1fd

Please sign in to comment.