Skip to content

Commit f94b7d5

Browse files
committed
Merge #10464: Introduce static DoWarning (simplify UpdateTip)
f285145 Introduce static DoWarning (simplify UpdateTip) (Jorge Timón) Tree-SHA512: 58b39f00bc921d47d199ef1cc15e9e36f918ec86e9182de46dc2f24fa9474853a92b18d330a274a3ea7c9b001681fdfa3d86aa2bbebb5c92ac8c5a6f7690dfc1
2 parents acd9957 + f285145 commit f94b7d5

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/validation.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,16 @@ void PruneAndFlush() {
18641864
FlushStateToDisk(state, FLUSH_STATE_NONE);
18651865
}
18661866

1867+
static void DoWarning(const std::string& strWarning)
1868+
{
1869+
static bool fWarned = false;
1870+
SetMiscWarning(strWarning);
1871+
if (!fWarned) {
1872+
AlertNotify(strWarning);
1873+
fWarned = true;
1874+
}
1875+
}
1876+
18671877
/** Update chainActive and related internal data structures. */
18681878
void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18691879
chainActive.SetTip(pindexNew);
@@ -1873,7 +1883,6 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18731883

18741884
cvBlockChange.notify_all();
18751885

1876-
static bool fWarned = false;
18771886
std::vector<std::string> warningMessages;
18781887
if (!IsInitialBlockDownload())
18791888
{
@@ -1883,15 +1892,11 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18831892
WarningBitsConditionChecker checker(bit);
18841893
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
18851894
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) {
1895+
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
18861896
if (state == THRESHOLD_ACTIVE) {
1887-
std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
1888-
SetMiscWarning(strWarning);
1889-
if (!fWarned) {
1890-
AlertNotify(strWarning);
1891-
fWarned = true;
1892-
}
1897+
DoWarning(strWarning);
18931898
} else {
1894-
warningMessages.push_back(strprintf("unknown new rules are about to activate (versionbit %i)", bit));
1899+
warningMessages.push_back(strWarning);
18951900
}
18961901
}
18971902
}
@@ -1904,16 +1909,12 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
19041909
pindex = pindex->pprev;
19051910
}
19061911
if (nUpgraded > 0)
1907-
warningMessages.push_back(strprintf("%d of last 100 blocks have unexpected version", nUpgraded));
1912+
warningMessages.push_back(strprintf(_("%d of last 100 blocks have unexpected version"), nUpgraded));
19081913
if (nUpgraded > 100/2)
19091914
{
19101915
std::string strWarning = _("Warning: Unknown block versions being mined! It's possible unknown rules are in effect");
19111916
// notify GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
1912-
SetMiscWarning(strWarning);
1913-
if (!fWarned) {
1914-
AlertNotify(strWarning);
1915-
fWarned = true;
1916-
}
1917+
DoWarning(strWarning);
19171918
}
19181919
}
19191920
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utx)", __func__,

0 commit comments

Comments
 (0)