Skip to content

Commit

Permalink
Merge #10464: Introduce static DoWarning (simplify UpdateTip)
Browse files Browse the repository at this point in the history
f285145 Introduce static DoWarning (simplify UpdateTip) (Jorge Timón)

Tree-SHA512: 58b39f00bc921d47d199ef1cc15e9e36f918ec86e9182de46dc2f24fa9474853a92b18d330a274a3ea7c9b001681fdfa3d86aa2bbebb5c92ac8c5a6f7690dfc1
  • Loading branch information
sipa committed May 31, 2017
2 parents acd9957 + f285145 commit f94b7d5
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/validation.cpp
Expand Up @@ -1864,6 +1864,16 @@ void PruneAndFlush() {
FlushStateToDisk(state, FLUSH_STATE_NONE);
}

static void DoWarning(const std::string& strWarning)
{
static bool fWarned = false;
SetMiscWarning(strWarning);
if (!fWarned) {
AlertNotify(strWarning);
fWarned = true;
}
}

/** Update chainActive and related internal data structures. */
void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
chainActive.SetTip(pindexNew);
Expand All @@ -1873,7 +1883,6 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {

cvBlockChange.notify_all();

static bool fWarned = false;
std::vector<std::string> warningMessages;
if (!IsInitialBlockDownload())
{
Expand All @@ -1883,15 +1892,11 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
WarningBitsConditionChecker checker(bit);
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) {
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
if (state == THRESHOLD_ACTIVE) {
std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
SetMiscWarning(strWarning);
if (!fWarned) {
AlertNotify(strWarning);
fWarned = true;
}
DoWarning(strWarning);
} else {
warningMessages.push_back(strprintf("unknown new rules are about to activate (versionbit %i)", bit));
warningMessages.push_back(strWarning);
}
}
}
Expand All @@ -1904,16 +1909,12 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
pindex = pindex->pprev;
}
if (nUpgraded > 0)
warningMessages.push_back(strprintf("%d of last 100 blocks have unexpected version", nUpgraded));
warningMessages.push_back(strprintf(_("%d of last 100 blocks have unexpected version"), nUpgraded));
if (nUpgraded > 100/2)
{
std::string strWarning = _("Warning: Unknown block versions being mined! It's possible unknown rules are in effect");
// notify GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
SetMiscWarning(strWarning);
if (!fWarned) {
AlertNotify(strWarning);
fWarned = true;
}
DoWarning(strWarning);
}
}
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utx)", __func__,
Expand Down

0 comments on commit f94b7d5

Please sign in to comment.