Inside Bitcoin
Opening the selected file…
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#include <node/kernel_notifications.h>7#include <bitcoin-build-config.h> // IWYU pragma: keep9#include <chain.h>10#include <common/args.h>11#include <common/system.h>12#include <kernel/context.h>13#include <kernel/warning.h>14#include <node/abort.h>15#include <node/interface_ui.h>16#include <node/warnings.h>17#include <util/check.h>18#include <util/log.h>19#include <util/signalinterrupt.h>20#include <util/strencodings.h>21#include <util/string.h>22#include <util/translation.h>24#include <cstdint>25#include <string>26#include <thread>28using util::ReplaceAll;30static void AlertNotify(const std::string& strMessage)31{32#if HAVE_SYSTEM33std::string strCmd = gArgs.GetArg("-alertnotify", "");34if (strCmd.empty()) return;36// Alert text should be plain ascii coming from a trusted source, but to37// be safe we first strip anything not in safeChars, then add single quotes around38// the whole string before passing it to the shell:39std::string singleQuote("'");40std::string safeStatus = SanitizeString(strMessage);41safeStatus = singleQuote+safeStatus+singleQuote;42ReplaceAll(strCmd, "%s", safeStatus);44std::thread t(runCommand, strCmd);45t.detach(); // thread runs free46#endif47}49namespace node {51kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, const CBlockIndex& index, double verification_progress)52{53{54LOCK(m_tip_block_mutex);55Assume(index.GetBlockHash() != uint256::ZERO);56m_state.tip_block = index.GetBlockHash();57m_tip_block_cv.notify_all();58}60uiInterface.NotifyBlockTip(state, index, verification_progress);61if (m_stop_at_height && index.nHeight >= m_stop_at_height) {62if (!m_shutdown_request()) {63LogError("Failed to send shutdown signal after reaching stop height\n");64}65return kernel::Interrupted{};66}67return {};68}70void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)71{72uiInterface.NotifyHeaderTip(state, height, timestamp, presync);73}75void KernelNotifications::progress(const bilingual_str& title, int progress_percent, bool resume_possible)76{77uiInterface.ShowProgress(title.translated, progress_percent, resume_possible);78}80void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message)81{82if (m_warnings.Set(id, message)) {83AlertNotify(message.original);84}85}87void KernelNotifications::warningUnset(kernel::Warning id)88{89m_warnings.Unset(id);90}92void KernelNotifications::flushError(const bilingual_str& message)93{94AbortNode(m_shutdown_request, m_exit_status, message, &m_warnings);95}97void KernelNotifications::fatalError(const bilingual_str& message)98{99node::AbortNode(m_shutdown_on_fatal_error ? m_shutdown_request : nullptr,100m_exit_status, message, &m_warnings);101}103std::optional<uint256> KernelNotifications::TipBlock()104{105AssertLockHeld(m_tip_block_mutex);106return m_state.tip_block;107};110void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications)111{112if (auto value{args.GetIntArg("-stopatheight")}) notifications.m_stop_at_height = *value;113}115} // namespace node