Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
node
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
8
#include <
kernel/notifications_interface.h
>
9
10
#include <
sync.h
>
11
#include <
threadsafety.h
>
12
#include <
uint256.h
>
13
14
#include <atomic>
15
#include <cstdint>
16
#include <functional>
17
18
class
ArgsManager
;
19
class
CBlockIndex
;
20
enum class
SynchronizationState
;
21
struct
bilingual_str
;
22
23
namespace
kernel
{
24
enum class
Warning
;
25
}
// namespace kernel
26
27
namespace
node
{
28
29
class
Warnings
;
30
static
constexpr
int
DEFAULT_STOPATHEIGHT
{0};
31
39
struct
KernelState
{
40
bool
chainstate_loaded
{
false
};
41
std::optional<uint256>
tip_block
;
42
};
43
44
class
KernelNotifications
:
public
kernel::Notifications
45
{
46
public
:
47
KernelNotifications
(
const
std::function<
bool
()>& shutdown_request, std::atomic<int>&
exit_status
,
node::Warnings
& warnings)
48
:
m_shutdown_request
(shutdown_request),
m_exit_status
{
exit_status
},
m_warnings
{warnings} {}
49
50
[[nodiscard]]
kernel::InterruptResult
blockTip
(
SynchronizationState
state,
const
CBlockIndex
& index,
double
verification_progress)
override
EXCLUSIVE_LOCKS_REQUIRED
(!
m_tip_block_mutex
);
51
52
void
headerTip
(
SynchronizationState
state, int64_t height, int64_t timestamp,
bool
presync)
override
;
53
54
void
progress
(
const
bilingual_str
& title,
int
progress_percent,
bool
resume_possible)
override
;
55
56
void
warningSet
(
kernel::Warning
id
,
const
bilingual_str
& message)
override
;
57
58
void
warningUnset
(
kernel::Warning
id
)
override
;
59
60
void
flushError
(
const
bilingual_str
& message)
override
;
61
62
void
fatalError
(
const
bilingual_str
& message)
override
;
63
64
void
setChainstateLoaded
(
bool
chainstate_loaded)
EXCLUSIVE_LOCKS_REQUIRED
(!
m_tip_block_mutex
) {
65
LOCK
(
m_tip_block_mutex
);
66
if
(!chainstate_loaded) m_state = {};
67
m_state.chainstate_loaded = chainstate_loaded;
68
m_tip_block_cv.notify_all();
69
}
70
72
int
m_stop_at_height
{
DEFAULT_STOPATHEIGHT
};
74
bool
m_shutdown_on_fatal_error
{
true
};
75
76
Mutex
m_tip_block_mutex
;
77
std::condition_variable m_tip_block_cv
GUARDED_BY
(
m_tip_block_mutex
);
78
KernelState
m_state
GUARDED_BY
(
m_tip_block_mutex
);
82
std::optional<uint256>
TipBlock
()
EXCLUSIVE_LOCKS_REQUIRED
(
m_tip_block_mutex
);
83
84
private:
85
const
std
::function<
bool
()>&
m_shutdown_request
;
86
std
::atomic<
int
>&
m_exit_status
;
87
node
::
Warnings
&
m_warnings
;
88
};
89
90
void
ReadNotificationArgs
(const
ArgsManager
&
args
,
KernelNotifications
& notifications);
91
92
}
// namespace node
93
94
#endif
// BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
exit_status
int exit_status
Definition
bitcoin-wallet.cpp:98
args
ArgsManager & args
Definition
bitcoind.cpp:277
ArgsManager
Definition
args.h:103
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition
chain.h:94
KernelNotifications::KernelNotifications
KernelNotifications(const std::function< bool()> &shutdown_request, std::atomic< int > &exit_status, node::Warnings &warnings)
Definition
kernel_notifications.h:47
kernel::Notifications
A base class defining functions for notifying about certain kernel events.
Definition
notifications_interface.h:36
node::KernelNotifications::m_stop_at_height
int m_stop_at_height
Block height after which blockTip notification will return Interrupted{}, if >0.
Definition
kernel_notifications.h:72
node::KernelNotifications::m_tip_block_mutex
Mutex m_tip_block_mutex
Definition
kernel_notifications.h:76
node::KernelNotifications::m_shutdown_request
const std::function< bool()> & m_shutdown_request
Definition
kernel_notifications.h:85
node::KernelNotifications::headerTip
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
Definition
kernel_notifications.cpp:70
node::KernelNotifications::m_exit_status
std::atomic< int > & m_exit_status
Definition
kernel_notifications.h:86
node::KernelNotifications::progress
void progress(const bilingual_str &title, int progress_percent, bool resume_possible) override
Definition
kernel_notifications.cpp:75
node::KernelNotifications::warningSet
void warningSet(kernel::Warning id, const bilingual_str &message) override
Definition
kernel_notifications.cpp:80
node::KernelNotifications::GUARDED_BY
KernelState m_state GUARDED_BY(m_tip_block_mutex)
node::KernelNotifications::GUARDED_BY
std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex)
node::KernelNotifications::setChainstateLoaded
void setChainstateLoaded(bool chainstate_loaded) EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex)
Definition
kernel_notifications.h:64
node::KernelNotifications::m_warnings
node::Warnings & m_warnings
Definition
kernel_notifications.h:87
node::KernelNotifications::fatalError
void fatalError(const bilingual_str &message) override
Definition
kernel_notifications.cpp:97
node::KernelNotifications::TipBlock
std::optional< uint256 > TipBlock() EXCLUSIVE_LOCKS_REQUIRED(m_tip_block_mutex)
Definition
kernel_notifications.cpp:103
node::KernelNotifications::warningUnset
void warningUnset(kernel::Warning id) override
Definition
kernel_notifications.cpp:87
node::KernelNotifications::KernelNotifications
KernelNotifications(const std::function< bool()> &shutdown_request, std::atomic< int > &exit_status, node::Warnings &warnings)
Definition
kernel_notifications.h:47
node::KernelNotifications::m_shutdown_on_fatal_error
bool m_shutdown_on_fatal_error
Useful for tests, can be set to false to avoid shutdown on fatal error.
Definition
kernel_notifications.h:74
node::KernelNotifications::flushError
void flushError(const bilingual_str &message) override
Definition
kernel_notifications.cpp:92
node::KernelNotifications::blockTip
kernel::InterruptResult blockTip(SynchronizationState state, const CBlockIndex &index, double verification_progress) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex)
Definition
kernel_notifications.cpp:51
node::Warnings
Manages warning messages within a node.
Definition
warnings.h:40
kernel
Definition
coinstatsindex.h:21
kernel::Warning
Warning
Definition
warning.h:9
kernel::InterruptResult
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
Definition
notifications_interface.h:23
node
Definition
messages.h:21
node::ReadNotificationArgs
void ReadNotificationArgs(const ArgsManager &args, KernelNotifications ¬ifications)
Definition
kernel_notifications.cpp:110
node::DEFAULT_STOPATHEIGHT
static constexpr int DEFAULT_STOPATHEIGHT
Definition
kernel_notifications.h:30
std
Definition
common.h:29
notifications_interface.h
bilingual_str
Bilingual messages:
Definition
translation.h:24
node::KernelState
Definition
kernel_notifications.h:39
node::KernelState::tip_block
std::optional< uint256 > tip_block
Definition
kernel_notifications.h:41
node::KernelState::chainstate_loaded
bool chainstate_loaded
Definition
kernel_notifications.h:40
sync.h
Mutex
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition
sync.h:123
LOCK
#define LOCK(cs)
Definition
sync.h:258
threadsafety.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:51
uint256.h
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition
validation.h:93
Generated on
for Bitcoin Core by
1.17.0