Skip to content

Commit d7523cd

Browse files
committed
cpp: Introduce Rewind Progress handler and nofifier
This introduces a Rewind Progress notification so that it is available when generating an AssumeUTXO snapshot through the UI.
1 parent b720cde commit d7523cd

18 files changed

+815
-11
lines changed

src/Makefile.qt.include

+2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ QML_RES_QML = \
406406
qml/components/NetworkIndicator.qml \
407407
qml/components/ProxySettings.qml \
408408
qml/components/Separator.qml \
409+
qml/components/SnapshotGenSettings.qml \
409410
qml/components/SnapshotSettings.qml \
410411
qml/components/StorageLocations.qml \
411412
qml/components/StorageOptions.qml \
@@ -465,6 +466,7 @@ QML_RES_QML = \
465466
qml/pages/settings/SettingsDisplay.qml \
466467
qml/pages/settings/SettingsProxy.qml \
467468
qml/pages/settings/SettingsSnapshot.qml \
469+
qml/pages/settings/SettingsSnapshotGen.qml \
468470
qml/pages/settings/SettingsStorage.qml \
469471
qml/pages/settings/SettingsTheme.qml \
470472
qml/pages/wallet/Activity.qml \

src/interfaces/node.h

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ class Node
251251
using SnapshotLoadProgressFn = std::function<void(double progress)>;
252252
virtual std::unique_ptr<Handler> handleSnapshotLoadProgress(SnapshotLoadProgressFn fn) = 0;
253253

254+
//! Register handler for rewind progress messages.
255+
using RewindProgressFn = std::function<void(double progress)>;
256+
virtual std::unique_ptr<Handler> handleRewindProgress(RewindProgressFn fn) = 0;
257+
254258
//! Register handler for wallet loader constructed messages.
255259
using InitWalletFn = std::function<void()>;
256260
virtual std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) = 0;

src/kernel/notifications_interface.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class Notifications
3939

4040
[[nodiscard]] virtual InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) { return {}; }
4141
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
42+
virtual void blockTipDisconnected(SynchronizationState state, CBlockIndex& index) {}
4243
virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {}
4344
virtual void snapshotLoadProgress(double progress) {}
45+
virtual void rewindProgress(double progress) {}
4446
virtual void warning(const bilingual_str& warning) {}
4547

4648
//! The flush error notification is sent to notify the user that an error

src/node/interface_ui.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ struct UISignals {
2222
boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
2323
boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
2424
boost::signals2::signal<CClientUIInterface::SnapshotLoadProgressSig> SnapshotLoadProgress;
25+
boost::signals2::signal<CClientUIInterface::RewindProgressSig> RewindProgress;
2526
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
2627
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
28+
boost::signals2::signal<CClientUIInterface::NotifyBlockDisconnectedSig> NotifyBlockDisconnected;
2729
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
2830
};
2931
static UISignals g_ui_signals;
@@ -44,9 +46,10 @@ ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
4446
ADD_SIGNALS_IMPL_WRAPPER(ShowProgress);
4547
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
4648
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
49+
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockDisconnected);
4750
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
4851
ADD_SIGNALS_IMPL_WRAPPER(SnapshotLoadProgress);
49-
52+
ADD_SIGNALS_IMPL_WRAPPER(RewindProgress);
5053
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);}
5154
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);}
5255
void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
@@ -56,8 +59,10 @@ void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return
5659
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
5760
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
5861
void CClientUIInterface::SnapshotLoadProgress(double progress) { return g_ui_signals.SnapshotLoadProgress(progress); }
62+
void CClientUIInterface::RewindProgress(double progress) { return g_ui_signals.RewindProgress(progress); }
5963
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
6064
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
65+
void CClientUIInterface::NotifyBlockDisconnected(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockDisconnected(s, i); }
6166
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
6267

6368
bool InitError(const bilingual_str& str)

src/node/interface_ui.h

+6
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,18 @@ class CClientUIInterface
112112
/** Snapshot load progress. */
113113
ADD_SIGNALS_DECL_WRAPPER(SnapshotLoadProgress, void, double progress);
114114

115+
/** Rewind progress. */
116+
ADD_SIGNALS_DECL_WRAPPER(RewindProgress, void, double progress);
117+
115118
/** New block has been accepted */
116119
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState, const CBlockIndex*);
117120

118121
/** Best header has changed */
119122
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState, int64_t height, int64_t timestamp, bool presync);
120123

124+
/** Block disconnected */
125+
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockDisconnected, void, SynchronizationState, const CBlockIndex*);
126+
121127
/** Banlist did change. */
122128
ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void);
123129
};

src/node/interfaces.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ class NodeImpl : public Node
383383
{
384384
return MakeSignalHandler(::uiInterface.SnapshotLoadProgress_connect(fn));
385385
}
386+
std::unique_ptr<Handler> handleRewindProgress(RewindProgressFn fn) override
387+
{
388+
return MakeSignalHandler(::uiInterface.RewindProgress_connect(fn));
389+
}
386390
std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
387391
{
388392
return MakeSignalHandler(::uiInterface.InitWallet_connect(fn));

src/node/kernel_notifications.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void KernelNotifications::snapshotLoadProgress(double progress)
8383
uiInterface.SnapshotLoadProgress(progress);
8484
}
8585

86+
void KernelNotifications::rewindProgress(double progress)
87+
{
88+
uiInterface.RewindProgress(progress);
89+
}
90+
8691
void KernelNotifications::warning(const bilingual_str& warning)
8792
{
8893
DoWarning(warning);

src/node/kernel_notifications.h

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class KernelNotifications : public kernel::Notifications
3333

3434
void snapshotLoadProgress(double progress) override;
3535

36+
void rewindProgress(double progress) override;
37+
3638
void warning(const bilingual_str& warning) override;
3739

3840
void flushError(const std::string& debug_message) override;

src/qml/bitcoin_qml.qrc

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<file>components/ProxySettings.qml</file>
1616
<file>components/StorageLocations.qml</file>
1717
<file>components/Separator.qml</file>
18+
<file>components/SnapshotGenSettings.qml</file>
1819
<file>components/SnapshotSettings.qml</file>
1920
<file>components/StorageOptions.qml</file>
2021
<file>components/StorageSettings.qml</file>
@@ -72,6 +73,7 @@
7273
<file>pages/settings/SettingsDeveloper.qml</file>
7374
<file>pages/settings/SettingsDisplay.qml</file>
7475
<file>pages/settings/SettingsProxy.qml</file>
76+
<file>pages/settings/SettingsSnapshotGen.qml</file>
7577
<file>pages/settings/SettingsSnapshot.qml</file>
7678
<file>pages/settings/SettingsStorage.qml</file>
7779
<file>pages/settings/SettingsTheme.qml</file>

src/qml/components/ConnectionSettings.qml

+33-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,43 @@ ColumnLayout {
1111
id: root
1212
signal next
1313
signal gotoSnapshot
14+
signal gotoGenerateSnapshot
1415
property bool snapshotImportCompleted: onboarding ? false : chainModel.isSnapshotActive
1516
property bool onboarding: false
16-
17+
property bool generateSnapshot: false
18+
property bool isSnapshotGenerated: nodeModel.isSnapshotGenerated
19+
property bool isIBDCompleted: nodeModel.isIBDCompleted
1720
spacing: 4
21+
Setting {
22+
id: gotoGenerateSnapshot
23+
visible: !root.onboarding && (root.snapshotImportCompleted || root.isIBDCompleted)
24+
Layout.fillWidth: true
25+
header: qsTr("Generate snapshot")
26+
description: qsTr("Speed up the setup of other nodes")
27+
actionItem: Item {
28+
width: 26
29+
height: 26
30+
CaretRightIcon {
31+
anchors.centerIn: parent
32+
color: gotoGenerateSnapshot.stateColor
33+
}
34+
}
35+
onClicked: {
36+
if (!nodeModel.isSnapshotFileExists()) {
37+
root.generateSnapshot = true
38+
root.gotoGenerateSnapshot()
39+
} else {
40+
root.gotoGenerateSnapshot()
41+
}
42+
}
43+
}
44+
Separator {
45+
visible: !root.onboarding && (root.snapshotImportCompleted || root.isIBDCompleted)
46+
Layout.fillWidth: true
47+
}
1848
Setting {
1949
id: gotoSnapshot
20-
visible: !root.onboarding
50+
visible: !root.onboarding && !snapshotImportCompleted && !root.isIBDCompleted
2151
Layout.fillWidth: true
2252
header: qsTr("Load snapshot")
2353
description: qsTr("Instant use with background sync")
@@ -39,7 +69,7 @@ ColumnLayout {
3969
onClicked: root.gotoSnapshot()
4070
}
4171
Separator {
42-
visible: !root.onboarding
72+
visible: !root.onboarding && !snapshotImportCompleted && !root.isIBDCompleted
4373
Layout.fillWidth: true
4474
}
4575
Setting {

0 commit comments

Comments
 (0)