Skip to content

Commit 4082e46

Browse files
committed
[Qt] call GuessVerificationProgress synchronous during core signal, pass double over UI signal
1 parent 947d20b commit 4082e46

File tree

8 files changed

+22
-19
lines changed

8 files changed

+22
-19
lines changed

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,9 +2638,8 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
26382638
GetMainSignals().UpdatedBlockTip(pindexNewTip);
26392639
}
26402640
}
2641-
if (!vHashes.empty()) {
2642-
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
2643-
}
2641+
// Always notify the UI if a new block tip was connected
2642+
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
26442643
} while(pindexMostWork != chainActive.Tip());
26452644
CheckBlockIndex(chainparams.GetConsensus());
26462645

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(), NULL);
447-
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,const CBlockIndex*)), this, SLOT(setNumBlocks(int,QDateTime,const CBlockIndex*)));
446+
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL));
447+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
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, const CBlockIndex *tip)
675+
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
676676
{
677677
if(!clientModel)
678678
return;
@@ -749,7 +749,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const CBloc
749749
progressBarLabel->setVisible(true);
750750
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
751751
progressBar->setMaximum(1000000000);
752-
progressBar->setValue(clientModel->getVerificationProgress(tip) * 1000000000.0 + 0.5);
752+
progressBar->setValue(nVerificationProgress * 1000000000.0 + 0.5);
753753
progressBar->setVisible(true);
754754

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

src/qt/bitcoingui.h

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

3433
class CWallet;
3534

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

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

src/qt/clientmodel.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,15 @@ size_t ClientModel::getMempoolDynamicUsage() const
9898
return mempool.DynamicMemoryUsage();
9999
}
100100

101-
double ClientModel::getVerificationProgress(const CBlockIndex *tip) const
101+
double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
102102
{
103-
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), (CBlockIndex *)tip);
103+
CBlockIndex *tip = const_cast<CBlockIndex *>(tipIn);
104+
if (!tip)
105+
{
106+
LOCK(cs_main);
107+
tip = chainActive.Tip();
108+
}
109+
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), tip);
104110
}
105111

106112
void ClientModel::updateTimer()
@@ -247,10 +253,9 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
247253
// if we are in-sync, update the UI regardless of last update time
248254
if (!initialSync || now - nLastBlockTipUpdateNotification > MODEL_UPDATE_DELAY) {
249255
//pass a async signal to the UI thread
250-
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight, QDateTime::fromTime_t(pIndex->GetBlockTime()), pIndex);
256+
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight, QDateTime::fromTime_t(pIndex->GetBlockTime()), clientmodel->getVerificationProgress(pIndex));
251257
nLastBlockTipUpdateNotification = now;
252258
}
253-
254259
}
255260

256261
void ClientModel::subscribeToCoreSignals()

src/qt/clientmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ClientModel : public QObject
8989

9090
Q_SIGNALS:
9191
void numConnectionsChanged(int count);
92-
void numBlocksChanged(int count, const QDateTime& blockDate, const CBlockIndex *tip);
92+
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress);
9393
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
9494
void alertsChanged(const QString &warnings);
9595
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(), NULL);
347-
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,const CBlockIndex*)), this, SLOT(setNumBlocks(int,QDateTime,const CBlockIndex*)));
346+
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL));
347+
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
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, const CBlockIndex* tip)
528+
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
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, const CBlockIndex* tip);
86+
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress);
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,const CBlockIndex*)), this, SLOT(updateSmartFeeLabel()));
127+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(updateSmartFeeLabel()));
128128
}
129129
}
130130

0 commit comments

Comments
 (0)