Skip to content

Commit

Permalink
Make QT runawayException call GetWarnings instead of directly access …
Browse files Browse the repository at this point in the history
…strMiscWarning.

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

The change required moving GetWarnings and related globals to util.

Coming from btc@c63198f1c787d69052d6332c5e52118f58eacf56

Github-Pull: #2063
Rebased-From: 5fdd73e
  • Loading branch information
furszy authored and Fuzzbawls committed Dec 19, 2020
1 parent 0ece82d commit 3fc1597
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/qt/pivx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ BitcoinCore::BitcoinCore() : QObject()
void BitcoinCore::handleRunawayException(const std::exception* e)
{
PrintExceptionContinue(e, "Runaway exception");
Q_EMIT runawayException(QString::fromStdString(strMiscWarning));
Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui")));
}

void BitcoinCore::initialize()
Expand Down Expand Up @@ -696,10 +696,10 @@ int main(int argc, char* argv[])
app.exec();
} catch (const std::exception& e) {
PrintExceptionContinue(&e, "Runaway exception");
app.handleRunawayException(QString::fromStdString(strMiscWarning));
app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
} catch (...) {
PrintExceptionContinue(NULL, "Runaway exception");
app.handleRunawayException(QString::fromStdString(strMiscWarning));
app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
}
return app.getReturnValue();
}
Expand Down
35 changes: 34 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ std::string strBudgetMode = "";
ArgsManager gArgs;

bool fDaemon = false;
std::string strMiscWarning;
CTranslationInterface translationInterface;

std::string strMiscWarning;
bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;

/** Init OpenSSL library multithreading support */
static RecursiveMutex** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
Expand Down Expand Up @@ -839,3 +842,33 @@ int GetNumCores()
{
return std::thread::hardware_concurrency();
}

std::string GetWarnings(const std::string& strFor)
{
std::string strStatusBar;
std::string strRPC;

if (!CLIENT_VERSION_IS_RELEASE)
strStatusBar = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!");

if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = "testsafemode enabled";

// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "") {
strStatusBar = strMiscWarning;
}

if (fLargeWorkForkFound) {
strStatusBar = strRPC = _("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.");
}

if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings() : invalid parameter");
return "error";
}
8 changes: 7 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ extern bool fLiteMode;
extern std::string strMasterNodeAddr;
extern std::string strBudgetMode;

extern std::string strMiscWarning;
extern CTranslationInterface translationInterface;

static const bool DEFAULT_TESTSAFEMODE = false;
extern std::string strMiscWarning;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;

/**
* Translation function: Call Translate signal on UI interface, which returns a Optional result.
* If no translation slot is registered, nothing is returned, and simply return the input.
Expand Down Expand Up @@ -262,4 +266,6 @@ void TraceThread(const char* name, Callable func)

fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);

std::string GetWarnings(const std::string& strFor);

#endif // BITCOIN_UTIL_H
33 changes: 0 additions & 33 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,6 @@ bool IsInitialBlockDownload()
return state;
}

bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;
CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL;

static void AlertNotify(const std::string& strMessage)
Expand Down Expand Up @@ -4087,37 +4085,6 @@ void static CheckBlockIndex()
assert(nNodes == forward.size());
}


std::string GetWarnings(std::string strFor)
{
std::string strStatusBar;
std::string strRPC;

if (!CLIENT_VERSION_IS_RELEASE)
strStatusBar = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!");

if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = "testsafemode enabled";

// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "") {
strStatusBar = strMiscWarning;
}

if (fLargeWorkForkFound) {
strStatusBar = strRPC = _("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.");
}

if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings() : invalid parameter");
return "error";
}

// Note: whenever a protocol update is needed toggle between both implementations (comment out the formerly active one)
// so we can leave the existing clients untouched (old SPORK will stay on so they don't see even older clients).
// Those old clients won't react to the changes of the other (new) SPORK because at the time of their implementation
Expand Down
4 changes: 0 additions & 4 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72;
/** Default for -txindex */
static const bool DEFAULT_TXINDEX = true;
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
/** Default for -testsafemode */
static const bool DEFAULT_TESTSAFEMODE = false;
/** Default for -relaypriority */
static const bool DEFAULT_RELAYPRIORITY = true;
/** Default for -limitfeerelay */
Expand Down Expand Up @@ -200,8 +198,6 @@ void ThreadScriptCheck();

/** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload();
/** Format a string that describes several potential problems detected by the core */
std::string GetWarnings(std::string strFor);
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
bool GetTransaction(const uint256& hash, CTransaction& tx, uint256& hashBlock, bool fAllowSlow = false, CBlockIndex* blockIndex = nullptr);
/** Retrieve an output (from memory pool, or from disk, if possible) */
Expand Down

0 comments on commit 3fc1597

Please sign in to comment.