Skip to content

Commit 947d20b

Browse files
committed
[Qt] reduce cs_main in getVerificationProgress()
1 parent e6d50fc commit 947d20b

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

src/qt/bitcoingui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
443443
setNumConnections(clientModel->getNumConnections());
444444
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
445445

446-
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate());
447-
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(setNumBlocks(int,QDateTime)));
446+
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), NULL);
447+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,const CBlockIndex*)), this, SLOT(setNumBlocks(int,QDateTime,const CBlockIndex*)));
448448

449449
// Receive and report messages from client model
450450
connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
@@ -672,7 +672,7 @@ void BitcoinGUI::setNumConnections(int count)
672672
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
673673
}
674674

675-
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate)
675+
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const CBlockIndex *tip)
676676
{
677677
if(!clientModel)
678678
return;
@@ -749,7 +749,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate)
749749
progressBarLabel->setVisible(true);
750750
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
751751
progressBar->setMaximum(1000000000);
752-
progressBar->setValue(clientModel->getVerificationProgress() * 1000000000.0 + 0.5);
752+
progressBar->setValue(clientModel->getVerificationProgress(tip) * 1000000000.0 + 0.5);
753753
progressBar->setVisible(true);
754754

755755
tooltip = tr("Catching up...") + QString("<br>") + tooltip;

src/qt/bitcoingui.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UnitDisplayStatusBarControl;
2929
class WalletFrame;
3030
class WalletModel;
3131
class HelpMessageDialog;
32+
class CBlockIndex;
3233

3334
class CWallet;
3435

@@ -149,7 +150,7 @@ public Q_SLOTS:
149150
/** Set number of connections shown in the UI */
150151
void setNumConnections(int count);
151152
/** Set number of blocks and last block date shown in the UI */
152-
void setNumBlocks(int count, const QDateTime& blockDate);
153+
void setNumBlocks(int count, const QDateTime& blockDate, const CBlockIndex* tip);
153154

154155
/** Notify the user of an event from the core network or transaction handling code.
155156
@param[in] title the message box / notification title

src/qt/clientmodel.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <QDebug>
2323
#include <QTimer>
2424

25+
class CBlockIndex;
26+
2527
static const int64_t nClientStartupTime = GetTime();
2628
static int64_t nLastBlockTipUpdateNotification = 0;
2729

@@ -96,10 +98,9 @@ size_t ClientModel::getMempoolDynamicUsage() const
9698
return mempool.DynamicMemoryUsage();
9799
}
98100

99-
double ClientModel::getVerificationProgress() const
101+
double ClientModel::getVerificationProgress(const CBlockIndex *tip) const
100102
{
101-
LOCK(cs_main);
102-
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip());
103+
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), (CBlockIndex *)tip);
103104
}
104105

105106
void ClientModel::updateTimer()
@@ -246,7 +247,7 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
246247
// if we are in-sync, update the UI regardless of last update time
247248
if (!initialSync || now - nLastBlockTipUpdateNotification > MODEL_UPDATE_DELAY) {
248249
//pass a async signal to the UI thread
249-
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight, QDateTime::fromTime_t(pIndex->GetBlockTime()));
250+
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight, QDateTime::fromTime_t(pIndex->GetBlockTime()), pIndex);
250251
nLastBlockTipUpdateNotification = now;
251252
}
252253

src/qt/clientmodel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PeerTableModel;
1515
class TransactionTableModel;
1616

1717
class CWallet;
18+
class CBlockIndex;
1819

1920
QT_BEGIN_NAMESPACE
2021
class QTimer;
@@ -59,7 +60,7 @@ class ClientModel : public QObject
5960
quint64 getTotalBytesRecv() const;
6061
quint64 getTotalBytesSent() const;
6162

62-
double getVerificationProgress() const;
63+
double getVerificationProgress(const CBlockIndex *tip) const;
6364
QDateTime getLastBlockDate() const;
6465

6566
//! Return true if core is doing initial block download
@@ -88,7 +89,7 @@ class ClientModel : public QObject
8889

8990
Q_SIGNALS:
9091
void numConnectionsChanged(int count);
91-
void numBlocksChanged(int count, const QDateTime& blockDate);
92+
void numBlocksChanged(int count, const QDateTime& blockDate, const CBlockIndex *tip);
9293
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
9394
void alertsChanged(const QString &warnings);
9495
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);

src/qt/rpcconsole.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ void RPCConsole::setClientModel(ClientModel *model)
343343
setNumConnections(model->getNumConnections());
344344
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
345345

346-
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate());
347-
connect(model, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(setNumBlocks(int,QDateTime)));
346+
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), NULL);
347+
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,const CBlockIndex*)), this, SLOT(setNumBlocks(int,QDateTime,const CBlockIndex*)));
348348

349349
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
350350
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@@ -525,7 +525,7 @@ void RPCConsole::setNumConnections(int count)
525525
ui->numberOfConnections->setText(connections);
526526
}
527527

528-
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate)
528+
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, const CBlockIndex* tip)
529529
{
530530
ui->numberOfBlocks->setText(QString::number(count));
531531
ui->lastBlockTime->setText(blockDate.toString());

src/qt/rpcconsole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Q_SLOTS:
8383
/** Set number of connections shown in the UI */
8484
void setNumConnections(int count);
8585
/** Set number of blocks and last block date shown in the UI */
86-
void setNumBlocks(int count, const QDateTime& blockDate);
86+
void setNumBlocks(int count, const QDateTime& blockDate, const CBlockIndex* tip);
8787
/** Set size (number of transactions and memory usage) of the mempool in the UI */
8888
void setMempoolSize(long numberOfTxs, size_t dynUsage);
8989
/** Go forward or back in history */

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void SendCoinsDialog::setClientModel(ClientModel *clientModel)
124124
this->clientModel = clientModel;
125125

126126
if (clientModel) {
127-
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(updateSmartFeeLabel()));
127+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,const CBlockIndex*)), this, SLOT(updateSmartFeeLabel()));
128128
}
129129
}
130130

0 commit comments

Comments
 (0)