Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 929 Lines • ▼ Show 20 Lines | bool IsInitialBlockDownload() { | ||||
LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); | LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); | ||||
latchToFalse.store(true, std::memory_order_relaxed); | latchToFalse.store(true, std::memory_order_relaxed); | ||||
return false; | return false; | ||||
} | } | ||||
CBlockIndex const *pindexBestForkTip = nullptr; | CBlockIndex const *pindexBestForkTip = nullptr; | ||||
CBlockIndex const *pindexBestForkBase = nullptr; | CBlockIndex const *pindexBestForkBase = nullptr; | ||||
static void AlertNotify(const std::string &strMessage) { | |||||
uiInterface.NotifyAlertChanged(); | |||||
std::string strCmd = gArgs.GetArg("-alertnotify", ""); | |||||
if (strCmd.empty()) { | |||||
return; | |||||
} | |||||
// Alert text should be plain ascii coming from a trusted source, but to be | |||||
// safe we first strip anything not in safeChars, then add single quotes | |||||
// around the whole string before passing it to the shell: | |||||
std::string singleQuote("'"); | |||||
std::string safeStatus = SanitizeString(strMessage); | |||||
safeStatus = singleQuote + safeStatus + singleQuote; | |||||
boost::replace_all(strCmd, "%s", safeStatus); | |||||
std::thread t(runCommand, strCmd); | |||||
// thread runs free | |||||
t.detach(); | |||||
} | |||||
static void CheckForkWarningConditions() { | static void CheckForkWarningConditions() { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
// Before we get past initial download, we cannot reliably alert about forks | // Before we get past initial download, we cannot reliably alert about forks | ||||
// (we assume we don't get stuck on a fork before finishing our initial | // (we assume we don't get stuck on a fork before finishing our initial | ||||
// sync) | // sync) | ||||
if (IsInitialBlockDownload()) { | if (IsInitialBlockDownload()) { | ||||
return; | return; | ||||
} | } | ||||
// If our best fork is no longer within 72 blocks (+/- 12 hours if no one | // If our best fork is no longer within 72 blocks (+/- 12 hours if no one | ||||
// mines it) of our head, drop it | // mines it) of our head, drop it | ||||
if (pindexBestForkTip && | if (pindexBestForkTip && | ||||
chainActive.Height() - pindexBestForkTip->nHeight >= 72) { | chainActive.Height() - pindexBestForkTip->nHeight >= 72) { | ||||
pindexBestForkTip = nullptr; | pindexBestForkTip = nullptr; | ||||
} | } | ||||
if (pindexBestForkTip || | if (pindexBestForkTip || | ||||
(pindexBestInvalid && | (pindexBestInvalid && | ||||
pindexBestInvalid->nChainWork > | pindexBestInvalid->nChainWork > | ||||
chainActive.Tip()->nChainWork + | chainActive.Tip()->nChainWork + | ||||
(GetBlockProof(*chainActive.Tip()) * 6))) { | (GetBlockProof(*chainActive.Tip()) * 6))) { | ||||
if (!GetfLargeWorkForkFound() && pindexBestForkBase) { | |||||
std::string warning = | |||||
std::string("'Warning: Large-work fork detected, forking after " | |||||
"block ") + | |||||
pindexBestForkBase->phashBlock->ToString() + std::string("'"); | |||||
AlertNotify(warning); | |||||
} | |||||
if (pindexBestForkTip && pindexBestForkBase) { | if (pindexBestForkTip && pindexBestForkBase) { | ||||
LogPrintf("%s: Warning: Large fork found\n forking the " | LogPrintf("%s: Warning: Large fork found\n forking the " | ||||
"chain at height %d (%s)\n lasting to height %d " | "chain at height %d (%s)\n lasting to height %d " | ||||
"(%s).\nChain state database corruption likely.\n", | "(%s).\nChain state database corruption likely.\n", | ||||
__func__, pindexBestForkBase->nHeight, | __func__, pindexBestForkBase->nHeight, | ||||
pindexBestForkBase->phashBlock->ToString(), | pindexBestForkBase->phashBlock->ToString(), | ||||
pindexBestForkTip->nHeight, | pindexBestForkTip->nHeight, | ||||
pindexBestForkTip->phashBlock->ToString()); | pindexBestForkTip->phashBlock->ToString()); | ||||
▲ Show 20 Lines • Show All 1,120 Lines • ▼ Show 20 Lines | static void UpdateTip(const Config &config, CBlockIndex *pindexNew) { | ||||
g_mempool.AddTransactionsUpdated(1); | g_mempool.AddTransactionsUpdated(1); | ||||
{ | { | ||||
LOCK(g_best_block_mutex); | LOCK(g_best_block_mutex); | ||||
g_best_block = pindexNew->GetBlockHash(); | g_best_block = pindexNew->GetBlockHash(); | ||||
g_best_block_cv.notify_all(); | g_best_block_cv.notify_all(); | ||||
} | } | ||||
static bool fWarned = false; | |||||
std::vector<std::string> warningMessages; | std::vector<std::string> warningMessages; | ||||
if (!IsInitialBlockDownload()) { | if (!IsInitialBlockDownload()) { | ||||
int nUpgraded = 0; | int nUpgraded = 0; | ||||
const CBlockIndex *pindex = chainActive.Tip(); | const CBlockIndex *pindex = chainActive.Tip(); | ||||
// Check the version of the last 100 blocks to see if we need to | // Check the version of the last 100 blocks to see if we need to | ||||
// upgrade: | // upgrade: | ||||
for (int i = 0; i < 100 && pindex != nullptr; i++) { | for (int i = 0; i < 100 && pindex != nullptr; i++) { | ||||
Show All 11 Lines | if (!IsInitialBlockDownload()) { | ||||
} | } | ||||
if (nUpgraded > 100 / 2) { | if (nUpgraded > 100 / 2) { | ||||
std::string strWarning = | std::string strWarning = | ||||
_("Warning: Unknown block versions being mined! It's possible " | _("Warning: Unknown block versions being mined! It's possible " | ||||
"unknown rules are in effect"); | "unknown rules are in effect"); | ||||
// notify GetWarnings(), called by Qt and the JSON-RPC code to warn | // notify GetWarnings(), called by Qt and the JSON-RPC code to warn | ||||
// the user: | // the user: | ||||
SetMiscWarning(strWarning); | SetMiscWarning(strWarning); | ||||
if (!fWarned) { | |||||
AlertNotify(strWarning); | |||||
fWarned = true; | |||||
} | |||||
} | } | ||||
} | } | ||||
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | ||||
"date='%s' progress=%f cache=%.1fMiB(%utxo)", | "date='%s' progress=%f cache=%.1fMiB(%utxo)", | ||||
__func__, chainActive.Tip()->GetBlockHash().ToString(), | __func__, chainActive.Tip()->GetBlockHash().ToString(), | ||||
chainActive.Height(), chainActive.Tip()->nVersion, | chainActive.Height(), chainActive.Tip()->nVersion, | ||||
log(chainActive.Tip()->nChainWork.getdouble()) / log(2.0), | log(chainActive.Tip()->nChainWork.getdouble()) / log(2.0), | ||||
(unsigned long)chainActive.Tip()->nChainTx, | (unsigned long)chainActive.Tip()->nChainTx, | ||||
▲ Show 20 Lines • Show All 3,395 Lines • Show Last 20 Lines |