LCOV - code coverage report
Current view: top level - src/node - kernel_notifications.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 8 43 18.6 %
Date: 2023-09-26 12:08:55 Functions: 3 10 30.0 %

          Line data    Source code
       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             : #if defined(HAVE_CONFIG_H)
       8             : #include <config/bitcoin-config.h>
       9             : #endif
      10             : 
      11             : #include <chain.h>
      12             : #include <common/args.h>
      13             : #include <common/system.h>
      14             : #include <kernel/context.h>
      15             : #include <logging.h>
      16             : #include <node/abort.h>
      17             : #include <node/interface_ui.h>
      18             : #include <shutdown.h>
      19             : #include <util/check.h>
      20             : #include <util/strencodings.h>
      21             : #include <util/string.h>
      22             : #include <util/translation.h>
      23             : #include <warnings.h>
      24             : 
      25             : #include <cstdint>
      26             : #include <string>
      27             : #include <thread>
      28             : 
      29           0 : static void AlertNotify(const std::string& strMessage)
      30             : {
      31           0 :     uiInterface.NotifyAlertChanged();
      32             : #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             : #endif
      47           0 : }
      48             : 
      49           0 : static void DoWarning(const bilingual_str& warning)
      50             : {
      51             :     static bool fWarned = false;
      52           0 :     SetMiscWarning(warning);
      53           0 :     if (!fWarned) {
      54           0 :         AlertNotify(warning.original);
      55           0 :         fWarned = true;
      56           0 :     }
      57           0 : }
      58             : 
      59             : namespace node {
      60             : 
      61         201 : kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
      62             : {
      63         201 :     uiInterface.NotifyBlockTip(state, &index);
      64         201 :     if (m_stop_at_height && index.nHeight >= m_stop_at_height) {
      65           0 :         StartShutdown();
      66           0 :         return kernel::Interrupted{};
      67             :     }
      68         201 :     return {};
      69         201 : }
      70             : 
      71         200 : void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
      72             : {
      73         200 :     uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
      74         202 : }
      75             : 
      76           0 : void KernelNotifications::progress(const bilingual_str& title, int progress_percent, bool resume_possible)
      77             : {
      78           0 :     uiInterface.ShowProgress(title.translated, progress_percent, resume_possible);
      79           0 : }
      80             : 
      81           0 : void KernelNotifications::warning(const bilingual_str& warning)
      82             : {
      83           0 :     DoWarning(warning);
      84           0 : }
      85             : 
      86           0 : void KernelNotifications::flushError(const std::string& debug_message)
      87             : {
      88           0 :     AbortNode(m_exit_status, debug_message);
      89           0 : }
      90             : 
      91           0 : void KernelNotifications::fatalError(const std::string& debug_message, const bilingual_str& user_message)
      92             : {
      93           0 :     node::AbortNode(m_exit_status, debug_message, user_message, m_shutdown_on_fatal_error);
      94           0 : }
      95             : 
      96           0 : void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications)
      97             : {
      98           0 :     if (auto value{args.GetIntArg("-stopatheight")}) notifications.m_stop_at_height = *value;
      99           0 : }
     100             : 
     101             : } // namespace node

Generated by: LCOV version 1.14