Skip to content

Commit 3add234

Browse files
sipasdaftuar
authored andcommitted
ui: show header pre-synchronization progress
1 parent 738421c commit 3add234

11 files changed

+59
-31
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
7575
Q_DECLARE_METATYPE(bool*)
7676
Q_DECLARE_METATYPE(CAmount)
7777
Q_DECLARE_METATYPE(SynchronizationState)
78+
Q_DECLARE_METATYPE(SyncType)
7879
Q_DECLARE_METATYPE(uint256)
7980

8081
static void RegisterMetaTypes()
8182
{
8283
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection
8384
qRegisterMetaType<bool*>();
8485
qRegisterMetaType<SynchronizationState>();
86+
qRegisterMetaType<SyncType>();
8587
#ifdef ENABLE_WALLET
8688
qRegisterMetaType<WalletModel*>();
8789
#endif

src/qt/bitcoingui.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
615615
connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections);
616616
connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);
617617

618-
modalOverlay->setKnownBestHeight(tip_info->header_height, QDateTime::fromSecsSinceEpoch(tip_info->header_time));
619-
setNumBlocks(tip_info->block_height, QDateTime::fromSecsSinceEpoch(tip_info->block_time), tip_info->verification_progress, false, SynchronizationState::INIT_DOWNLOAD);
618+
modalOverlay->setKnownBestHeight(tip_info->header_height, QDateTime::fromSecsSinceEpoch(tip_info->header_time), /*presync=*/false);
619+
setNumBlocks(tip_info->block_height, QDateTime::fromSecsSinceEpoch(tip_info->block_time), tip_info->verification_progress, SyncType::BLOCK_SYNC, SynchronizationState::INIT_DOWNLOAD);
620620
connect(_clientModel, &ClientModel::numBlocksChanged, this, &BitcoinGUI::setNumBlocks);
621621

622622
// Receive and report messages from client model
@@ -1026,6 +1026,13 @@ void BitcoinGUI::updateHeadersSyncProgressLabel()
10261026
progressBarLabel->setText(tr("Syncing Headers (%1%)…").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
10271027
}
10281028

1029+
void BitcoinGUI::updateHeadersPresyncProgressLabel(int64_t height, const QDateTime& blockDate)
1030+
{
1031+
int estHeadersLeft = blockDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing;
1032+
if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
1033+
progressBarLabel->setText(tr("Pre-syncing Headers (%1%)…").arg(QString::number(100.0 / (height+estHeadersLeft)*height, 'f', 1)));
1034+
}
1035+
10291036
void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
10301037
{
10311038
if (!clientModel || !clientModel->getOptionsModel())
@@ -1039,7 +1046,7 @@ void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
10391046
GUIUtil::ShowModalDialogAsynchronously(dlg);
10401047
}
10411048

1042-
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
1049+
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
10431050
{
10441051
// Disabling macOS App Nap on initial sync, disk and reindex operations.
10451052
#ifdef Q_OS_MACOS
@@ -1052,8 +1059,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
10521059

10531060
if (modalOverlay)
10541061
{
1055-
if (header)
1056-
modalOverlay->setKnownBestHeight(count, blockDate);
1062+
if (synctype != SyncType::BLOCK_SYNC)
1063+
modalOverlay->setKnownBestHeight(count, blockDate, synctype == SyncType::HEADER_PRESYNC);
10571064
else
10581065
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
10591066
}
@@ -1067,15 +1074,18 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
10671074
enum BlockSource blockSource = clientModel->getBlockSource();
10681075
switch (blockSource) {
10691076
case BlockSource::NETWORK:
1070-
if (header) {
1077+
if (synctype == SyncType::HEADER_PRESYNC) {
1078+
updateHeadersPresyncProgressLabel(count, blockDate);
1079+
return;
1080+
} else if (synctype == SyncType::HEADER_SYNC) {
10711081
updateHeadersSyncProgressLabel();
10721082
return;
10731083
}
10741084
progressBarLabel->setText(tr("Synchronizing with network…"));
10751085
updateHeadersSyncProgressLabel();
10761086
break;
10771087
case BlockSource::DISK:
1078-
if (header) {
1088+
if (synctype != SyncType::BLOCK_SYNC) {
10791089
progressBarLabel->setText(tr("Indexing blocks on disk…"));
10801090
} else {
10811091
progressBarLabel->setText(tr("Processing blocks on disk…"));
@@ -1085,7 +1095,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
10851095
progressBarLabel->setText(tr("Reindexing blocks on disk…"));
10861096
break;
10871097
case BlockSource::NONE:
1088-
if (header) {
1098+
if (synctype != SyncType::BLOCK_SYNC) {
10891099
return;
10901100
}
10911101
progressBarLabel->setText(tr("Connecting to peers…"));

src/qt/bitcoingui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111

1212
#include <qt/bitcoinunits.h>
13+
#include <qt/clientmodel.h>
1314
#include <qt/guiutil.h>
1415
#include <qt/optionsdialog.h>
1516

@@ -28,7 +29,6 @@
2829

2930
#include <memory>
3031

31-
class ClientModel;
3232
class NetworkStyle;
3333
class Notificator;
3434
class OptionsModel;
@@ -208,6 +208,7 @@ class BitcoinGUI : public QMainWindow
208208
void updateNetworkState();
209209

210210
void updateHeadersSyncProgressLabel();
211+
void updateHeadersPresyncProgressLabel(int64_t height, const QDateTime& blockDate);
211212

212213
/** Open the OptionsDialog on the specified tab index */
213214
void openOptionsDialogWithTab(OptionsDialog::Tab tab);
@@ -226,7 +227,7 @@ public Q_SLOTS:
226227
/** Set network state shown in the UI */
227228
void setNetworkActive(bool network_active);
228229
/** Set number of blocks and last block date shown in the UI */
229-
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state);
230+
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state);
230231

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

src/qt/clientmodel.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,26 @@ QString ClientModel::blocksDir() const
215215
return GUIUtil::PathToQString(gArgs.GetBlocksDirPath());
216216
}
217217

218-
void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, bool header)
218+
void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype)
219219
{
220-
if (header) {
220+
if (synctype == SyncType::HEADER_SYNC) {
221221
// cache best headers time and height to reduce future cs_main locks
222222
cachedBestHeaderHeight = tip.block_height;
223223
cachedBestHeaderTime = tip.block_time;
224-
} else {
224+
} else if (synctype == SyncType::BLOCK_SYNC) {
225225
m_cached_num_blocks = tip.block_height;
226226
WITH_LOCK(m_cached_tip_mutex, m_cached_tip_blocks = tip.block_hash;);
227227
}
228228

229229
// Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex.
230-
const bool throttle = (sync_state != SynchronizationState::POST_INIT && !header) || sync_state == SynchronizationState::INIT_REINDEX;
230+
const bool throttle = (sync_state != SynchronizationState::POST_INIT && synctype == SyncType::BLOCK_SYNC) || sync_state == SynchronizationState::INIT_REINDEX;
231231
const int64_t now = throttle ? GetTimeMillis() : 0;
232-
int64_t& nLastUpdateNotification = header ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
232+
int64_t& nLastUpdateNotification = synctype != SyncType::BLOCK_SYNC ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
233233
if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) {
234234
return;
235235
}
236236

237-
Q_EMIT numBlocksChanged(tip.block_height, QDateTime::fromSecsSinceEpoch(tip.block_time), verification_progress, header, sync_state);
237+
Q_EMIT numBlocksChanged(tip.block_height, QDateTime::fromSecsSinceEpoch(tip.block_time), verification_progress, synctype, sync_state);
238238
nLastUpdateNotification = now;
239239
}
240240

@@ -264,11 +264,11 @@ void ClientModel::subscribeToCoreSignals()
264264
});
265265
m_handler_notify_block_tip = m_node.handleNotifyBlockTip(
266266
[this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) {
267-
TipChanged(sync_state, tip, verification_progress, /*header=*/false);
267+
TipChanged(sync_state, tip, verification_progress, SyncType::BLOCK_SYNC);
268268
});
269269
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(
270270
[this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) {
271-
if (!presync) TipChanged(sync_state, tip, /*verification_progress=*/0.0, /*header=*/true);
271+
TipChanged(sync_state, tip, /*verification_progress=*/0.0, presync ? SyncType::HEADER_PRESYNC : SyncType::HEADER_SYNC);
272272
});
273273
}
274274

src/qt/clientmodel.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ enum class BlockSource {
3737
NETWORK
3838
};
3939

40+
enum class SyncType {
41+
HEADER_PRESYNC,
42+
HEADER_SYNC,
43+
BLOCK_SYNC
44+
};
45+
4046
enum NumConnections {
4147
CONNECTIONS_NONE = 0,
4248
CONNECTIONS_IN = (1U << 0),
@@ -105,13 +111,13 @@ class ClientModel : public QObject
105111
//! A thread to interact with m_node asynchronously
106112
QThread* const m_thread;
107113

108-
void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, bool header) EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
114+
void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype) EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
109115
void subscribeToCoreSignals();
110116
void unsubscribeFromCoreSignals();
111117

112118
Q_SIGNALS:
113119
void numConnectionsChanged(int count);
114-
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state);
120+
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state);
115121
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
116122
void networkActiveChanged(bool networkActive);
117123
void alertsChanged(const QString &warnings);

src/qt/modaloverlay.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ bool ModalOverlay::event(QEvent* ev) {
7878
return QWidget::event(ev);
7979
}
8080

81-
void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate)
81+
void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate, bool presync)
8282
{
83-
if (count > bestHeaderHeight) {
83+
if (!presync && count > bestHeaderHeight) {
8484
bestHeaderHeight = count;
8585
bestHeaderDate = blockDate;
8686
UpdateHeaderSyncLabel();
8787
}
88+
if (presync) {
89+
UpdateHeaderPresyncLabel(count, blockDate);
90+
}
8891
}
8992

9093
void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress)
@@ -158,6 +161,11 @@ void ModalOverlay::UpdateHeaderSyncLabel() {
158161
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1, %2%)…").arg(bestHeaderHeight).arg(QString::number(100.0 / (bestHeaderHeight + est_headers_left) * bestHeaderHeight, 'f', 1)));
159162
}
160163

164+
void ModalOverlay::UpdateHeaderPresyncLabel(int height, const QDateTime& blockDate) {
165+
int est_headers_left = blockDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing;
166+
ui->numberOfBlocksLeft->setText(tr("Unknown. Pre-syncing Headers (%1, %2%)…").arg(height).arg(QString::number(100.0 / (height + est_headers_left) * height, 'f', 1)));
167+
}
168+
161169
void ModalOverlay::toggleVisibility()
162170
{
163171
showHide(layerIsVisible, true);

src/qt/modaloverlay.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ModalOverlay : public QWidget
2626
~ModalOverlay();
2727

2828
void tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress);
29-
void setKnownBestHeight(int count, const QDateTime& blockDate);
29+
void setKnownBestHeight(int count, const QDateTime& blockDate, bool presync);
3030

3131
// will show or hide the modal layer
3232
void showHide(bool hide = false, bool userRequested = false);
@@ -52,6 +52,7 @@ public Q_SLOTS:
5252
bool userClosed;
5353
QPropertyAnimation m_animation;
5454
void UpdateHeaderSyncLabel();
55+
void UpdateHeaderPresyncLabel(int height, const QDateTime& blockDate);
5556
};
5657

5758
#endif // BITCOIN_QT_MODALOVERLAY_H

src/qt/rpcconsole.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
661661
setNumConnections(model->getNumConnections());
662662
connect(model, &ClientModel::numConnectionsChanged, this, &RPCConsole::setNumConnections);
663663

664-
setNumBlocks(bestblock_height, QDateTime::fromSecsSinceEpoch(bestblock_date), verification_progress, false);
664+
setNumBlocks(bestblock_height, QDateTime::fromSecsSinceEpoch(bestblock_date), verification_progress, SyncType::BLOCK_SYNC);
665665
connect(model, &ClientModel::numBlocksChanged, this, &RPCConsole::setNumBlocks);
666666

667667
updateNetworkState();
@@ -973,9 +973,9 @@ void RPCConsole::setNetworkActive(bool networkActive)
973973
updateNetworkState();
974974
}
975975

976-
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
976+
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype)
977977
{
978-
if (!headers) {
978+
if (synctype == SyncType::BLOCK_SYNC) {
979979
ui->numberOfBlocks->setText(QString::number(count));
980980
ui->lastBlockTime->setText(blockDate.toString());
981981
}

src/qt/rpcconsole.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <config/bitcoin-config.h>
1010
#endif
1111

12+
#include <qt/clientmodel.h>
1213
#include <qt/guiutil.h>
1314
#include <qt/peertablemodel.h>
1415

@@ -19,7 +20,6 @@
1920
#include <QThread>
2021
#include <QWidget>
2122

22-
class ClientModel;
2323
class PlatformStyle;
2424
class RPCExecutor;
2525
class RPCTimerInterface;
@@ -121,7 +121,7 @@ public Q_SLOTS:
121121
/** Set network state shown in the UI */
122122
void setNetworkActive(bool networkActive);
123123
/** Set number of blocks and last block date shown in the UI */
124-
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
124+
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype);
125125
/** Set size (number of transactions and memory usage) of the mempool in the UI */
126126
void setMempoolSize(long numberOfTxs, size_t dynUsage);
127127
/** Go forward or back in history */

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void SendCoinsDialog::updateCoinControlState()
839839
m_coin_control->fAllowWatchOnly = model->wallet().privateKeysDisabled() && !model->wallet().hasExternalSigner();
840840
}
841841

842-
void SendCoinsDialog::updateNumberOfBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state) {
842+
void SendCoinsDialog::updateNumberOfBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state) {
843843
if (sync_state == SynchronizationState::POST_INIT) {
844844
updateSmartFeeLabel();
845845
}

0 commit comments

Comments
 (0)