/Users/eugenesiegel/btc/bitcoin/src/node/kernel_notifications.cpp
| Line | Count | Source (jump to first uncovered line) | 
| 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 |  | #include <node/kernel_notifications.h> | 
| 6 |  |  | 
| 7 |  | #include <bitcoin-build-config.h> // IWYU pragma: keep | 
| 8 |  |  | 
| 9 |  | #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 <logging.h> | 
| 15 |  | #include <node/abort.h> | 
| 16 |  | #include <node/interface_ui.h> | 
| 17 |  | #include <node/warnings.h> | 
| 18 |  | #include <util/check.h> | 
| 19 |  | #include <util/signalinterrupt.h> | 
| 20 |  | #include <util/strencodings.h> | 
| 21 |  | #include <util/string.h> | 
| 22 |  | #include <util/translation.h> | 
| 23 |  |  | 
| 24 |  | #include <cstdint> | 
| 25 |  | #include <string> | 
| 26 |  | #include <thread> | 
| 27 |  |  | 
| 28 |  | using util::ReplaceAll; | 
| 29 |  |  | 
| 30 |  | static void AlertNotify(const std::string& strMessage) | 
| 31 | 0 | { | 
| 32 | 0 | #if HAVE_SYSTEM | 
| 33 | 0 |     std::string strCmd = gArgs.GetArg("-alertnotify", ""); | 
| 34 | 0 |     if (strCmd.empty()) return; | 
| 35 |  |  | 
| 36 |  |     // Alert text should be plain ascii coming from a trusted source, but to | 
| 37 |  |     // be safe we first strip anything not in safeChars, then add single quotes around | 
| 38 |  |     // the whole string before passing it to the shell: | 
| 39 | 0 |     std::string singleQuote("'"); | 
| 40 | 0 |     std::string safeStatus = SanitizeString(strMessage); | 
| 41 | 0 |     safeStatus = singleQuote+safeStatus+singleQuote; | 
| 42 | 0 |     ReplaceAll(strCmd, "%s", safeStatus); | 
| 43 |  | 
 | 
| 44 | 0 |     std::thread t(runCommand, strCmd); | 
| 45 | 0 |     t.detach(); // thread runs free | 
| 46 | 0 | #endif | 
| 47 | 0 | } | 
| 48 |  |  | 
| 49 |  | namespace node { | 
| 50 |  |  | 
| 51 |  | kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, const CBlockIndex& index, double verification_progress) | 
| 52 | 72.9k | { | 
| 53 | 72.9k |     { | 
| 54 | 72.9k |         LOCK(m_tip_block_mutex); | Line | Count | Source |  | 259 | 72.9k | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) | Line | Count | Source |  | 11 | 72.9k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) | Line | Count | Source |  | 9 | 72.9k | #define PASTE2(x, y) PASTE(x, y) | Line | Count | Source |  | 8 | 72.9k | #define PASTE(x, y) x ## y | 
 | 
 | 
 | 
 | 
| 55 | 72.9k |         Assume(index.GetBlockHash() != uint256::ZERO); | Line | Count | Source |  | 118 | 72.9k | #define Assume(val) inline_assertion_check<false>(val, __FILE__, __LINE__, __func__, #val) | 
 | 
| 56 | 72.9k |         m_tip_block = index.GetBlockHash(); | 
| 57 | 72.9k |         m_tip_block_cv.notify_all(); | 
| 58 | 72.9k |     } | 
| 59 |  |  | 
| 60 | 72.9k |     uiInterface.NotifyBlockTip(state, index, verification_progress); | 
| 61 | 72.9k |     if (m_stop_at_height && index.nHeight >= m_stop_at_height0) { | 
| 62 | 0 |         if (!m_shutdown_request()) { | 
| 63 | 0 |             LogError("Failed to send shutdown signal after reaching stop height\n");| Line | Count | Source |  | 358 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) | Line | Count | Source |  | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) | 
 | 
 | 
| 64 | 0 |         } | 
| 65 | 0 |         return kernel::Interrupted{}; | 
| 66 | 0 |     } | 
| 67 | 72.9k |     return {}; | 
| 68 | 72.9k | } | 
| 69 |  |  | 
| 70 |  | void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) | 
| 71 | 47.2k | { | 
| 72 | 47.2k |     uiInterface.NotifyHeaderTip(state, height, timestamp, presync); | 
| 73 | 47.2k | } | 
| 74 |  |  | 
| 75 |  | void KernelNotifications::progress(const bilingual_str& title, int progress_percent, bool resume_possible) | 
| 76 | 461k | { | 
| 77 | 461k |     uiInterface.ShowProgress(title.translated, progress_percent, resume_possible); | 
| 78 | 461k | } | 
| 79 |  |  | 
| 80 |  | void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message) | 
| 81 | 0 | { | 
| 82 | 0 |     if (m_warnings.Set(id, message)) { | 
| 83 | 0 |         AlertNotify(message.original); | 
| 84 | 0 |     } | 
| 85 | 0 | } | 
| 86 |  |  | 
| 87 |  | void KernelNotifications::warningUnset(kernel::Warning id) | 
| 88 | 29.8k | { | 
| 89 | 29.8k |     m_warnings.Unset(id); | 
| 90 | 29.8k | } | 
| 91 |  |  | 
| 92 |  | void KernelNotifications::flushError(const bilingual_str& message) | 
| 93 | 0 | { | 
| 94 | 0 |     AbortNode(m_shutdown_request, m_exit_status, message, &m_warnings); | 
| 95 | 0 | } | 
| 96 |  |  | 
| 97 |  | void KernelNotifications::fatalError(const bilingual_str& message) | 
| 98 | 0 | { | 
| 99 | 0 |     node::AbortNode(m_shutdown_on_fatal_error ? m_shutdown_request : nullptr, | 
| 100 | 0 |                     m_exit_status, message, &m_warnings); | 
| 101 | 0 | } | 
| 102 |  |  | 
| 103 |  | std::optional<uint256> KernelNotifications::TipBlock() | 
| 104 | 0 | { | 
| 105 | 0 |     AssertLockHeld(m_tip_block_mutex); | Line | Count | Source |  | 137 | 0 | #define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs) | 
 | 
| 106 | 0 |     return m_tip_block; | 
| 107 | 0 | }; | 
| 108 |  |  | 
| 109 |  |  | 
| 110 |  | void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications) | 
| 111 | 0 | { | 
| 112 | 0 |     if (auto value{args.GetIntArg("-stopatheight")}) notifications.m_stop_at_height = *value; | 
| 113 | 0 | } | 
| 114 |  |  | 
| 115 |  | } // namespace node |