Skip to content

Commit 1c956ff

Browse files
committed
cpp: Implement snapshot load progress notifications
- Added a new signal for snapshot load progress in the UI interface. - Updated the notifications interface to include a method for reporting snapshot loading progress. - Enhanced the ChainstateManager to report progress during snapshot loading. - Implemented the necessary handler in the kernel notifications to relay progress updates. This change improves user feedback during the snapshot loading process.
1 parent 1bf2d64 commit 1c956ff

File tree

8 files changed

+26
-0
lines changed

8 files changed

+26
-0
lines changed

src/interfaces/node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ class Node
237237
using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
238238
virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
239239

240+
//! Register handler for snapshot load progress.
241+
using SnapshotLoadProgressFn = std::function<void(double progress)>;
242+
virtual std::unique_ptr<Handler> handleSnapshotLoadProgress(SnapshotLoadProgressFn fn) = 0;
243+
240244
//! Register handler for wallet loader constructed messages.
241245
using InitWalletFn = std::function<void()>;
242246
virtual std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) = 0;

src/kernel/notifications_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Notifications
4040
[[nodiscard]] virtual InterruptResult blockTip(SynchronizationState state, CBlockIndex& index, double verification_progress) { return {}; }
4141
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
4242
virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {}
43+
virtual void snapshotLoadProgress(double progress) {}
4344
virtual void warningSet(Warning id, const bilingual_str& message) {}
4445
virtual void warningUnset(Warning id) {}
4546

src/node/interface_ui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct UISignals {
2323
boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
2424
boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
2525
boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
26+
boost::signals2::signal<CClientUIInterface::SnapshotLoadProgressSig> SnapshotLoadProgress;
2627
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
2728
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
2829
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
@@ -46,6 +47,7 @@ ADD_SIGNALS_IMPL_WRAPPER(ShowProgress);
4647
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
4748
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
4849
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
50+
ADD_SIGNALS_IMPL_WRAPPER(SnapshotLoadProgress);
4951

5052
bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style).value_or(false);}
5153
bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style).value_or(false);}
@@ -55,6 +57,7 @@ void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { re
5557
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
5658
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
5759
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
60+
void CClientUIInterface::SnapshotLoadProgress(double progress) { return g_ui_signals.SnapshotLoadProgress(progress); }
5861
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex& block, double verification_progress) { return g_ui_signals.NotifyBlockTip(s, block, verification_progress); }
5962
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
6063
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }

src/node/interface_ui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class CClientUIInterface
102102
*/
103103
ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible);
104104

105+
/** Snapshot load progress. */
106+
ADD_SIGNALS_DECL_WRAPPER(SnapshotLoadProgress, void, double progress);
107+
105108
/** New block has been accepted */
106109
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex& block, double verification_progress);
107110

src/node/interfaces.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ class NodeImpl : public Node
391391
{
392392
return MakeSignalHandler(::uiInterface.ShowProgress_connect(fn));
393393
}
394+
std::unique_ptr<Handler> handleSnapshotLoadProgress(SnapshotLoadProgressFn fn) override
395+
{
396+
return MakeSignalHandler(::uiInterface.SnapshotLoadProgress_connect(fn));
397+
}
394398
std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
395399
{
396400
return MakeSignalHandler(::uiInterface.InitWallet_connect(fn));

src/node/kernel_notifications.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ void KernelNotifications::progress(const bilingual_str& title, int progress_perc
7777
uiInterface.ShowProgress(title.translated, progress_percent, resume_possible);
7878
}
7979

80+
void KernelNotifications::snapshotLoadProgress(double progress)
81+
{
82+
uiInterface.SnapshotLoadProgress(progress);
83+
}
84+
8085
void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message)
8186
{
8287
if (m_warnings.Set(id, message)) {

src/node/kernel_notifications.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class KernelNotifications : public kernel::Notifications
4141

4242
void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;
4343

44+
void snapshotLoadProgress(double progress) override;
45+
4446
void warningSet(kernel::Warning id, const bilingual_str& message) override;
4547

4648
void warningUnset(kernel::Warning id) override;

src/validation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5980,6 +5980,10 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59805980
--coins_left;
59815981
++coins_processed;
59825982

5983+
// Show Snapshot Loading progress
5984+
double progress = static_cast<double>(coins_processed) / static_cast<double>(coins_count);
5985+
GetNotifications().snapshotLoadProgress(progress);
5986+
59835987
if (coins_processed % 1000000 == 0) {
59845988
LogInfo("[snapshot] %d coins loaded (%.2f%%, %.2f MB)",
59855989
coins_processed,

0 commit comments

Comments
 (0)