2016-12-19 12:38:35 +01:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// 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>
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
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 ;
static std : : string strMiscWarning GUARDED_BY ( g_warnings_mutex ) ;
static bool fLargeWorkForkFound GUARDED_BY ( g_warnings_mutex ) = false ;
static bool fLargeWorkInvalidChainFound GUARDED_BY ( g_warnings_mutex ) = false ;
2016-12-19 12:38:35 +01:00
void SetMiscWarning ( const std : : string & strWarning )
{
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
strMiscWarning = strWarning ;
}
void SetfLargeWorkForkFound ( 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
fLargeWorkForkFound = flag ;
}
bool GetfLargeWorkForkFound ( )
{
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
return fLargeWorkForkFound ;
}
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 ;
}
2019-12-16 22:07:12 +01:00
std : : string GetWarnings ( bool verbose )
2016-12-19 12:38:35 +01:00
{
2019-12-16 22:07:12 +01:00
std : : string warnings_concise ;
std : : string warnings_verbose ;
const std : : string warning_separator = " <hr /> " ;
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 ) {
2019-12-16 22:07:12 +01: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 = _ ( " This is a pre-release test build - use at your own risk - do not use for mining or merchant applications " ) . translated ;
2016-12-19 12:38:35 +01:00
}
// Misc warnings like out of disk space and clock is wrong
2019-12-16 22:07:12 +01:00
if ( strMiscWarning ! = " " ) {
warnings_concise = strMiscWarning ;
warnings_verbose + = ( warnings_verbose . empty ( ) ? " " : warning_separator ) + strMiscWarning ;
2016-12-19 12:38:35 +01:00
}
2019-12-16 22:07:12 +01:00
if ( fLargeWorkForkFound ) {
warnings_concise = " Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues. " ;
warnings_verbose + = ( warnings_verbose . empty ( ) ? " " : warning_separator ) + _ ( " Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues. " ) . translated ;
} else if ( fLargeWorkInvalidChainFound ) {
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 + = ( warnings_verbose . empty ( ) ? " " : warning_separator ) + _ ( " Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade. " ) . translated ;
2016-12-19 12:38:35 +01:00
}
2019-12-16 22:07:12 +01:00
if ( verbose ) return warnings_verbose ;
else return warnings_concise ;
2016-12-19 12:38:35 +01:00
}