Move pindexBestInvalid to ChainstateManager
A private member is better than a global.
This commit is contained in:
2 files changed
+16
-15
No files matched your search
+13
-15
@@ -133,11 +133,6 @@ arith_uint256 nMinimumChainWork;
|
|||||||
|
|
||||||
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
||||||
|
|
||||||
// Internal stuff
|
|
||||||
namespace {
|
|
||||||
CBlockIndex* pindexBestInvalid = nullptr;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// Internal stuff from blockstorage ...
|
// Internal stuff from blockstorage ...
|
||||||
extern RecursiveMutex cs_LastBlockFile;
|
extern RecursiveMutex cs_LastBlockFile;
|
||||||
extern std::vector<CBlockFileInfo> vinfoBlockFile;
|
extern std::vector<CBlockFileInfo> vinfoBlockFile;
|
||||||
@@ -1257,7 +1252,7 @@ void CChainState::CheckForkWarningConditions()
|
|||||||
return;
|
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__);
|
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
||||||
SetfLargeWorkInvalidChainFound(true);
|
SetfLargeWorkInvalidChainFound(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1268,8 +1263,9 @@ void CChainState::CheckForkWarningConditions()
|
|||||||
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
// Called both upon regular invalid block discovery *and* InvalidateBlock
|
||||||
void CChainState::InvalidChainFound(CBlockIndex* pindexNew)
|
void CChainState::InvalidChainFound(CBlockIndex* pindexNew)
|
||||||
{
|
{
|
||||||
if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork)
|
if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork) {
|
||||||
pindexBestInvalid = pindexNew;
|
m_chainman.m_best_invalid = pindexNew;
|
||||||
|
}
|
||||||
if (pindexBestHeader != nullptr && pindexBestHeader->GetAncestor(pindexNew->nHeight) == pindexNew) {
|
if (pindexBestHeader != nullptr && pindexBestHeader->GetAncestor(pindexNew->nHeight) == pindexNew) {
|
||||||
pindexBestHeader = m_chain.Tip();
|
pindexBestHeader = m_chain.Tip();
|
||||||
}
|
}
|
||||||
@@ -2432,8 +2428,9 @@ CBlockIndex* CChainState::FindMostWorkChain() {
|
|||||||
bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA);
|
bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA);
|
||||||
if (fFailedChain || fMissingData) {
|
if (fFailedChain || fMissingData) {
|
||||||
// Candidate chain is not usable (either invalid or missing data)
|
// Candidate chain is not usable (either invalid or missing data)
|
||||||
if (fFailedChain && (pindexBestInvalid == nullptr || pindexNew->nChainWork > pindexBestInvalid->nChainWork))
|
if (fFailedChain && (m_chainman.m_best_invalid == nullptr || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork)) {
|
||||||
pindexBestInvalid = pindexNew;
|
m_chainman.m_best_invalid = pindexNew;
|
||||||
|
}
|
||||||
CBlockIndex *pindexFailed = pindexNew;
|
CBlockIndex *pindexFailed = pindexNew;
|
||||||
// Remove the entire chain from the set.
|
// Remove the entire chain from the set.
|
||||||
while (pindexTest != pindexFailed) {
|
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)) {
|
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), it->second)) {
|
||||||
setBlockIndexCandidates.insert(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.
|
// 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);
|
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))
|
if (pindex->nStatus & BLOCK_FAILED_MASK && (!chainman.m_best_invalid || pindex->nChainWork > chainman.m_best_invalid->nChainWork)) {
|
||||||
pindexBestInvalid = pindex;
|
chainman.m_best_invalid = pindex;
|
||||||
|
}
|
||||||
if (pindex->pprev)
|
if (pindex->pprev)
|
||||||
pindex->BuildSkip();
|
pindex->BuildSkip();
|
||||||
if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator()(pindexBestHeader, pindex)))
|
if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator()(pindexBestHeader, pindex)))
|
||||||
@@ -4141,7 +4139,6 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
chainman.Unload();
|
chainman.Unload();
|
||||||
pindexBestInvalid = nullptr;
|
|
||||||
pindexBestHeader = nullptr;
|
pindexBestHeader = nullptr;
|
||||||
if (mempool) mempool->clear();
|
if (mempool) mempool->clear();
|
||||||
vinfoBlockFile.clear();
|
vinfoBlockFile.clear();
|
||||||
@@ -5120,6 +5117,7 @@ void ChainstateManager::Unload()
|
|||||||
|
|
||||||
m_failed_blocks.clear();
|
m_failed_blocks.clear();
|
||||||
m_blockman.Unload();
|
m_blockman.Unload();
|
||||||
|
m_best_invalid = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChainstateManager::Reset()
|
void ChainstateManager::Reset()
|
||||||
|
|||||||
@@ -866,6 +866,9 @@ private:
|
|||||||
//! by the background validation chainstate.
|
//! by the background validation chainstate.
|
||||||
bool m_snapshot_validated{false};
|
bool m_snapshot_validated{false};
|
||||||
|
|
||||||
|
CBlockIndex* m_best_invalid;
|
||||||
|
friend bool BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
|
||||||
|
|
||||||
//! Internal helper for ActivateSnapshot().
|
//! Internal helper for ActivateSnapshot().
|
||||||
[[nodiscard]] bool PopulateAndValidateSnapshot(
|
[[nodiscard]] bool PopulateAndValidateSnapshot(
|
||||||
CChainState& snapshot_chainstate,
|
CChainState& snapshot_chainstate,
|
||||||
|
|||||||
Reference in new issue
Block a user