Skip to content

Commit f285145

Browse files
committed
Introduce static DoWarning (simplify UpdateTip)
1 parent 4314544 commit f285145

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
@@ -1814,6 +1814,16 @@ void PruneAndFlush() {
18141814
FlushStateToDisk(state, FLUSH_STATE_NONE);
18151815
}
18161816

1817+
static void DoWarning(const std::string& strWarning)
1818+
{
1819+
static bool fWarned = false;
1820+
SetMiscWarning(strWarning);
1821+
if (!fWarned) {
1822+
AlertNotify(strWarning);
1823+
fWarned = true;
1824+
}
1825+
}
1826+
18171827
/** Update chainActive and related internal data structures. */
18181828
void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18191829
chainActive.SetTip(pindexNew);
@@ -1823,7 +1833,6 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18231833

18241834
cvBlockChange.notify_all();
18251835

1826-
static bool fWarned = false;
18271836
std::vector<std::string> warningMessages;
18281837
if (!IsInitialBlockDownload())
18291838
{
@@ -1833,15 +1842,11 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18331842
WarningBitsConditionChecker checker(bit);
18341843
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
18351844
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) {
1845+
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
18361846
if (state == THRESHOLD_ACTIVE) {
1837-
std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
1838-
SetMiscWarning(strWarning);
1839-
if (!fWarned) {
1840-
AlertNotify(strWarning);
1841-
fWarned = true;
1842-
}
1847+
DoWarning(strWarning);
18431848
} else {
1844-
warningMessages.push_back(strprintf("unknown new rules are about to activate (versionbit %i)", bit));
1849+
warningMessages.push_back(strWarning);
18451850
}
18461851
}
18471852
}
@@ -1854,16 +1859,12 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
18541859
pindex = pindex->pprev;
18551860
}
18561861
if (nUpgraded > 0)
1857-
warningMessages.push_back(strprintf("%d of last 100 blocks have unexpected version", nUpgraded));
1862+
warningMessages.push_back(strprintf(_("%d of last 100 blocks have unexpected version"), nUpgraded));
18581863
if (nUpgraded > 100/2)
18591864
{
18601865
std::string strWarning = _("Warning: Unknown block versions being mined! It's possible unknown rules are in effect");
18611866
// notify GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
1862-
SetMiscWarning(strWarning);
1863-
if (!fWarned) {
1864-
AlertNotify(strWarning);
1865-
fWarned = true;
1866-
}
1867+
DoWarning(strWarning);
18671868
}
18681869
}
18691870
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)