Skip to content

Commit ebc93a0

Browse files
hebastoryanofsky
andcommitted
refactor: Pass SynchronizationState enum to GUI
Co-authored-by: Russell Yanofsky <[email protected]>
1 parent b5d4fb5 commit ebc93a0

File tree

8 files changed

+33
-16
lines changed

8 files changed

+33
-16
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,9 @@ std::string LicenseInfo()
582582
}
583583

584584
#if HAVE_SYSTEM
585-
static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex)
585+
static void BlockNotifyCallback(SynchronizationState sync_state, const CBlockIndex* pBlockIndex)
586586
{
587-
if (initialSync || !pBlockIndex)
587+
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
588588
return;
589589

590590
std::string strCmd = gArgs.GetArg("-blocknotify", "");

src/interfaces/node.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,16 @@ class NodeImpl : public Node
305305
}
306306
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
307307
{
308-
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) {
309-
fn(initial_download, block->nHeight, block->GetBlockTime(),
308+
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
309+
fn(sync_state, block->nHeight, block->GetBlockTime(),
310310
GuessVerificationProgress(Params().TxData(), block));
311311
}));
312312
}
313313
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
314314
{
315315
return MakeHandler(
316-
::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) {
317-
fn(initial_download, block->nHeight, block->GetBlockTime(),
316+
::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
317+
fn(sync_state, block->nHeight, block->GetBlockTime(),
318318
/* verification progress is unused when a header was received */ 0);
319319
}));
320320
}

src/interfaces/node.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UniValue;
2929
class proxyType;
3030
struct CNodeStateStats;
3131
struct NodeContext;
32+
enum class SynchronizationState;
3233
enum class WalletCreationStatus;
3334

3435
namespace interfaces {
@@ -248,12 +249,12 @@ class Node
248249

249250
//! Register handler for block tip messages.
250251
using NotifyBlockTipFn =
251-
std::function<void(bool initial_download, int height, int64_t block_time, double verification_progress)>;
252+
std::function<void(SynchronizationState, int height, int64_t block_time, double verification_progress)>;
252253
virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
253254

254255
//! Register handler for header tip messages.
255256
using NotifyHeaderTipFn =
256-
std::function<void(bool initial_download, int height, int64_t block_time, double verification_progress)>;
257+
std::function<void(SynchronizationState, int height, int64_t block_time, double verification_progress)>;
257258
virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
258259

259260
//! Return pointer to internal chain interface, useful for testing.

src/qt/clientmodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ static void BannedListChanged(ClientModel *clientmodel)
226226
assert(invoked);
227227
}
228228

229-
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, int height, int64_t blockTime, double verificationProgress, bool fHeader)
229+
static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_state, int height, int64_t blockTime, double verificationProgress, bool fHeader)
230230
{
231+
const bool initialSync = sync_state != SynchronizationState::POST_INIT;
232+
231233
// lock free async UI updates in case we have a new block tip
232234
// during initial sync, only update the UI if the last update
233235
// was > 250ms (MODEL_UPDATE_DELAY) ago

src/ui_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { re
4747
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
4848
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
4949
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
50-
void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(b, i); }
51-
void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); }
50+
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
51+
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(s, i); }
5252
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
5353

5454

src/ui_interface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <string>
1212

1313
class CBlockIndex;
14+
enum class SynchronizationState;
1415
namespace boost {
1516
namespace signals2 {
1617
class connection;
@@ -108,10 +109,10 @@ class CClientUIInterface
108109
ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible);
109110

110111
/** New block has been accepted */
111-
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, bool, const CBlockIndex*);
112+
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex*);
112113

113114
/** Best header has changed */
114-
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, bool, const CBlockIndex*);
115+
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, const CBlockIndex*);
115116

116117
/** Banlist did change. */
117118
ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void);

src/util/system.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ inline bool IsSwitchChar(char c)
107107
#endif
108108
}
109109

110+
enum class SynchronizationState {
111+
INIT_DOWNLOAD,
112+
INIT_REINDEX,
113+
POST_INIT
114+
};
115+
110116
enum class OptionsCategory {
111117
OPTIONS,
112118
CONNECTION,

src/validation.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,13 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27892789
return true;
27902790
}
27912791

2792+
static SynchronizationState GetSynchronizationState(bool init)
2793+
{
2794+
if (!init) return SynchronizationState::POST_INIT;
2795+
if (::fReindex) return SynchronizationState::INIT_REINDEX;
2796+
return SynchronizationState::INIT_DOWNLOAD;
2797+
}
2798+
27922799
static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
27932800
bool fNotify = false;
27942801
bool fInitialBlockDownload = false;
@@ -2806,7 +2813,7 @@ static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
28062813
}
28072814
// Send block tip changed notifications without cs_main
28082815
if (fNotify) {
2809-
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
2816+
uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader);
28102817
}
28112818
return fNotify;
28122819
}
@@ -2895,7 +2902,7 @@ bool CChainState::ActivateBestChain(BlockValidationState &state, const CChainPar
28952902
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
28962903

28972904
// Always notify the UI if a new block tip was connected
2898-
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
2905+
uiInterface.NotifyBlockTip(GetSynchronizationState(fInitialDownload), pindexNewTip);
28992906
}
29002907
}
29012908
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
@@ -3086,7 +3093,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
30863093

30873094
// Only notify about a new block tip if the active chain was modified.
30883095
if (pindex_was_in_chain) {
3089-
uiInterface.NotifyBlockTip(IsInitialBlockDownload(), to_mark_failed->pprev);
3096+
uiInterface.NotifyBlockTip(GetSynchronizationState(IsInitialBlockDownload()), to_mark_failed->pprev);
30903097
}
30913098
return true;
30923099
}

0 commit comments

Comments
 (0)