Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_NODE_KERNEL_NOTIFICATIONS_H6#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H8#include <kernel/notifications_interface.h>10#include <sync.h>11#include <uint256.h>13#include <atomic>14#include <cstdint>15#include <functional>17class ArgsManager;18class CBlockIndex;19enum class SynchronizationState;20struct bilingual_str;22namespace kernel {23enum class Warning;24} // namespace kernel26namespace node {28class Warnings;29inline constexpr int DEFAULT_STOPATHEIGHT{0};31//! State tracked by the KernelNotifications interface meant to be used by32//! mining code, index code, RPCs, and other code sitting above the validation33//! layer.34//!35//! Currently just tracks the chain tip, but could be used to hold other36//! information in the future, like the last flushed block, pruning37//! information, etc.38struct KernelState {39bool chainstate_loaded{false};40std::optional<uint256> tip_block;41};43class KernelNotifications : public kernel::Notifications44{45public:46KernelNotifications(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} {}49[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, const CBlockIndex& index, double verification_progress) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex);51void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;53void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;55void warningSet(kernel::Warning id, const bilingual_str& message) override;57void warningUnset(kernel::Warning id) override;59void flushError(const bilingual_str& message) override;61void fatalError(const bilingual_str& message) override;63void setChainstateLoaded(bool chainstate_loaded) EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex) {64LOCK(m_tip_block_mutex);65if (!chainstate_loaded) m_state = {};66m_state.chainstate_loaded = chainstate_loaded;67m_tip_block_cv.notify_all();68}70//! Block height after which blockTip notification will return Interrupted{}, if >0.71int m_stop_at_height{DEFAULT_STOPATHEIGHT};72//! Useful for tests, can be set to false to avoid shutdown on fatal error.73bool m_shutdown_on_fatal_error{true};75Mutex m_tip_block_mutex;76std::condition_variable m_tip_block_cv GUARDED_BY(m_tip_block_mutex);77KernelState m_state GUARDED_BY(m_tip_block_mutex);78//! The block for which the last blockTip notification was received.79//! It's first set when the tip is connected during node initialization.80//! Might be unset during an early shutdown.81std::optional<uint256> TipBlock() EXCLUSIVE_LOCKS_REQUIRED(m_tip_block_mutex);83private:84const std::function<bool()>& m_shutdown_request;85std::atomic<int>& m_exit_status;86node::Warnings& m_warnings;87};89void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);91} // namespace node93#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H