Bitcoin Core 28.99.0
P2P Digital Currency
kernel_notifications.h
Go to the documentation of this file.
1// Copyright (c) 2023 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 <threadsafety.h>
12#include <uint256.h>
13
14#include <atomic>
15#include <cstdint>
16#include <functional>
17
18class ArgsManager;
19class CBlockIndex;
20enum class SynchronizationState;
21struct bilingual_str;
22
23namespace kernel {
24enum class Warning;
25} // namespace kernel
26
27namespace node {
28
29class Warnings;
30static constexpr int DEFAULT_STOPATHEIGHT{0};
31
33{
34public:
35 KernelNotifications(const std::function<bool()>& shutdown_request, std::atomic<int>& exit_status, node::Warnings& warnings)
36 : m_shutdown_request(shutdown_request), m_exit_status{exit_status}, m_warnings{warnings} {}
37
39
40 void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
41
42 void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;
43
44 void warningSet(kernel::Warning id, const bilingual_str& message) override;
45
46 void warningUnset(kernel::Warning id) override;
47
48 void flushError(const bilingual_str& message) override;
49
50 void fatalError(const bilingual_str& message) override;
51
56
58 std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex);
63
64private:
65 const std::function<bool()>& m_shutdown_request;
66 std::atomic<int>& m_exit_status;
68};
69
70void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
71
72} // namespace node
73
74#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
int exit_status
ArgsManager & args
Definition: bitcoind.cpp:277
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:141
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.
kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex &index) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex)
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
uint256 m_tip_block GUARDED_BY(m_tip_block_mutex)
The block for which the last blockTip notification was received.
std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex)
void fatalError(const bilingual_str &message) override
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
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
The flush error notification is sent to notify the user that an error occurred while flushing block d...
Manages warning messages within a node.
Definition: warnings.h:40
256-bit opaque blob.
Definition: uint256.h:190
static const uint256 ZERO
Definition: uint256.h:198
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
Warning
Definition: warning.h:9
Definition: messages.h:20
void ReadNotificationArgs(const ArgsManager &args, KernelNotifications &notifications)
static constexpr int DEFAULT_STOPATHEIGHT
Bilingual messages:
Definition: translation.h:21
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:85