Make QT runawayException call GetWarnings instead of directly access strMiscWarning.

This is a first step in avoiding racy accesses to strMiscWarning.

The change required moving GetWarnings and related globals to util.
This commit is contained in:
Gregory Maxwell 2016-11-29 01:00:11 +00:00
parent 2efcfa5acf
commit c63198f1c7
5 changed files with 59 additions and 49 deletions

View file

@ -260,7 +260,7 @@ BitcoinCore::BitcoinCore():
void BitcoinCore::handleRunawayException(const std::exception *e) void BitcoinCore::handleRunawayException(const std::exception *e)
{ {
PrintExceptionContinue(e, "Runaway exception"); PrintExceptionContinue(e, "Runaway exception");
Q_EMIT runawayException(QString::fromStdString(strMiscWarning)); Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui")));
} }
void BitcoinCore::initialize() void BitcoinCore::initialize()
@ -691,10 +691,10 @@ int main(int argc, char *argv[])
app.exec(); app.exec();
} catch (const std::exception& e) { } catch (const std::exception& e) {
PrintExceptionContinue(&e, "Runaway exception"); PrintExceptionContinue(&e, "Runaway exception");
app.handleRunawayException(QString::fromStdString(strMiscWarning)); app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
} catch (...) { } catch (...) {
PrintExceptionContinue(NULL, "Runaway exception"); PrintExceptionContinue(NULL, "Runaway exception");
app.handleRunawayException(QString::fromStdString(strMiscWarning)); app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
} }
return app.getReturnValue(); return app.getReturnValue();
} }

View file

@ -107,7 +107,11 @@ map<string, vector<string> > mapMultiArgs;
bool fDebug = false; bool fDebug = false;
bool fPrintToConsole = false; bool fPrintToConsole = false;
bool fPrintToDebugLog = true; bool fPrintToDebugLog = true;
string strMiscWarning; string strMiscWarning;
bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogIPs = DEFAULT_LOGIPS; bool fLogIPs = DEFAULT_LOGIPS;
@ -808,3 +812,46 @@ std::string CopyrightHolders(const std::string& strPrefix)
} }
return strCopyrightHolders; return strCopyrightHolders;
} }
std::string GetWarnings(const std::string& strFor)
{
string strStatusBar;
string strRPC;
string strGUI;
const string uiAlertSeperator = "<hr />";
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";
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
}
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = strGUI = "testsafemode enabled";
// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "")
{
strStatusBar = strMiscWarning;
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
}
if (fLargeWorkForkFound)
{
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
}
else if (fLargeWorkInvalidChainFound)
{
strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
}
if (strFor == "gui")
return strGUI;
else if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings(): invalid parameter");
return "error";
}

View file

@ -46,7 +46,12 @@ extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug; extern bool fDebug;
extern bool fPrintToConsole; extern bool fPrintToConsole;
extern bool fPrintToDebugLog; extern bool fPrintToDebugLog;
static const bool DEFAULT_TESTSAFEMODE = false;
extern std::string strMiscWarning; extern std::string strMiscWarning;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;
extern bool fLogTimestamps; extern bool fLogTimestamps;
extern bool fLogTimeMicros; extern bool fLogTimeMicros;
extern bool fLogIPs; extern bool fLogIPs;
@ -224,4 +229,6 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
std::string CopyrightHolders(const std::string& strPrefix); std::string CopyrightHolders(const std::string& strPrefix);
std::string GetWarnings(const std::string& strFor);
#endif // BITCOIN_UTIL_H #endif // BITCOIN_UTIL_H

View file

@ -1149,8 +1149,6 @@ bool IsInitialBlockDownload()
return false; return false;
} }
bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;
CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL; CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL;
static void AlertNotify(const std::string& strMessage) static void AlertNotify(const std::string& strMessage)
@ -4005,51 +4003,10 @@ void static CheckBlockIndex(const Consensus::Params& consensusParams)
assert(nNodes == forward.size()); assert(nNodes == forward.size());
} }
std::string GetWarnings(const std::string& strFor) std::string CBlockFileInfo::ToString() const
{ {
string strStatusBar;
string strRPC;
string strGUI;
const string uiAlertSeperator = "<hr />";
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";
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
}
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = strGUI = "testsafemode enabled";
// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "")
{
strStatusBar = strMiscWarning;
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
}
if (fLargeWorkForkFound)
{
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
}
else if (fLargeWorkInvalidChainFound)
{
strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
}
if (strFor == "gui")
return strGUI;
else if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings(): invalid parameter");
return "error";
}
std::string CBlockFileInfo::ToString() const {
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast)); return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast));
} }
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos) ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
{ {

View file

@ -137,7 +137,6 @@ static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
static const bool DEFAULT_TXINDEX = false; static const bool DEFAULT_TXINDEX = false;
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100; static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
static const bool DEFAULT_TESTSAFEMODE = false;
/** Default for -mempoolreplacement */ /** Default for -mempoolreplacement */
static const bool DEFAULT_ENABLE_REPLACEMENT = true; static const bool DEFAULT_ENABLE_REPLACEMENT = true;
/** Default for using fee filter */ /** Default for using fee filter */