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 ;
}
std : : string GetWarnings ( const std : : string & strFor )
{
std : : string strStatusBar ;
std : : string strGUI ;
2021-07-19 12:39:22 +02:00
const std : : string uiAlertSeparator = " <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
if ( ! CLIENT_VERSION_IS_RELEASE ) {
strStatusBar = " This is a pre-release test build - use at your own risk - do not use for mining or merchant applications " ;
2022-03-24 05:13:51 +01:00
strGUI = _ ( " 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
if ( strMiscWarning ! = " " )
{
strStatusBar = strMiscWarning ;
2021-07-19 12:39:22 +02:00
strGUI + = ( strGUI . empty ( ) ? " " : uiAlertSeparator ) + strMiscWarning ;
2016-12-19 12:38:35 +01:00
}
if ( fLargeWorkForkFound )
{
2018-04-27 17:03:33 +02:00
strStatusBar = " Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues. " ;
2022-03-24 05:13:51 +01:00
strGUI + = ( strGUI . empty ( ) ? " " : uiAlertSeparator ) + _ ( " Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues. " ) . translated ;
2016-12-19 12:38:35 +01:00
}
else if ( fLargeWorkInvalidChainFound )
{
2018-04-27 17:03:33 +02:00
strStatusBar = " Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade. " ;
2022-03-24 05:13:51 +01:00
strGUI + = ( strGUI . empty ( ) ? " " : uiAlertSeparator ) + _ ( " 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
}
if ( strFor = = " gui " )
return strGUI ;
else if ( strFor = = " statusbar " )
return strStatusBar ;
assert ( ! " GetWarnings(): invalid parameter " ) ;
return " error " ;
}