mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Move pindexBestInvalid to ChainstateManager
A private member is better than a global.
This commit is contained in:
parent
facd2137ec
commit
fab6d6b2d1
2 changed files with 16 additions and 15 deletions
|
@ -133,11 +133,6 @@ arith_uint256 nMinimumChainWork;
|
|||
|
||||
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
||||
|
||||
// Internal stuff
|
||||
namespace {
|
||||
CBlockIndex* pindexBestInvalid = nullptr;
|
||||
} // namespace
|
||||
|
||||
// Internal stuff from blockstorage ...
|
||||
extern RecursiveMutex cs_LastBlockFile;
|
||||
extern std::vector<CBlockFileInfo> vinfoBlockFile;
|
||||
|
@ -1257,7 +1252,7 @@ void CChainState::CheckForkWarningConditions()
|
|||
return;
|
||||
}
|
||||
|
||||
if (pindexBestInvalid && pindexBestInvalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
|
||||
if (m_chainman.m_best_invalid && m_chainman.m_best_invalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
|
||||
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 {
|
||||
|
@ -1268,8 +1263,9 @@ void CChainState::CheckForkWarningConditions()
|
|||
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
||||
void CChainState::InvalidChainFound(CBlockIndex* pindexNew)
|
||||
{
|
||||
if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork)
|
||||
pindexBestInvalid = pindexNew;
|
||||
if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork) {
|
||||
m_chainman.m_best_invalid = pindexNew;
|
||||
}
|
||||
if (pindexBestHeader != nullptr && pindexBestHeader->GetAncestor(pindexNew->nHeight) == pindexNew) {
|
||||
pindexBestHeader = m_chain.Tip();
|
||||
}
|
||||
|
@ -2432,8 +2428,9 @@ CBlockIndex* CChainState::FindMostWorkChain() {
|
|||
bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA);
|
||||
if (fFailedChain || fMissingData) {
|
||||
// Candidate chain is not usable (either invalid or missing data)
|
||||
if (fFailedChain && (pindexBestInvalid == nullptr || pindexNew->nChainWork > pindexBestInvalid->nChainWork))
|
||||
pindexBestInvalid = pindexNew;
|
||||
if (fFailedChain && (m_chainman.m_best_invalid == nullptr || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork)) {
|
||||
m_chainman.m_best_invalid = pindexNew;
|
||||
}
|
||||
CBlockIndex *pindexFailed = pindexNew;
|
||||
// Remove the entire chain from the set.
|
||||
while (pindexTest != pindexFailed) {
|
||||
|
@ -2885,9 +2882,9 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
|||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), it->second)) {
|
||||
setBlockIndexCandidates.insert(it->second);
|
||||
}
|
||||
if (it->second == pindexBestInvalid) {
|
||||
if (it->second == m_chainman.m_best_invalid) {
|
||||
// Reset invalid block marker if it was pointing to one of those.
|
||||
pindexBestInvalid = nullptr;
|
||||
m_chainman.m_best_invalid = nullptr;
|
||||
}
|
||||
m_chainman.m_failed_blocks.erase(it->second);
|
||||
}
|
||||
|
@ -3792,8 +3789,9 @@ bool BlockManager::LoadBlockIndex(
|
|||
}
|
||||
}
|
||||
}
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
|
||||
pindexBestInvalid = pindex;
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK && (!chainman.m_best_invalid || pindex->nChainWork > chainman.m_best_invalid->nChainWork)) {
|
||||
chainman.m_best_invalid = pindex;
|
||||
}
|
||||
if (pindex->pprev)
|
||||
pindex->BuildSkip();
|
||||
if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator()(pindexBestHeader, pindex)))
|
||||
|
@ -4141,7 +4139,6 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
|
|||
{
|
||||
LOCK(cs_main);
|
||||
chainman.Unload();
|
||||
pindexBestInvalid = nullptr;
|
||||
pindexBestHeader = nullptr;
|
||||
if (mempool) mempool->clear();
|
||||
vinfoBlockFile.clear();
|
||||
|
@ -5120,6 +5117,7 @@ void ChainstateManager::Unload()
|
|||
|
||||
m_failed_blocks.clear();
|
||||
m_blockman.Unload();
|
||||
m_best_invalid = nullptr;
|
||||
}
|
||||
|
||||
void ChainstateManager::Reset()
|
||||
|
|
|
@ -866,6 +866,9 @@ private:
|
|||
//! by the background validation chainstate.
|
||||
bool m_snapshot_validated{false};
|
||||
|
||||
CBlockIndex* m_best_invalid;
|
||||
friend bool BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
|
||||
|
||||
//! Internal helper for ActivateSnapshot().
|
||||
[[nodiscard]] bool PopulateAndValidateSnapshot(
|
||||
CChainState& snapshot_chainstate,
|
||||
|
|
Loading…
Add table
Reference in a new issue