LCOV - code coverage report
Current view: top level - src - warnings.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 14 28 50.0 %
Date: 2024-05-24 08:22:33 Functions: 3 5 60.0 %
Branches: 10 32 31.2 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2022 The Bitcoin Core developers
       3                 :            : // Distributed under the MIT software license, see the accompanying
       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :            : 
       6                 :            : #include <config/bitcoin-config.h> // IWYU pragma: keep
       7                 :            : 
       8                 :            : #include <warnings.h>
       9                 :            : 
      10                 :            : #include <common/system.h>
      11                 :            : #include <sync.h>
      12                 :            : #include <util/translation.h>
      13                 :            : 
      14                 :            : #include <optional>
      15                 :            : #include <vector>
      16                 :            : 
      17                 :            : static GlobalMutex g_warnings_mutex;
      18                 :            : static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
      19                 :            : static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
      20                 :            : static std::optional<bilingual_str> g_timeoffset_warning GUARDED_BY(g_warnings_mutex){};
      21                 :            : 
      22                 :          0 : void SetMiscWarning(const bilingual_str& warning)
      23                 :            : {
      24                 :          0 :     LOCK(g_warnings_mutex);
      25         [ #  # ]:          0 :     g_misc_warnings = warning;
      26                 :          0 : }
      27                 :            : 
      28                 :          0 : void SetfLargeWorkInvalidChainFound(bool flag)
      29                 :            : {
      30                 :          0 :     LOCK(g_warnings_mutex);
      31                 :          0 :     fLargeWorkInvalidChainFound = flag;
      32                 :          0 : }
      33                 :            : 
      34                 :     106900 : void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning)
      35                 :            : {
      36                 :     106900 :     LOCK(g_warnings_mutex);
      37         [ +  - ]:     106900 :     g_timeoffset_warning = warning;
      38                 :     106900 : }
      39                 :            : 
      40                 :          9 : std::vector<bilingual_str> GetWarnings()
      41                 :            : {
      42                 :          9 :     std::vector<bilingual_str> warnings;
      43                 :            : 
      44   [ +  -  +  - ]:          9 :     LOCK(g_warnings_mutex);
      45                 :            : 
      46                 :            :     // Pre-release build warning
      47                 :            :     if (!CLIENT_VERSION_IS_RELEASE) {
      48   [ +  -  +  - ]:          9 :         warnings.emplace_back(_("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"));
      49                 :            :     }
      50                 :            : 
      51                 :            :     // Misc warnings like out of disk space and clock is wrong
      52   [ +  -  -  + ]:          9 :     if (!g_misc_warnings.empty()) {
      53         [ #  # ]:          0 :         warnings.emplace_back(g_misc_warnings);
      54                 :          0 :     }
      55                 :            : 
      56         [ +  - ]:          9 :     if (fLargeWorkInvalidChainFound) {
      57   [ #  #  #  # ]:          0 :         warnings.emplace_back(_("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."));
      58                 :          0 :     }
      59                 :            : 
      60         [ -  + ]:          9 :     if (g_timeoffset_warning) {
      61   [ #  #  #  # ]:          0 :         warnings.emplace_back(g_timeoffset_warning.value());
      62                 :          0 :     }
      63                 :            : 
      64                 :          9 :     return warnings;
      65         [ +  - ]:          9 : }

Generated by: LCOV version 1.16