Skip to content

Commit be93ac1

Browse files
committed
src/qt/mempooltxtables.h/cpp:fix blocking issue
1 parent 15ac9bf commit be93ac1

File tree

8 files changed

+61
-63
lines changed

8 files changed

+61
-63
lines changed

src/qt/clientmodel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,17 @@ void ClientModel::onWalletTxChanged()
267267
for (std::unique_ptr<interfaces::Wallet>& wallet_ptr : m_node.walletLoader().getWallets()) {
268268
if (!wallet_ptr) continue;
269269
for (const interfaces::WalletTx& wtx : wallet_ptr->getWalletTxs()) {
270-
m_wallet_transactions.insert(wtx);
270+
interfaces::WalletTxStatus tx_status;
271+
int num_blocks;
272+
int64_t block_time;
273+
if (wallet_ptr->tryGetTxStatus(wtx.tx->GetHash(), tx_status, num_blocks, block_time)) {
274+
if (tx_status.depth_in_main_chain == 0 && !tx_status.is_in_main_chain) {
275+
m_wallet_transactions.append(wtx);
276+
}
277+
} else {
278+
// If status can't be retrieved, assume it's in mempool for now
279+
m_wallet_transactions.append(wtx);
280+
}
271281
}
272282
}
273283
Q_EMIT walletTxChanged();

src/qt/clientmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ClientModel : public QObject
113113
std::vector<mempool_feehist_sample> m_mempool_feehist;
114114
std::atomic<int64_t> m_mempool_feehist_last_sample_timestamp{0};
115115

116-
std::set<interfaces::WalletTx> m_wallet_transactions; // New: Stores active wallet's mempool transactions
116+
QList<interfaces::WalletTx> m_wallet_transactions; // New: Stores active wallet's mempool transactions
117117

118118
private:
119119
interfaces::Node& m_node;

src/qt/mempooldetail.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ void MempoolDetail::setPlatformStyle(const PlatformStyle* platform_style)
129129
}
130130
m_fee_table_model->setSelectedRange(m_selected_range);
131131
});
132+
133+
connect(m_tx_table_model, &MempoolTxTableModel::mempoolStatusChanged, this, &MempoolDetail::onMempoolStatusChanged);
134+
}
135+
136+
void MempoolDetail::onMempoolStatusChanged(bool hasMempoolTxs)
137+
{
138+
qDebug() << "MempoolDetail::onMempoolStatusChanged(" << hasMempoolTxs << ")";
139+
m_tx_table->setVisible(hasMempoolTxs);
132140
}
133141

134142
void MempoolDetail::setClientModel(ClientModel* model)
@@ -165,6 +173,7 @@ void MempoolDetail::updateTxTable()
165173
if (m_clientmodel) {
166174
QMutexLocker locker(&m_clientmodel->m_mempool_locker);
167175
bool has_active_wallet = !m_clientmodel->node().walletLoader().getWallets().empty();
176+
// m_clientmodel->m_wallet_transactions is now a QList<interfaces::WalletTx> and already filtered
168177
m_tx_table_model->updateModel(m_clientmodel->m_wallet_transactions, has_active_wallet);
169178
}
170179
}

src/qt/mempooldetail.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public Q_SLOTS:
3333
void onRangeSelected(int range);
3434
void updateFeeTable();
3535
void updateTxTable();
36+
void onMempoolStatusChanged(bool hasMempoolTxs);
3637

3738
void mousePressEvent(QMouseEvent *event) override;
3839
void mouseReleaseEvent(QMouseEvent *event) override;

src/qt/mempoolstats.cpp

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void MempoolStats::drawWalletTxIndicators()
341341
if (!m_clientmodel)
342342
return;
343343

344-
std::set<interfaces::WalletTx> wallet_transactions_copy;
344+
QList<interfaces::WalletTx> wallet_transactions_copy;
345345
{
346346
QMutexLocker locker(&m_wallet_tx_mutex);
347347
wallet_transactions_copy = m_wallet_transactions;
@@ -363,49 +363,33 @@ void MempoolStats::drawWalletTxIndicators()
363363

364364
for (const interfaces::WalletTx& wtx : wallet_transactions_copy) {
365365
if (!wtx.tx) continue;
366-
bool in_mempool = false;
367-
CAmount net_amount = 0;
368-
369-
for (std::unique_ptr<interfaces::Wallet>& wallet_ptr : m_clientmodel->node().walletLoader().getWallets()) {
370-
if (!wallet_ptr) continue;
371-
interfaces::WalletTxStatus tx_status;
372-
int num_blocks;
373-
int64_t block_time;
374-
375-
if (wallet_ptr->tryGetTxStatus(wtx.tx->GetHash(), tx_status, num_blocks, block_time)) {
376-
if (tx_status.depth_in_main_chain == 0 && !tx_status.is_abandoned) {
377-
in_mempool = true;
378-
net_amount = wtx.credit - wtx.debit;
379-
break; // Found status for this transaction, no need to check other wallets
380-
}
381-
}
382-
}
366+
// Transactions in m_wallet_transactions are already filtered to be in mempool
367+
// No need to check status again here.
368+
CAmount net_amount = wtx.credit - wtx.debit;
383369

384370
if (MEMPOOL_GRAPH_LOGGING) {
385-
LogPrintf("drawWalletTxIndicators: tx %s, in_mempool: %s, net_amount: %s\n", wtx.tx->GetHash().ToString(), in_mempool, net_amount);
371+
LogPrintf("drawWalletTxIndicators: tx %s, net_amount: %s\n", wtx.tx->GetHash().ToString(), net_amount);
386372
}
387373

388-
if (in_mempool) {
389-
QGraphicsTextItem *sign_item = nullptr;
390-
QColor sign_color;
391-
392-
if (net_amount > 0) { // Receive transaction
393-
gridFont.setPointSize(36);
394-
sign_item = m_scene->addText("+", gridFont);
395-
sign_color = QColor(0, 255, 0); // Green
396-
} else if (net_amount < 0) { // Send transaction
397-
gridFont.setPointSize(48);
398-
sign_item = m_scene->addText("-", gridFont);
399-
sign_color = QColor(255, 0, 0); // Red
400-
}
374+
QGraphicsTextItem *sign_item = nullptr;
375+
QColor sign_color;
376+
377+
if (net_amount > 0) { // Receive transaction
378+
gridFont.setPointSize(36);
379+
sign_item = m_scene->addText("+", gridFont);
380+
sign_color = QColor(0, 255, 0); // Green
381+
} else if (net_amount < 0) { // Send transaction
382+
gridFont.setPointSize(48);
383+
sign_item = m_scene->addText("-", gridFont);
384+
sign_color = QColor(255, 0, 0); // Red
385+
}
401386

402-
if (sign_item) {
403-
sign_item->setDefaultTextColor(sign_color);
404-
sign_item->setPos(indicator_x, indicator_y);
405-
sign_item->setToolTip(QString::fromStdString(wtx.tx->GetHash().ToString()));
406-
m_wallet_indicator_items.append(sign_item); // Store the item
407-
indicator_y += y_offset; // Move down for the next indicator
408-
}
387+
if (sign_item) {
388+
sign_item->setDefaultTextColor(sign_color);
389+
sign_item->setPos(indicator_x, indicator_y);
390+
sign_item->setToolTip(QString::fromStdString(wtx.tx->GetHash().ToString()));
391+
m_wallet_indicator_items.append(sign_item); // Store the item
392+
indicator_y += y_offset; // Move down for the next indicator
409393
}
410394
}
411395
}
@@ -431,18 +415,11 @@ void MempoolStats::onWalletTxChanged()
431415
{
432416
QMutexLocker locker(&m_wallet_tx_mutex);
433417
if (m_clientmodel) {
434-
m_clientmodel->m_wallet_transactions.clear(); // Clear ClientModel's transactions
435-
for (std::unique_ptr<interfaces::Wallet>& wallet_ptr : m_clientmodel->node().walletLoader().getWallets()) {
436-
if (!wallet_ptr) continue;
437-
for (const interfaces::WalletTx& wtx : wallet_ptr->getWalletTxs()) {
438-
m_clientmodel->m_wallet_transactions.insert(wtx); // Populate ClientModel's transactions
439-
}
440-
}
441-
m_wallet_transactions = m_clientmodel->m_wallet_transactions; // Keep MempoolStats's local copy in sync for indicators
418+
// ClientModel's m_wallet_transactions is already updated and filtered by ClientModel itself.
419+
// We just need to keep MempoolStats's local copy in sync.
420+
m_wallet_transactions = m_clientmodel->m_wallet_transactions;
442421
}
443422
}
444423
QMetaObject::invokeMethod(this, "drawChart", Qt::QueuedConnection);
445-
if (m_clientmodel) {
446-
Q_EMIT m_clientmodel->walletTxChanged(); // Emit ClientModel's signal
447-
}
424+
// No need to emit ClientModel's signal here, it's already emitted by ClientModel itself.
448425
}

src/qt/mempoolstats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Q_SLOTS:
5555
int m_selected_range = -1;
5656
MempoolDetail* m_mempool_detail{nullptr};
5757
QMutex m_wallet_tx_mutex;
58-
std::set<interfaces::WalletTx> m_wallet_transactions;
58+
QList<interfaces::WalletTx> m_wallet_transactions;
5959
std::vector<std::unique_ptr<interfaces::Handler>> m_wallet_handlers;
6060
QList<QGraphicsItem*> m_wallet_indicator_items;
6161
QList<ClickableFeePathItem*> m_fee_path_items;

src/qt/mempooltxtables.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,24 @@ void MempoolTxTableModel::sort(int column, Qt::SortOrder order)
156156
endResetModel();
157157
}
158158

159-
void MempoolTxTableModel::updateModel(const std::set<interfaces::WalletTx>& wallet_transactions, bool has_active_wallet)
159+
void MempoolTxTableModel::updateModel(const QList<interfaces::WalletTx>& wallet_transactions, bool has_active_wallet)
160160
{
161161
beginResetModel();
162162
m_tx_data.clear();
163163

164164
if (!has_active_wallet || wallet_transactions.empty()) {
165165
endResetModel();
166+
qDebug() << "MempoolTxTableModel::mempoolStatusChanged(" << !m_tx_data.empty() << ")";
167+
Q_EMIT mempoolStatusChanged(!m_tx_data.empty());
166168
return;
167169
}
168170

169-
for (const auto& wtx : wallet_transactions) {
170-
// Only add transactions that are currently in the mempool
171-
// This logic might need to be more sophisticated if we want to show other statuses
172-
// For now, we assume the set only contains mempool transactions or we filter here.
173-
// The `drawWalletTxIndicators` in MempoolStats already checks for in_mempool status.
174-
// We'll rely on that for now, or add a similar check here if needed.
175-
m_tx_data.append(wtx);
176-
}
171+
m_tx_data = wallet_transactions;
172+
177173
if (m_sort_column != -1) {
178174
sort(m_sort_column, m_sort_order);
179175
}
180176
endResetModel();
177+
qDebug() << "MempoolTxTableModel::mempoolStatusChanged(" << !m_tx_data.empty() << ")";
178+
Q_EMIT mempoolStatusChanged(!m_tx_data.empty());
181179
}

src/qt/mempooltxtables.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ class MempoolTxTableModel : public QAbstractTableModel
4444
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
4545
/*@}*/
4646

47+
Q_SIGNALS:
48+
void mempoolStatusChanged(bool hasMempoolTxs);
49+
4750
public Q_SLOTS:
48-
void updateModel(const std::set<interfaces::WalletTx>& wallet_transactions, bool has_active_wallet);
51+
void updateModel(const QList<interfaces::WalletTx>& wallet_transactions, bool has_active_wallet);
4952

5053
public:
5154
QList<interfaces::WalletTx> m_tx_data;

0 commit comments

Comments
 (0)