Skip to content

Commit c63198f

Browse files
committed
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.
1 parent 2efcfa5 commit c63198f

File tree

5 files changed

+59
-49
lines changed

5 files changed

+59
-49
lines changed

src/qt/bitcoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ BitcoinCore::BitcoinCore():
260260
void BitcoinCore::handleRunawayException(const std::exception *e)
261261
{
262262
PrintExceptionContinue(e, "Runaway exception");
263-
Q_EMIT runawayException(QString::fromStdString(strMiscWarning));
263+
Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui")));
264264
}
265265

266266
void BitcoinCore::initialize()
@@ -691,10 +691,10 @@ int main(int argc, char *argv[])
691691
app.exec();
692692
} catch (const std::exception& e) {
693693
PrintExceptionContinue(&e, "Runaway exception");
694-
app.handleRunawayException(QString::fromStdString(strMiscWarning));
694+
app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
695695
} catch (...) {
696696
PrintExceptionContinue(NULL, "Runaway exception");
697-
app.handleRunawayException(QString::fromStdString(strMiscWarning));
697+
app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
698698
}
699699
return app.getReturnValue();
700700
}

src/util.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ map<string, vector<string> > mapMultiArgs;
107107
bool fDebug = false;
108108
bool fPrintToConsole = false;
109109
bool fPrintToDebugLog = true;
110+
110111
string strMiscWarning;
112+
bool fLargeWorkForkFound = false;
113+
bool fLargeWorkInvalidChainFound = false;
114+
111115
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
112116
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
113117
bool fLogIPs = DEFAULT_LOGIPS;
@@ -808,3 +812,46 @@ std::string CopyrightHolders(const std::string& strPrefix)
808812
}
809813
return strCopyrightHolders;
810814
}
815+
816+
std::string GetWarnings(const std::string& strFor)
817+
{
818+
string strStatusBar;
819+
string strRPC;
820+
string strGUI;
821+
const string uiAlertSeperator = "<hr />";
822+
823+
if (!CLIENT_VERSION_IS_RELEASE) {
824+
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
825+
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
826+
}
827+
828+
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
829+
strStatusBar = strRPC = strGUI = "testsafemode enabled";
830+
831+
// Misc warnings like out of disk space and clock is wrong
832+
if (strMiscWarning != "")
833+
{
834+
strStatusBar = strMiscWarning;
835+
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
836+
}
837+
838+
if (fLargeWorkForkFound)
839+
{
840+
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
841+
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
842+
}
843+
else if (fLargeWorkInvalidChainFound)
844+
{
845+
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.";
846+
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.");
847+
}
848+
849+
if (strFor == "gui")
850+
return strGUI;
851+
else if (strFor == "statusbar")
852+
return strStatusBar;
853+
else if (strFor == "rpc")
854+
return strRPC;
855+
assert(!"GetWarnings(): invalid parameter");
856+
return "error";
857+
}

src/util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
4646
extern bool fDebug;
4747
extern bool fPrintToConsole;
4848
extern bool fPrintToDebugLog;
49+
50+
static const bool DEFAULT_TESTSAFEMODE = false;
4951
extern std::string strMiscWarning;
52+
extern bool fLargeWorkForkFound;
53+
extern bool fLargeWorkInvalidChainFound;
54+
5055
extern bool fLogTimestamps;
5156
extern bool fLogTimeMicros;
5257
extern bool fLogIPs;
@@ -224,4 +229,6 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
224229

225230
std::string CopyrightHolders(const std::string& strPrefix);
226231

232+
std::string GetWarnings(const std::string& strFor);
233+
227234
#endif // BITCOIN_UTIL_H

src/validation.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,6 @@ bool IsInitialBlockDownload()
11491149
return false;
11501150
}
11511151

1152-
bool fLargeWorkForkFound = false;
1153-
bool fLargeWorkInvalidChainFound = false;
11541152
CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL;
11551153

11561154
static void AlertNotify(const std::string& strMessage)
@@ -4005,51 +4003,10 @@ void static CheckBlockIndex(const Consensus::Params& consensusParams)
40054003
assert(nNodes == forward.size());
40064004
}
40074005

4008-
std::string GetWarnings(const std::string& strFor)
4006+
std::string CBlockFileInfo::ToString() const
40094007
{
4010-
string strStatusBar;
4011-
string strRPC;
4012-
string strGUI;
4013-
const string uiAlertSeperator = "<hr />";
4014-
4015-
if (!CLIENT_VERSION_IS_RELEASE) {
4016-
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
4017-
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
4018-
}
4019-
4020-
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
4021-
strStatusBar = strRPC = strGUI = "testsafemode enabled";
4022-
4023-
// Misc warnings like out of disk space and clock is wrong
4024-
if (strMiscWarning != "")
4025-
{
4026-
strStatusBar = strMiscWarning;
4027-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
4028-
}
4029-
4030-
if (fLargeWorkForkFound)
4031-
{
4032-
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
4033-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
4034-
}
4035-
else if (fLargeWorkInvalidChainFound)
4036-
{
4037-
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.";
4038-
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.");
4039-
}
4040-
4041-
if (strFor == "gui")
4042-
return strGUI;
4043-
else if (strFor == "statusbar")
4044-
return strStatusBar;
4045-
else if (strFor == "rpc")
4046-
return strRPC;
4047-
assert(!"GetWarnings(): invalid parameter");
4048-
return "error";
4008+
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));
40494009
}
4050-
std::string CBlockFileInfo::ToString() const {
4051-
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));
4052-
}
40534010

40544011
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
40554012
{

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
137137
static const bool DEFAULT_TXINDEX = false;
138138
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
139139

140-
static const bool DEFAULT_TESTSAFEMODE = false;
141140
/** Default for -mempoolreplacement */
142141
static const bool DEFAULT_ENABLE_REPLACEMENT = true;
143142
/** Default for using fee filter */

0 commit comments

Comments
 (0)