Bitcoin Core  0.20.99
P2P Digital Currency
warnings.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <util/string.h>
10 #include <util/system.h>
11 #include <util/translation.h>
12 
13 #include <vector>
14 
16 static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
17 static bool fLargeWorkForkFound GUARDED_BY(g_warnings_mutex) = false;
18 static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
19 
20 void SetMiscWarning(const bilingual_str& warning)
21 {
22  LOCK(g_warnings_mutex);
23  g_misc_warnings = warning;
24 }
25 
26 void SetfLargeWorkForkFound(bool flag)
27 {
28  LOCK(g_warnings_mutex);
29  fLargeWorkForkFound = flag;
30 }
31 
33 {
34  LOCK(g_warnings_mutex);
35  return fLargeWorkForkFound;
36 }
37 
39 {
40  LOCK(g_warnings_mutex);
41  fLargeWorkInvalidChainFound = flag;
42 }
43 
45 {
46  bilingual_str warnings_concise;
47  std::vector<bilingual_str> warnings_verbose;
48 
49  LOCK(g_warnings_mutex);
50 
51  // Pre-release build warning
53  warnings_concise = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
54  warnings_verbose.emplace_back(warnings_concise);
55  }
56 
57  // Misc warnings like out of disk space and clock is wrong
58  if (!g_misc_warnings.empty()) {
59  warnings_concise = g_misc_warnings;
60  warnings_verbose.emplace_back(warnings_concise);
61  }
62 
63  if (fLargeWorkForkFound) {
64  warnings_concise = _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
65  warnings_verbose.emplace_back(warnings_concise);
66  } else if (fLargeWorkInvalidChainFound) {
67  warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
68  warnings_verbose.emplace_back(warnings_concise);
69  }
70 
71  if (verbose) {
72  return Join(warnings_verbose, Untranslated("<hr />"));
73  }
74 
75  return warnings_concise;
76 }
Bilingual messages:
Definition: translation.h:16
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Definition: string.h:34
void SetMiscWarning(const bilingual_str &warning)
Definition: warnings.cpp:20
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:40
#define CLIENT_VERSION_IS_RELEASE
void SetfLargeWorkInvalidChainFound(bool flag)
Definition: warnings.cpp:38
#define LOCK(cs)
Definition: sync.h:226
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:57
bilingual_str GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:44
bool GetfLargeWorkForkFound()
Definition: warnings.cpp:32
static Mutex g_warnings_mutex
Definition: warnings.cpp:15
void SetfLargeWorkForkFound(bool flag)
Definition: warnings.cpp:26
static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex)