Skip to content

Commit 376086f

Browse files
sipasdaftuar
authored andcommitted
Make validation interface capable of signalling header presync
This makes a number of changes: - Get rid of the verification_progress argument in the node interface NotifyHeaderTip (it was always 0.0). - Instead of passing a CBlockIndex* in the UI interface's NotifyHeaderTip, send separate height, timestamp fields. This is becuase in headers presync, no actual CBlockIndex object is available. - Add a bool presync argument to both of the above, to identify signals pertaining to the first headers sync phase.
1 parent 93eae27 commit 376086f

File tree

6 files changed

+8
-9
lines changed

6 files changed

+8
-9
lines changed

src/interfaces/node.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class Node
260260

261261
//! Register handler for header tip messages.
262262
using NotifyHeaderTipFn =
263-
std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
263+
std::function<void(SynchronizationState, interfaces::BlockTip tip, bool presync)>;
264264
virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
265265

266266
//! Get and set internal node context. Useful for testing, but not

src/node/interface_ui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return
5353
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
5454
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
5555
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
56-
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(s, i); }
56+
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
5757
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
5858

5959
bool InitError(const bilingual_str& str)

src/node/interface_ui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class CClientUIInterface
105105
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex*);
106106

107107
/** Best header has changed */
108-
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, const CBlockIndex*);
108+
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, int64_t height, int64_t timestamp, bool presync);
109109

110110
/** Banlist did change. */
111111
ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void);

src/node/interfaces.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,8 @@ class NodeImpl : public Node
377377
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
378378
{
379379
return MakeHandler(
380-
::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
381-
fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
382-
/* verification progress is unused when a header was received */ 0);
380+
::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) {
381+
fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync);
383382
}));
384383
}
385384
NodeContext* context() override { return m_context; }

src/qt/clientmodel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ void ClientModel::subscribeToCoreSignals()
267267
TipChanged(sync_state, tip, verification_progress, /*header=*/false);
268268
});
269269
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(
270-
[this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) {
271-
TipChanged(sync_state, tip, verification_progress, /*header=*/true);
270+
[this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) {
271+
if (!presync) TipChanged(sync_state, tip, /*verification_progress=*/0.0, /*header=*/true);
272272
});
273273
}
274274

src/validation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2944,7 +2944,7 @@ static bool NotifyHeaderTip(CChainState& chainstate) LOCKS_EXCLUDED(cs_main) {
29442944
}
29452945
// Send block tip changed notifications without cs_main
29462946
if (fNotify) {
2947-
uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader);
2947+
uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false);
29482948
}
29492949
return fNotify;
29502950
}

0 commit comments

Comments
 (0)