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 : 2430 : void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning) 35 : : { 36 : 2430 : LOCK(g_warnings_mutex); 37 [ + - ]: 2430 : g_timeoffset_warning = warning; 38 : 2430 : } 39 : : 40 : 0 : std::vector<bilingual_str> GetWarnings() 41 : : { 42 : 0 : std::vector<bilingual_str> warnings; 43 : : 44 [ # # # # ]: 0 : LOCK(g_warnings_mutex); 45 : : 46 : : // Pre-release build warning 47 : : if (!CLIENT_VERSION_IS_RELEASE) { 48 [ # # # # ]: 0 : 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 [ # # # # ]: 0 : if (!g_misc_warnings.empty()) { 53 [ # # ]: 0 : warnings.emplace_back(g_misc_warnings); 54 : 0 : } 55 : : 56 [ # # ]: 0 : 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 [ # # ]: 0 : if (g_timeoffset_warning) { 61 [ # # # # ]: 0 : warnings.emplace_back(g_timeoffset_warning.value()); 62 : 0 : } 63 : : 64 : 0 : return warnings; 65 [ # # ]: 0 : }