Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show All 33 Lines | |||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
#include "versionbits.h" | #include "versionbits.h" | ||||
#include "warnings.h" | #include "warnings.h" | ||||
#include <atomic> | #include <atomic> | ||||
#include <set> | |||||
#include <sstream> | #include <sstream> | ||||
#include <boost/algorithm/string/join.hpp> | #include <boost/algorithm/string/join.hpp> | ||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <boost/filesystem.hpp> | #include <boost/filesystem.hpp> | ||||
#include <boost/filesystem/fstream.hpp> | #include <boost/filesystem/fstream.hpp> | ||||
#include <boost/math/distributions/poisson.hpp> | #include <boost/math/distributions/poisson.hpp> | ||||
#include <boost/range/adaptor/reversed.hpp> | #include <boost/range/adaptor/reversed.hpp> | ||||
▲ Show 20 Lines • Show All 1,083 Lines • ▼ Show 20 Lines | |||||
void CheckForkWarningConditions() { | 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()) return; | if (IsInitialBlockDownload()) return; | ||||
if (pindexBestForkTip || pindexBestForkBase || pindexBestInvalid) | |||||
LogPrintf("DEBUG CALIN - " | |||||
"pindexBestInvalid->nHeight=%d / " | |||||
"pindexBestForkTip->nHeight=%d / " | |||||
"chainActive.Height()=%d / " | |||||
"pindexBestForkBase->nHeight=%d / " | |||||
"(pibi->hash=%s pbft->hash=%s pbfb->hash=%s)\n", | |||||
pindexBestInvalid ? pindexBestInvalid->nHeight : 0, | |||||
pindexBestForkTip ? pindexBestForkTip->nHeight : 0, | |||||
chainActive.Height(), | |||||
pindexBestForkBase ? pindexBestForkBase->nHeight : 0, | |||||
pindexBestInvalid ? pindexBestInvalid->phashBlock->ToString() | |||||
: std::string(""), | |||||
pindexBestForkTip ? pindexBestForkTip->phashBlock->ToString() | |||||
: std::string(""), | |||||
pindexBestForkBase | |||||
? pindexBestForkBase->phashBlock->ToString() | |||||
: std::string("") | |||||
); | |||||
// 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) { | if (!GetfLargeWorkForkFound() && pindexBestForkBase) { | ||||
std::string warning = | std::string warning = | ||||
std::string("'Warning: Large-work fork detected, forking after " | std::string("'Warning: Large-work fork detected, " | ||||
"block ") + | "forking after block ") + | ||||
pindexBestForkBase->phashBlock->ToString() + std::string("'"); | pindexBestForkBase->phashBlock->ToString() + std::string("'"); | ||||
AlertNotify(warning); | AlertNotify(warning); | ||||
} | } | ||||
if (pindexBestForkTip && pindexBestForkBase) { | if (pindexBestForkTip && pindexBestForkBase) { | ||||
LogPrintf("%s: Warning: Large valid fork found\n forking the " | LogPrintf("%s: Warning: Large valid 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()); | ||||
SetfLargeWorkForkFound(true); | SetfLargeWorkForkFound(true); | ||||
} else { | } else { | ||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks " | const CBlockIndex *forkBase = | ||||
"longer than our best chain.\nChain state database " | pindexBestInvalid ? chainActive.FindFork(pindexBestInvalid) | ||||
"corruption likely.\n", | : nullptr; | ||||
const CBlockIndex *chkPt = | |||||
Checkpoints::GetLastCheckpoint(Params().Checkpoints()); | |||||
if (forkBase && chkPt && forkBase->nHeight < chkPt->nHeight) { | |||||
static std::set<int> warnedForks; | |||||
SetfLargeWorkInvalidChainFound(false); | |||||
if (!warnedForks.count(forkBase->nHeight)) { | |||||
LogPrintf("%s: Found a long fork chain at least ~6 blocks " | |||||
"longer than our best chain at height %d, " | |||||
"however since it is behind a checkpoint at %d, " | |||||
"this is the legacy chain (ignoring).\n", | |||||
__func__, forkBase->nHeight, chkPt->nHeight); | |||||
warnedForks.insert(forkBase->nHeight); | |||||
} | |||||
} else { | |||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 " | |||||
"blocks longer than our best chain.\n" | |||||
"Chain state database corruption likely.\n", | |||||
__func__); | __func__); | ||||
SetfLargeWorkInvalidChainFound(true); | SetfLargeWorkInvalidChainFound(true); | ||||
} | } | ||||
} | |||||
} else { | } else { | ||||
SetfLargeWorkForkFound(false); | SetfLargeWorkForkFound(false); | ||||
SetfLargeWorkInvalidChainFound(false); | SetfLargeWorkInvalidChainFound(false); | ||||
} | } | ||||
} | } | ||||
void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip) { | void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
▲ Show 20 Lines • Show All 3,779 Lines • Show Last 20 Lines |