aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
Diffstat (limited to 'src/node')
-rw-r--r--src/node/chainstatemanager_args.cpp2
-rw-r--r--src/node/kernel_notifications.cpp13
-rw-r--r--src/node/kernel_notifications.h11
3 files changed, 22 insertions, 4 deletions
diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp
index a7f7303348..87d9238c18 100644
--- a/src/node/chainstatemanager_args.cpp
+++ b/src/node/chainstatemanager_args.cpp
@@ -37,8 +37,6 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
- if (auto value{args.GetIntArg("-stopatheight")}) opts.stop_at_height = *value;
-
ReadDatabaseArgs(args, opts.block_tree_db);
ReadDatabaseArgs(args, opts.coins_db);
ReadCoinsViewArgs(args, opts.coins_view);
diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp
index 0be7d51afb..7224127c72 100644
--- a/src/node/kernel_notifications.cpp
+++ b/src/node/kernel_notifications.cpp
@@ -8,6 +8,7 @@
#include <config/bitcoin-config.h>
#endif
+#include <chain.h>
#include <common/args.h>
#include <common/system.h>
#include <kernel/context.h>
@@ -57,9 +58,14 @@ static void DoWarning(const bilingual_str& warning)
namespace node {
-void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
+kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
{
uiInterface.NotifyBlockTip(state, &index);
+ if (m_stop_at_height && index.nHeight >= m_stop_at_height) {
+ StartShutdown();
+ return kernel::Interrupted{};
+ }
+ return {};
}
void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
@@ -87,4 +93,9 @@ void KernelNotifications::fatalError(const std::string& debug_message, const bil
node::AbortNode(m_exit_status, debug_message, user_message, m_shutdown_on_fatal_error);
}
+void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications)
+{
+ if (auto value{args.GetIntArg("-stopatheight")}) notifications.m_stop_at_height = *value;
+}
+
} // namespace node
diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h
index d35b6ecca5..b2dfc03398 100644
--- a/src/node/kernel_notifications.h
+++ b/src/node/kernel_notifications.h
@@ -11,17 +11,21 @@
#include <cstdint>
#include <string>
+class ArgsManager;
class CBlockIndex;
enum class SynchronizationState;
struct bilingual_str;
namespace node {
+
+static constexpr int DEFAULT_STOPATHEIGHT{0};
+
class KernelNotifications : public kernel::Notifications
{
public:
KernelNotifications(std::atomic<int>& exit_status) : m_exit_status{exit_status} {}
- void blockTip(SynchronizationState state, CBlockIndex& index) override;
+ [[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override;
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
@@ -33,11 +37,16 @@ public:
void fatalError(const std::string& debug_message, const bilingual_str& user_message = {}) override;
+ //! Block height after which blockTip notification will return Interrupted{}, if >0.
+ int m_stop_at_height{DEFAULT_STOPATHEIGHT};
//! Useful for tests, can be set to false to avoid shutdown on fatal error.
bool m_shutdown_on_fatal_error{true};
private:
std::atomic<int>& m_exit_status;
};
+
+void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
+
} // namespace node
#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H