Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
kernel_notifications.h
Go to the documentation of this file.
1// Copyright (c) 2023-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
6#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
7
9
10#include <sync.h>
11#include <uint256.h>
12
13#include <atomic>
14#include <cstdint>
15#include <functional>
16
17class ArgsManager;
18class CBlockIndex;
19enum class SynchronizationState;
20struct bilingual_str;
21
22namespace kernel {
23enum class Warning;
24} // namespace kernel
25
26namespace node {
27
28class Warnings;
29inline constexpr int DEFAULT_STOPATHEIGHT{0};
30
39 bool chainstate_loaded{false};
40 std::optional<uint256> tip_block;
41};
42
44{
45public:
46 KernelNotifications(const std::function<bool()>& shutdown_request, std::atomic<int>& exit_status, node::Warnings& warnings)
47 : m_shutdown_request(shutdown_request), m_exit_status{exit_status}, m_warnings{warnings} {}
48
49 [[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, const CBlockIndex& index, double verification_progress) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex);
50
51 void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
52
53 void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;
54
55 void warningSet(kernel::Warning id, const bilingual_str& message) override;
56
57 void warningUnset(kernel::Warning id) override;
58
59 void flushError(const bilingual_str& message) override;
60
61 void fatalError(const bilingual_str& message) override;
62
65 if (!chainstate_loaded) m_state = {};
66 m_state.chainstate_loaded = chainstate_loaded;
67 m_tip_block_cv.notify_all();
68 }
69
74
76 std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex);
81 std::optional<uint256> TipBlock() EXCLUSIVE_LOCKS_REQUIRED(m_tip_block_mutex);
82
83private:
84 const std::function<bool()>& m_shutdown_request;
85 std::atomic<int>& m_exit_status;
87};
88
89void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
90
91} // namespace node
92
93#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
int exit_status
ArgsManager & args
Definition bitcoind.cpp:280
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition chain.h:94
KernelNotifications(const std::function< bool()> &shutdown_request, std::atomic< int > &exit_status, node::Warnings &warnings)
A base class defining functions for notifying about certain kernel events.
int m_stop_at_height
Block height after which blockTip notification will return Interrupted{}, if >0.
const std::function< bool()> & m_shutdown_request
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
std::atomic< int > & m_exit_status
void progress(const bilingual_str &title, int progress_percent, bool resume_possible) override
void warningSet(kernel::Warning id, const bilingual_str &message) override
KernelState m_state GUARDED_BY(m_tip_block_mutex)
std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex)
void setChainstateLoaded(bool chainstate_loaded) EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex)
void fatalError(const bilingual_str &message) override
std::optional< uint256 > TipBlock() EXCLUSIVE_LOCKS_REQUIRED(m_tip_block_mutex)
void warningUnset(kernel::Warning id) override
KernelNotifications(const std::function< bool()> &shutdown_request, std::atomic< int > &exit_status, node::Warnings &warnings)
bool m_shutdown_on_fatal_error
Useful for tests, can be set to false to avoid shutdown on fatal error.
void flushError(const bilingual_str &message) override
kernel::InterruptResult blockTip(SynchronizationState state, const CBlockIndex &index, double verification_progress) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex)
Manages warning messages within a node.
Definition warnings.h:40
Warning
Definition warning.h:9
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
void ReadNotificationArgs(const ArgsManager &args, KernelNotifications &notifications)
constexpr int DEFAULT_STOPATHEIGHT
Bilingual messages:
Definition translation.h:24
std::optional< uint256 > tip_block
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition sync.h:131
#define LOCK(cs)
Definition sync.h:268
#define EXCLUSIVE_LOCKS_REQUIRED(...)
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition validation.h:96