2016-12-19 12:38:35 +01:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2019-12-31 18:35:41 +01:00
|
|
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
2016-12-19 12:38:35 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2022-03-24 05:13:51 +01:00
|
|
|
#include <warnings.h>
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <sync.h>
|
2020-06-10 15:50:50 +02:00
|
|
|
#include <util/string.h>
|
2021-06-27 08:33:13 +02:00
|
|
|
#include <util/system.h>
|
2022-03-24 05:13:51 +01:00
|
|
|
#include <util/translation.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <hash.h>
|
2016-12-19 12:38:35 +01:00
|
|
|
|
2020-06-10 15:50:50 +02:00
|
|
|
#include <vector>
|
|
|
|
|
Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp
bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)
Pull request description:
The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.
Related to #19180.
ACKs for top commit:
laanwj:
Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
MarcoFalke:
ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W --word-diff-regex=. 🎿
Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
2020-06-09 14:54:52 +02:00
|
|
|
static Mutex g_warnings_mutex;
|
2020-06-10 15:50:50 +02:00
|
|
|
static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
|
Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp
bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)
Pull request description:
The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.
Related to #19180.
ACKs for top commit:
laanwj:
Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
MarcoFalke:
ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W --word-diff-regex=. 🎿
Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
2020-06-09 14:54:52 +02:00
|
|
|
static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
|
2016-12-19 12:38:35 +01:00
|
|
|
|
2020-06-10 15:50:50 +02:00
|
|
|
void SetMiscWarning(const bilingual_str& warning)
|
2016-12-19 12:38:35 +01:00
|
|
|
{
|
Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp
bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)
Pull request description:
The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.
Related to #19180.
ACKs for top commit:
laanwj:
Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
MarcoFalke:
ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W --word-diff-regex=. 🎿
Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
2020-06-09 14:54:52 +02:00
|
|
|
LOCK(g_warnings_mutex);
|
2020-06-10 15:50:50 +02:00
|
|
|
g_misc_warnings = warning;
|
2016-12-19 12:38:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetfLargeWorkInvalidChainFound(bool flag)
|
|
|
|
{
|
Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp
bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)
Pull request description:
The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.
Related to #19180.
ACKs for top commit:
laanwj:
Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
MarcoFalke:
ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W --word-diff-regex=. 🎿
Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
2020-06-09 14:54:52 +02:00
|
|
|
LOCK(g_warnings_mutex);
|
2016-12-19 12:38:35 +01:00
|
|
|
fLargeWorkInvalidChainFound = flag;
|
|
|
|
}
|
|
|
|
|
2020-06-10 15:50:50 +02:00
|
|
|
bilingual_str GetWarnings(bool verbose)
|
2016-12-19 12:38:35 +01:00
|
|
|
{
|
2020-06-10 15:50:50 +02:00
|
|
|
bilingual_str warnings_concise;
|
|
|
|
std::vector<bilingual_str> warnings_verbose;
|
2016-12-19 12:38:35 +01:00
|
|
|
|
Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp
bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)
Pull request description:
The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.
Related to #19180.
ACKs for top commit:
laanwj:
Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
MarcoFalke:
ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W --word-diff-regex=. 🎿
Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
2020-06-09 14:54:52 +02:00
|
|
|
LOCK(g_warnings_mutex);
|
2016-12-19 12:38:35 +01:00
|
|
|
|
2019-12-16 22:07:12 +01:00
|
|
|
// Pre-release build warning
|
2016-12-19 12:38:35 +01:00
|
|
|
if (!CLIENT_VERSION_IS_RELEASE) {
|
2020-06-10 15:50:50 +02:00
|
|
|
warnings_concise = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
|
|
|
|
warnings_verbose.emplace_back(warnings_concise);
|
2016-12-19 12:38:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Misc warnings like out of disk space and clock is wrong
|
2020-06-10 15:50:50 +02:00
|
|
|
if (!g_misc_warnings.empty()) {
|
|
|
|
warnings_concise = g_misc_warnings;
|
|
|
|
warnings_verbose.emplace_back(warnings_concise);
|
2016-12-19 12:38:35 +01:00
|
|
|
}
|
|
|
|
|
2020-09-07 07:58:42 +02:00
|
|
|
if (fLargeWorkInvalidChainFound) {
|
2020-06-10 15:50:50 +02:00
|
|
|
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.");
|
|
|
|
warnings_verbose.emplace_back(warnings_concise);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
return Join(warnings_verbose, Untranslated("<hr />"));
|
2016-12-19 12:38:35 +01:00
|
|
|
}
|
|
|
|
|
2020-06-10 15:50:50 +02:00
|
|
|
return warnings_concise;
|
2016-12-19 12:38:35 +01:00
|
|
|
}
|