2023-05-10 22:29:17 +02:00
|
|
|
// Copyright (c) 2023 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
|
|
|
|
#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
|
|
|
|
|
|
|
|
#include <kernel/notifications_interface.h>
|
|
|
|
|
2024-08-26 18:16:08 +02:00
|
|
|
#include <sync.h>
|
|
|
|
#include <threadsafety.h>
|
|
|
|
#include <uint256.h>
|
|
|
|
|
2023-05-09 11:15:46 +02:00
|
|
|
#include <atomic>
|
2023-05-10 22:35:49 +02:00
|
|
|
#include <cstdint>
|
2024-09-25 10:45:34 +02:00
|
|
|
#include <functional>
|
2023-05-10 22:35:49 +02:00
|
|
|
|
2023-07-07 12:53:31 -04:00
|
|
|
class ArgsManager;
|
2023-05-10 22:29:17 +02:00
|
|
|
class CBlockIndex;
|
|
|
|
enum class SynchronizationState;
|
2023-05-10 22:36:04 +02:00
|
|
|
struct bilingual_str;
|
2023-05-10 22:29:17 +02:00
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
namespace kernel {
|
|
|
|
enum class Warning;
|
|
|
|
} // namespace kernel
|
|
|
|
|
2023-05-10 22:29:17 +02:00
|
|
|
namespace node {
|
2023-07-07 12:53:31 -04:00
|
|
|
|
2024-05-07 14:21:35 +01:00
|
|
|
class Warnings;
|
2023-07-07 12:53:31 -04:00
|
|
|
static constexpr int DEFAULT_STOPATHEIGHT{0};
|
|
|
|
|
2023-05-10 22:29:17 +02:00
|
|
|
class KernelNotifications : public kernel::Notifications
|
|
|
|
{
|
|
|
|
public:
|
2024-09-25 10:45:34 +02:00
|
|
|
KernelNotifications(const std::function<bool()>& shutdown_request, std::atomic<int>& exit_status, node::Warnings& warnings)
|
|
|
|
: m_shutdown_request(shutdown_request), m_exit_status{exit_status}, m_warnings{warnings} {}
|
2023-05-09 11:15:46 +02:00
|
|
|
|
2024-08-26 18:16:08 +02:00
|
|
|
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex);
|
2023-05-10 22:35:49 +02:00
|
|
|
|
|
|
|
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
|
2023-05-10 22:36:04 +02:00
|
|
|
|
|
|
|
void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;
|
2023-05-08 14:49:37 +02:00
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
void warningSet(kernel::Warning id, const bilingual_str& message) override;
|
|
|
|
|
|
|
|
void warningUnset(kernel::Warning id) override;
|
2023-06-15 23:09:37 +02:00
|
|
|
|
2024-03-15 21:42:44 +01:00
|
|
|
void flushError(const bilingual_str& message) override;
|
2023-05-09 11:15:46 +02:00
|
|
|
|
2024-03-15 21:42:44 +01:00
|
|
|
void fatalError(const bilingual_str& message) override;
|
2023-05-09 11:15:46 +02:00
|
|
|
|
2023-07-07 12:53:31 -04:00
|
|
|
//! Block height after which blockTip notification will return Interrupted{}, if >0.
|
|
|
|
int m_stop_at_height{DEFAULT_STOPATHEIGHT};
|
2023-05-09 11:15:46 +02:00
|
|
|
//! Useful for tests, can be set to false to avoid shutdown on fatal error.
|
|
|
|
bool m_shutdown_on_fatal_error{true};
|
2024-08-26 18:16:08 +02:00
|
|
|
|
|
|
|
Mutex m_tip_block_mutex;
|
2024-09-30 11:53:05 +02:00
|
|
|
std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex);
|
2024-12-06 14:24:21 +07:00
|
|
|
//! The block for which the last blockTip notification was received.
|
|
|
|
//! It's first set when the tip is connected during node initialization.
|
|
|
|
//! Might be unset during an early shutdown.
|
2024-12-17 10:18:36 +07:00
|
|
|
std::optional<uint256> m_tip_block GUARDED_BY(m_tip_block_mutex);
|
2024-08-26 18:16:08 +02:00
|
|
|
|
2023-05-09 11:15:46 +02:00
|
|
|
private:
|
2024-09-25 10:45:34 +02:00
|
|
|
const std::function<bool()>& m_shutdown_request;
|
2023-05-09 11:15:46 +02:00
|
|
|
std::atomic<int>& m_exit_status;
|
2024-05-07 14:21:35 +01:00
|
|
|
node::Warnings& m_warnings;
|
2023-05-10 22:29:17 +02:00
|
|
|
};
|
2023-07-07 12:53:31 -04:00
|
|
|
|
|
|
|
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
|
|
|
|
|
2023-05-10 22:29:17 +02:00
|
|
|
} // namespace node
|
|
|
|
|
|
|
|
#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
|