mirror of https://github.com/bitcoin/bitcoin.git
Remove dead CheckForkWarningConditionsOnNewFork
This commit is contained in:
parent
218fe60d91
commit
fa62304c97
|
@ -1312,8 +1312,6 @@ bool CChainState::IsInitialBlockDownload() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
|
|
||||||
|
|
||||||
static void AlertNotify(const std::string& strMessage)
|
static void AlertNotify(const std::string& strMessage)
|
||||||
{
|
{
|
||||||
uiInterface.NotifyAlertChanged();
|
uiInterface.NotifyAlertChanged();
|
||||||
|
@ -1342,72 +1340,17 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||||
if (::ChainstateActive().IsInitialBlockDownload())
|
if (::ChainstateActive().IsInitialBlockDownload())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If our best fork is no longer within 72 blocks (+/- 12 hours if no one mines it)
|
if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive().Tip()->nChainWork + (GetBlockProof(*::ChainActive().Tip()) * 6))
|
||||||
// of our head, drop it
|
|
||||||
if (pindexBestForkTip && ::ChainActive().Height() - pindexBestForkTip->nHeight >= 72)
|
|
||||||
pindexBestForkTip = nullptr;
|
|
||||||
|
|
||||||
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive().Tip()->nChainWork + (GetBlockProof(*::ChainActive().Tip()) * 6)))
|
|
||||||
{
|
{
|
||||||
if (!GetfLargeWorkForkFound() && pindexBestForkBase)
|
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
||||||
{
|
SetfLargeWorkInvalidChainFound(true);
|
||||||
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
|
|
||||||
pindexBestForkBase->phashBlock->ToString() + std::string("'");
|
|
||||||
AlertNotify(warning);
|
|
||||||
}
|
|
||||||
if (pindexBestForkTip && pindexBestForkBase)
|
|
||||||
{
|
|
||||||
LogPrintf("%s: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\nChain state database corruption likely.\n", __func__,
|
|
||||||
pindexBestForkBase->nHeight, pindexBestForkBase->phashBlock->ToString(),
|
|
||||||
pindexBestForkTip->nHeight, pindexBestForkTip->phashBlock->ToString());
|
|
||||||
SetfLargeWorkForkFound(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
|
||||||
SetfLargeWorkInvalidChainFound(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetfLargeWorkForkFound(false);
|
|
||||||
SetfLargeWorkInvalidChainFound(false);
|
SetfLargeWorkInvalidChainFound(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|
||||||
{
|
|
||||||
AssertLockHeld(cs_main);
|
|
||||||
// If we are on a fork that is sufficiently large, set a warning flag
|
|
||||||
CBlockIndex* pfork = pindexNewForkTip;
|
|
||||||
CBlockIndex* plonger = ::ChainActive().Tip();
|
|
||||||
while (pfork && pfork != plonger)
|
|
||||||
{
|
|
||||||
while (plonger && plonger->nHeight > pfork->nHeight)
|
|
||||||
plonger = plonger->pprev;
|
|
||||||
if (pfork == plonger)
|
|
||||||
break;
|
|
||||||
pfork = pfork->pprev;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We define a condition where we should warn the user about as a fork of at least 7 blocks
|
|
||||||
// with a tip within 72 blocks (+/- 12 hours if no one mines it) of ours
|
|
||||||
// We use 7 blocks rather arbitrarily as it represents just under 10% of sustained network
|
|
||||||
// hash rate operating on the fork.
|
|
||||||
// or a chain that is entirely longer than ours and invalid (note that this should be detected by both)
|
|
||||||
// We define it this way because it allows us to only store the highest fork tip (+ base) which meets
|
|
||||||
// the 7-block condition and from this always have the most-likely-to-cause-warning fork
|
|
||||||
if (pfork && (!pindexBestForkTip || pindexNewForkTip->nHeight > pindexBestForkTip->nHeight) &&
|
|
||||||
pindexNewForkTip->nChainWork - pfork->nChainWork > (GetBlockProof(*pfork) * 7) &&
|
|
||||||
::ChainActive().Height() - pindexNewForkTip->nHeight < 72)
|
|
||||||
{
|
|
||||||
pindexBestForkTip = pindexNewForkTip;
|
|
||||||
pindexBestForkBase = pfork;
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckForkWarningConditions();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
||||||
void static InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
void static InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||||
{
|
{
|
||||||
|
@ -2821,11 +2764,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
|
||||||
}
|
}
|
||||||
m_mempool.check(&CoinsTip());
|
m_mempool.check(&CoinsTip());
|
||||||
|
|
||||||
// Callbacks/notifications for a new best chain.
|
CheckForkWarningConditions();
|
||||||
if (fInvalidFound)
|
|
||||||
CheckForkWarningConditionsOnNewFork(vpindexToConnect.back());
|
|
||||||
else
|
|
||||||
CheckForkWarningConditions();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
static Mutex g_warnings_mutex;
|
static Mutex g_warnings_mutex;
|
||||||
static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
|
static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
|
||||||
static bool fLargeWorkForkFound GUARDED_BY(g_warnings_mutex) = false;
|
|
||||||
static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
|
static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
|
||||||
|
|
||||||
void SetMiscWarning(const bilingual_str& warning)
|
void SetMiscWarning(const bilingual_str& warning)
|
||||||
|
@ -23,18 +22,6 @@ void SetMiscWarning(const bilingual_str& warning)
|
||||||
g_misc_warnings = warning;
|
g_misc_warnings = warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetfLargeWorkForkFound(bool flag)
|
|
||||||
{
|
|
||||||
LOCK(g_warnings_mutex);
|
|
||||||
fLargeWorkForkFound = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetfLargeWorkForkFound()
|
|
||||||
{
|
|
||||||
LOCK(g_warnings_mutex);
|
|
||||||
return fLargeWorkForkFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetfLargeWorkInvalidChainFound(bool flag)
|
void SetfLargeWorkInvalidChainFound(bool flag)
|
||||||
{
|
{
|
||||||
LOCK(g_warnings_mutex);
|
LOCK(g_warnings_mutex);
|
||||||
|
@ -60,10 +47,7 @@ bilingual_str GetWarnings(bool verbose)
|
||||||
warnings_verbose.emplace_back(warnings_concise);
|
warnings_verbose.emplace_back(warnings_concise);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fLargeWorkForkFound) {
|
if (fLargeWorkInvalidChainFound) {
|
||||||
warnings_concise = _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
|
|
||||||
warnings_verbose.emplace_back(warnings_concise);
|
|
||||||
} else if (fLargeWorkInvalidChainFound) {
|
|
||||||
warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
|
warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
|
||||||
warnings_verbose.emplace_back(warnings_concise);
|
warnings_verbose.emplace_back(warnings_concise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
|
||||||
void SetMiscWarning(const bilingual_str& warning);
|
void SetMiscWarning(const bilingual_str& warning);
|
||||||
void SetfLargeWorkForkFound(bool flag);
|
|
||||||
bool GetfLargeWorkForkFound();
|
|
||||||
void SetfLargeWorkInvalidChainFound(bool flag);
|
void SetfLargeWorkInvalidChainFound(bool flag);
|
||||||
/** Format a string that describes several potential problems detected by the core.
|
/** Format a string that describes several potential problems detected by the core.
|
||||||
* @param[in] verbose bool
|
* @param[in] verbose bool
|
||||||
|
|
Loading…
Reference in New Issue