Skip to content

Commit b4d24e1

Browse files
committed
Report reindexing progress in GUI
1 parent d3d7547 commit b4d24e1

File tree

10 files changed

+82
-19
lines changed

10 files changed

+82
-19
lines changed

qa/rpc-tests/reindex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import *
11+
import time
1112

1213
class ReindexTest(BitcoinTestFramework):
1314

@@ -26,6 +27,8 @@ def reindex(self, justchainstate=False):
2627
stop_node(self.nodes[0], 0)
2728
wait_bitcoinds()
2829
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug", "-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"])
30+
while self.nodes[0].getblockcount() < blockcount:
31+
time.sleep(0.1)
2932
assert_equal(self.nodes[0].getblockcount(), blockcount)
3033
print("Success")
3134

src/main.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,28 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
28832883
return true;
28842884
}
28852885

2886+
static void NotifyHeaderTip() {
2887+
bool fNotify = false;
2888+
bool fInitialBlockDownload = false;
2889+
static CBlockIndex* pindexHeaderOld = NULL;
2890+
CBlockIndex* pindexHeader = NULL;
2891+
{
2892+
LOCK(cs_main);
2893+
if (!setBlockIndexCandidates.empty()) {
2894+
pindexHeader = *setBlockIndexCandidates.rbegin();
2895+
}
2896+
if (pindexHeader != pindexHeaderOld) {
2897+
fNotify = true;
2898+
fInitialBlockDownload = IsInitialBlockDownload();
2899+
pindexHeaderOld = pindexHeader;
2900+
}
2901+
}
2902+
// Send block tip changed notifications without cs_main
2903+
if (fNotify) {
2904+
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
2905+
}
2906+
}
2907+
28862908
/**
28872909
* Make the best chain active, in multiple steps. The result is either failure
28882910
* or an activated best chain. pblock is either NULL or a pointer to a block
@@ -3499,6 +3521,8 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
34993521
return error("%s: AcceptBlock FAILED", __func__);
35003522
}
35013523

3524+
NotifyHeaderTip();
3525+
35023526
if (!ActivateBestChain(state, chainparams, pblock))
35033527
return error("%s: ActivateBestChain failed", __func__);
35043528

@@ -4054,6 +4078,16 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
40544078
LogPrint("reindex", "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
40554079
}
40564080

4081+
// Activate the genesis block so normal node progress can continue
4082+
if (hash == chainparams.GetConsensus().hashGenesisBlock) {
4083+
CValidationState state;
4084+
if (!ActivateBestChain(state, chainparams)) {
4085+
break;
4086+
}
4087+
}
4088+
4089+
NotifyHeaderTip();
4090+
40574091
// Recursively process earlier encountered successors of this block
40584092
deque<uint256> queue;
40594093
queue.push_back(hash);
@@ -4077,6 +4111,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
40774111
}
40784112
range.first++;
40794113
mapBlocksUnknownParent.erase(it);
4114+
NotifyHeaderTip();
40804115
}
40814116
}
40824117
} catch (const std::exception& e) {
@@ -5088,6 +5123,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50885123
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
50895124
}
50905125

5126+
{
50915127
LOCK(cs_main);
50925128

50935129
if (nCount == 0) {
@@ -5171,6 +5207,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51715207
}
51725208

51735209
CheckBlockIndex(chainparams.GetConsensus());
5210+
}
5211+
5212+
NotifyHeaderTip();
51745213
}
51755214

51765215
else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) // Ignore blocks received while importing

src/qt/bitcoingui.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
457457
setNumConnections(clientModel->getNumConnections());
458458
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
459459

460-
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL));
461-
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
460+
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL), false);
461+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
462462

463463
// Receive and report messages from client model
464464
connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
@@ -696,7 +696,7 @@ void BitcoinGUI::setNumConnections(int count)
696696
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
697697
}
698698

699-
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
699+
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
700700
{
701701
if(!clientModel)
702702
return;
@@ -708,15 +708,25 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
708708
enum BlockSource blockSource = clientModel->getBlockSource();
709709
switch (blockSource) {
710710
case BLOCK_SOURCE_NETWORK:
711+
if (header) {
712+
return;
713+
}
711714
progressBarLabel->setText(tr("Synchronizing with network..."));
712715
break;
713716
case BLOCK_SOURCE_DISK:
714-
progressBarLabel->setText(tr("Importing blocks from disk..."));
717+
if (header) {
718+
progressBarLabel->setText(tr("Indexing blocks on disk..."));
719+
} else {
720+
progressBarLabel->setText(tr("Processing blocks on disk..."));
721+
}
715722
break;
716723
case BLOCK_SOURCE_REINDEX:
717724
progressBarLabel->setText(tr("Reindexing blocks on disk..."));
718725
break;
719726
case BLOCK_SOURCE_NONE:
727+
if (header) {
728+
return;
729+
}
720730
// Case: not Importing, not Reindexing and no network connection
721731
progressBarLabel->setText(tr("No block source available..."));
722732
break;

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public Q_SLOTS:
150150
/** Set number of connections shown in the UI */
151151
void setNumConnections(int count);
152152
/** Set number of blocks and last block date shown in the UI */
153-
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress);
153+
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
154154

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

src/qt/clientmodel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
class CBlockIndex;
2525

2626
static const int64_t nClientStartupTime = GetTime();
27+
static int64_t nLastHeaderTipUpdateNotification = 0;
2728
static int64_t nLastBlockTipUpdateNotification = 0;
2829

2930
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
@@ -226,7 +227,7 @@ static void BannedListChanged(ClientModel *clientmodel)
226227
QMetaObject::invokeMethod(clientmodel, "updateBanlist", Qt::QueuedConnection);
227228
}
228229

229-
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex)
230+
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex, bool fHeader)
230231
{
231232
// lock free async UI updates in case we have a new block tip
232233
// during initial sync, only update the UI if the last update
@@ -235,14 +236,17 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
235236
if (initialSync)
236237
now = GetTimeMillis();
237238

239+
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
240+
238241
// if we are in-sync, update the UI regardless of last update time
239-
if (!initialSync || now - nLastBlockTipUpdateNotification > MODEL_UPDATE_DELAY) {
242+
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
240243
//pass a async signal to the UI thread
241244
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
242245
Q_ARG(int, pIndex->nHeight),
243246
Q_ARG(QDateTime, QDateTime::fromTime_t(pIndex->GetBlockTime())),
244-
Q_ARG(double, clientmodel->getVerificationProgress(pIndex)));
245-
nLastBlockTipUpdateNotification = now;
247+
Q_ARG(double, clientmodel->getVerificationProgress(pIndex)),
248+
Q_ARG(bool, fHeader));
249+
nLastUpdateNotification = now;
246250
}
247251
}
248252

@@ -253,7 +257,8 @@ void ClientModel::subscribeToCoreSignals()
253257
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
254258
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this));
255259
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
256-
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2));
260+
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
261+
uiInterface.NotifyHeaderTip.connect(boost::bind(BlockTipChanged, this, _1, _2, true));
257262
}
258263

259264
void ClientModel::unsubscribeFromCoreSignals()
@@ -263,5 +268,6 @@ void ClientModel::unsubscribeFromCoreSignals()
263268
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
264269
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this));
265270
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
266-
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2));
271+
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));
272+
uiInterface.NotifyHeaderTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, true));
267273
}

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, double nVerificationProgress);
92+
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ void RPCConsole::setClientModel(ClientModel *model)
353353
setNumConnections(model->getNumConnections());
354354
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
355355

356-
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL));
357-
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
356+
setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false);
357+
connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
358358

359359
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
360360
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@@ -585,10 +585,12 @@ void RPCConsole::setNumConnections(int count)
585585
ui->numberOfConnections->setText(connections);
586586
}
587587

588-
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
588+
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
589589
{
590-
ui->numberOfBlocks->setText(QString::number(count));
591-
ui->lastBlockTime->setText(blockDate.toString());
590+
if (!headers) {
591+
ui->numberOfBlocks->setText(QString::number(count));
592+
ui->lastBlockTime->setText(blockDate.toString());
593+
}
592594
}
593595

594596
void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)

src/qt/rpcconsole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Q_SLOTS:
8787
/** Set number of connections shown in the UI */
8888
void setNumConnections(int count);
8989
/** Set number of blocks and last block date shown in the UI */
90-
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress);
90+
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
9191
/** Set size (number of transactions and memory usage) of the mempool in the UI */
9292
void setMempoolSize(long numberOfTxs, size_t dynUsage);
9393
/** 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,double)), this, SLOT(updateSmartFeeLabel()));
127+
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(updateSmartFeeLabel()));
128128
}
129129
}
130130

src/ui_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class CClientUIInterface
9696
/** New block has been accepted */
9797
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;
9898

99+
/** Best header has changed */
100+
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyHeaderTip;
101+
99102
/** Banlist did change. */
100103
boost::signals2::signal<void (void)> BannedListChanged;
101104
};

0 commit comments

Comments
 (0)