mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#19905: Remove dead CheckForkWarningConditionsOnNewFork
This commit is contained in:
parent
bd00a6a2e8
commit
bce9b6bc97
@ -1340,8 +1340,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();
|
||||||
@ -1367,82 +1365,18 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|||||||
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 sync)
|
// (we assume we don't get stuck on a fork before finishing our initial sync)
|
||||||
if (::ChainstateActive().IsInitialBlockDownload())
|
if (::ChainstateActive().IsInitialBlockDownload()) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If our best fork is no longer within 72 blocks (+/- 3 hours if no one mines it)
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
if(pindexBestForkBase->phashBlock){
|
|
||||||
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
|
|
||||||
pindexBestForkBase->phashBlock->ToString() + std::string("'");
|
|
||||||
AlertNotify(warning);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pindexBestForkTip && pindexBestForkBase)
|
|
||||||
{
|
|
||||||
if(pindexBestForkBase->phashBlock){
|
|
||||||
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
|
|
||||||
{
|
|
||||||
if(pindexBestInvalid->nHeight > ::ChainActive().Height() + 6)
|
|
||||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
|
||||||
else
|
|
||||||
LogPrintf("%s: Warning: Found invalid chain which has higher work (at least ~6 blocks worth of work) than our best chain.\nChain state database corruption likely.\n", __func__);
|
|
||||||
SetfLargeWorkInvalidChainFound(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive().Tip()->nChainWork + (GetBlockProof(*::ChainActive().Tip()) * 6)) {
|
||||||
SetfLargeWorkForkFound(false);
|
LogPrintf("%s: Warning: Found invalid chain which has higher work (at least ~6 blocks worth of work) than our best chain.\nChain state database corruption likely.\n", __func__);
|
||||||
|
SetfLargeWorkInvalidChainFound(true);
|
||||||
|
} else {
|
||||||
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 (+/- 3 hours if no one mines it) of ours
|
|
||||||
// or a chain that is entirely longer than ours and invalid (note that this should be detected by both)
|
|
||||||
// We use 7 blocks rather arbitrarily as it represents just under 10% of sustained network
|
|
||||||
// hash rate operating on the fork.
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
@ -3094,8 +3028,8 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
|
|||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
AssertLockHeld(m_mempool.cs);
|
AssertLockHeld(m_mempool.cs);
|
||||||
|
|
||||||
const CBlockIndex *pindexOldTip = m_chain.Tip();
|
const CBlockIndex* pindexOldTip = m_chain.Tip();
|
||||||
const CBlockIndex *pindexFork = m_chain.FindFork(pindexMostWork);
|
const CBlockIndex* pindexFork = m_chain.FindFork(pindexMostWork);
|
||||||
|
|
||||||
// Disconnect active blocks which are no longer in the best chain.
|
// Disconnect active blocks which are no longer in the best chain.
|
||||||
bool fBlocksDisconnected = false;
|
bool fBlocksDisconnected = false;
|
||||||
@ -3115,7 +3049,7 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
|
|||||||
fBlocksDisconnected = true;
|
fBlocksDisconnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build list of new blocks to connect.
|
// Build list of new blocks to connect (in descending height order).
|
||||||
std::vector<CBlockIndex*> vpindexToConnect;
|
std::vector<CBlockIndex*> vpindexToConnect;
|
||||||
bool fContinue = true;
|
bool fContinue = true;
|
||||||
int nHeight = pindexFork ? pindexFork->nHeight : -1;
|
int nHeight = pindexFork ? pindexFork->nHeight : -1;
|
||||||
@ -3125,7 +3059,7 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
|
|||||||
int nTargetHeight = std::min(nHeight + 32, pindexMostWork->nHeight);
|
int nTargetHeight = std::min(nHeight + 32, pindexMostWork->nHeight);
|
||||||
vpindexToConnect.clear();
|
vpindexToConnect.clear();
|
||||||
vpindexToConnect.reserve(nTargetHeight - nHeight);
|
vpindexToConnect.reserve(nTargetHeight - nHeight);
|
||||||
CBlockIndex *pindexIter = pindexMostWork->GetAncestor(nTargetHeight);
|
CBlockIndex* pindexIter = pindexMostWork->GetAncestor(nTargetHeight);
|
||||||
while (pindexIter && pindexIter->nHeight != nHeight) {
|
while (pindexIter && pindexIter->nHeight != nHeight) {
|
||||||
vpindexToConnect.push_back(pindexIter);
|
vpindexToConnect.push_back(pindexIter);
|
||||||
pindexIter = pindexIter->pprev;
|
pindexIter = pindexIter->pprev;
|
||||||
@ -3133,7 +3067,7 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
|
|||||||
nHeight = nTargetHeight;
|
nHeight = nTargetHeight;
|
||||||
|
|
||||||
// Connect new blocks.
|
// Connect new blocks.
|
||||||
for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) {
|
for (CBlockIndex* pindexConnect : reverse_iterate(vpindexToConnect)) {
|
||||||
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
|
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
|
||||||
if (state.IsInvalid()) {
|
if (state.IsInvalid()) {
|
||||||
// The block violates a consensus rule.
|
// The block violates a consensus rule.
|
||||||
@ -3169,11 +3103,7 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
|
|||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
static Mutex g_warnings_mutex;
|
static Mutex g_warnings_mutex;
|
||||||
static std::string strMiscWarning GUARDED_BY(g_warnings_mutex);
|
static std::string strMiscWarning 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 std::string& strWarning)
|
void SetMiscWarning(const std::string& strWarning)
|
||||||
@ -21,18 +20,6 @@ void SetMiscWarning(const std::string& strWarning)
|
|||||||
strMiscWarning = strWarning;
|
strMiscWarning = strWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -59,10 +46,7 @@ std::string GetWarnings(bool verbose)
|
|||||||
warnings_verbose += (warnings_verbose.empty() ? "" : warning_separator) + strMiscWarning;
|
warnings_verbose += (warnings_verbose.empty() ? "" : warning_separator) + strMiscWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fLargeWorkForkFound) {
|
if (fLargeWorkInvalidChainFound) {
|
||||||
warnings_concise = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
|
|
||||||
warnings_verbose += (warnings_verbose.empty() ? "" : warning_separator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.").translated;
|
|
||||||
} 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 += (warnings_verbose.empty() ? "" : warning_separator) + _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.").translated;
|
warnings_verbose += (warnings_verbose.empty() ? "" : warning_separator) + _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.").translated;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void SetMiscWarning(const std::string& strWarning);
|
void SetMiscWarning(const std::string& strWarning);
|
||||||
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
Block a user