LCOV - code coverage report
Current view: top level - src - warnings.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 32 45 71.1 %
Date: 2026-08-09 10:51:41 Functions: 4 6 66.7 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2016 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 "warnings.h"
       7             : 
       8             : #include "sync.h"
       9             : #include "clientversion.h"
      10             : #include "util/system.h"
      11             : 
      12             : RecursiveMutex cs_warnings;
      13             : std::string strMiscWarning;
      14             : bool fLargeWorkForkFound = false;
      15             : bool fLargeWorkInvalidChainFound = false;
      16             : 
      17         152 : void SetMiscWarning(const std::string& strWarning)
      18             : {
      19         152 :     LOCK(cs_warnings);
      20         152 :     strMiscWarning = strWarning;
      21         152 : }
      22             : 
      23       24196 : void SetfLargeWorkForkFound(bool flag)
      24             : {
      25       24196 :     LOCK(cs_warnings);
      26       24196 :     fLargeWorkForkFound = flag;
      27       24196 : }
      28             : 
      29           0 : bool GetfLargeWorkForkFound()
      30             : {
      31           0 :     LOCK(cs_warnings);
      32           0 :     return fLargeWorkForkFound;
      33             : }
      34             : 
      35       24196 : void SetfLargeWorkInvalidChainFound(bool flag)
      36             : {
      37       24196 :     LOCK(cs_warnings);
      38       24196 :     fLargeWorkInvalidChainFound = flag;
      39       24196 : }
      40             : 
      41           0 : bool GetfLargeWorkInvalidChainFound()
      42             : {
      43           0 :     LOCK(cs_warnings);
      44           0 :     return fLargeWorkInvalidChainFound;
      45             : }
      46             : 
      47       56608 : std::string GetWarnings(const std::string& strFor)
      48             : {
      49      113216 :     std::string strStatusBar;
      50       56608 :     std::string strRPC;
      51       56608 :     std::string strGUI;
      52      113216 :     const std::string uiAlertSeperator = "\n";
      53             : 
      54      113216 :     LOCK(cs_warnings);
      55             : 
      56       56608 :     if (!CLIENT_VERSION_IS_RELEASE) {
      57       56608 :         strStatusBar = "This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!";
      58       56608 :         strGUI = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!");
      59             :     }
      60             : 
      61       56608 :     if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
      62           0 :         strStatusBar = strRPC = strGUI = "testsafemode enabled";
      63             : 
      64             :     // Misc warnings like out of disk space and clock is wrong
      65       56608 :     if (!strMiscWarning.empty()) {
      66          48 :         strStatusBar = strMiscWarning;
      67         192 :         strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
      68             :     }
      69             : 
      70       56608 :     if (fLargeWorkForkFound) {
      71           0 :         strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
      72           0 :         strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
      73       56608 :     } else if (fLargeWorkInvalidChainFound) {
      74           0 :         strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
      75           0 :         strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
      76             :     }
      77             : 
      78       56608 :     if (strFor == "gui")
      79           0 :         return strGUI;
      80       56608 :     else if (strFor == "statusbar")
      81         626 :         return strStatusBar;
      82       55982 :     else if (strFor == "rpc")
      83      112590 :         return strRPC;
      84           0 :     assert(!"GetWarnings() : invalid parameter");
      85             :     return "error";
      86             : }
      87             : 

Generated by: LCOV version 1.14