mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Make blockstorage globals private members of BlockManager
This commit is contained in:
@@ -133,16 +133,6 @@ arith_uint256 nMinimumChainWork;
|
||||
|
||||
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
||||
|
||||
// Internal stuff from blockstorage ...
|
||||
extern RecursiveMutex cs_LastBlockFile;
|
||||
extern std::vector<CBlockFileInfo> vinfoBlockFile;
|
||||
extern int nLastBlockFile;
|
||||
extern bool fCheckForPruning;
|
||||
extern std::set<CBlockIndex*> setDirtyBlockIndex;
|
||||
extern std::set<int> setDirtyFileInfo;
|
||||
void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false);
|
||||
// ... TODO move fully to blockstorage
|
||||
|
||||
CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
@@ -1505,7 +1495,7 @@ void CChainState::InvalidBlockFound(CBlockIndex* pindex, const BlockValidationSt
|
||||
if (state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
|
||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||
m_chainman.m_failed_blocks.insert(pindex);
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
m_blockman.setDirtyBlockIndex.insert(pindex);
|
||||
setBlockIndexCandidates.erase(pindex);
|
||||
InvalidChainFound(pindex);
|
||||
}
|
||||
@@ -2141,7 +2131,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
|
||||
if (!pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
|
||||
pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
m_blockman.setDirtyBlockIndex.insert(pindex);
|
||||
}
|
||||
|
||||
assert(pindex->phashBlock);
|
||||
@@ -2214,8 +2204,8 @@ bool CChainState::FlushStateToDisk(
|
||||
bool fDoFullFlush = false;
|
||||
|
||||
CoinsCacheSizeState cache_state = GetCoinsCacheSizeState();
|
||||
LOCK(cs_LastBlockFile);
|
||||
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
|
||||
LOCK(m_blockman.cs_LastBlockFile);
|
||||
if (fPruneMode && (m_blockman.fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
|
||||
// make sure we don't prune above the blockfilterindexes bestblocks
|
||||
// pruning is height-based
|
||||
int last_prune = m_chain.Height(); // last height we can prune
|
||||
@@ -2231,7 +2221,7 @@ bool CChainState::FlushStateToDisk(
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
|
||||
|
||||
m_blockman.FindFilesToPrune(setFilesToPrune, m_params.PruneAfterHeight(), m_chain.Height(), last_prune, IsInitialBlockDownload());
|
||||
fCheckForPruning = false;
|
||||
m_blockman.fCheckForPruning = false;
|
||||
}
|
||||
if (!setFilesToPrune.empty()) {
|
||||
fFlushForPrune = true;
|
||||
@@ -2336,7 +2326,7 @@ void CChainState::ForceFlushStateToDisk()
|
||||
void CChainState::PruneAndFlush()
|
||||
{
|
||||
BlockValidationState state;
|
||||
fCheckForPruning = true;
|
||||
m_blockman.fCheckForPruning = true;
|
||||
if (!this->FlushStateToDisk(state, FlushStateMode::NONE)) {
|
||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, state.ToString());
|
||||
}
|
||||
@@ -3006,14 +2996,14 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
|
||||
// are no blocks that meet the "have data and are not invalid per
|
||||
// nStatus" criteria for inclusion in setBlockIndexCandidates).
|
||||
invalid_walk_tip->nStatus |= BLOCK_FAILED_VALID;
|
||||
setDirtyBlockIndex.insert(invalid_walk_tip);
|
||||
m_blockman.setDirtyBlockIndex.insert(invalid_walk_tip);
|
||||
setBlockIndexCandidates.erase(invalid_walk_tip);
|
||||
setBlockIndexCandidates.insert(invalid_walk_tip->pprev);
|
||||
if (invalid_walk_tip->pprev == to_mark_failed && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) {
|
||||
// We only want to mark the last disconnected block as BLOCK_FAILED_VALID; its children
|
||||
// need to be BLOCK_FAILED_CHILD instead.
|
||||
to_mark_failed->nStatus = (to_mark_failed->nStatus ^ BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
|
||||
setDirtyBlockIndex.insert(to_mark_failed);
|
||||
m_blockman.setDirtyBlockIndex.insert(to_mark_failed);
|
||||
}
|
||||
|
||||
// Add any equal or more work headers to setBlockIndexCandidates
|
||||
@@ -3043,7 +3033,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
|
||||
|
||||
// Mark pindex (or the last disconnected block) as invalid, even when it never was in the main chain
|
||||
to_mark_failed->nStatus |= BLOCK_FAILED_VALID;
|
||||
setDirtyBlockIndex.insert(to_mark_failed);
|
||||
m_blockman.setDirtyBlockIndex.insert(to_mark_failed);
|
||||
setBlockIndexCandidates.erase(to_mark_failed);
|
||||
m_chainman.m_failed_blocks.insert(to_mark_failed);
|
||||
|
||||
@@ -3082,7 +3072,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
while (it != m_blockman.m_block_index.end()) {
|
||||
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
||||
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(it->second);
|
||||
m_blockman.setDirtyBlockIndex.insert(it->second);
|
||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), it->second)) {
|
||||
setBlockIndexCandidates.insert(it->second);
|
||||
}
|
||||
@@ -3099,7 +3089,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
while (pindex != nullptr) {
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK) {
|
||||
pindex->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
m_blockman.setDirtyBlockIndex.insert(pindex);
|
||||
m_chainman.m_failed_blocks.erase(pindex);
|
||||
}
|
||||
pindex = pindex->pprev;
|
||||
@@ -3119,7 +3109,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
|
||||
pindexNew->nStatus |= BLOCK_OPT_WITNESS;
|
||||
}
|
||||
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
|
||||
setDirtyBlockIndex.insert(pindexNew);
|
||||
m_blockman.setDirtyBlockIndex.insert(pindexNew);
|
||||
|
||||
if (pindexNew->pprev == nullptr || pindexNew->pprev->HaveTxsDownloaded()) {
|
||||
// If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS.
|
||||
@@ -3481,7 +3471,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
|
||||
CBlockIndex* invalid_walk = pindexPrev;
|
||||
while (invalid_walk != failedit) {
|
||||
invalid_walk->nStatus |= BLOCK_FAILED_CHILD;
|
||||
setDirtyBlockIndex.insert(invalid_walk);
|
||||
m_blockman.setDirtyBlockIndex.insert(invalid_walk);
|
||||
invalid_walk = invalid_walk->pprev;
|
||||
}
|
||||
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
|
||||
@@ -3579,7 +3569,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
|
||||
!ContextualCheckBlock(block, state, m_params.GetConsensus(), pindex->pprev)) {
|
||||
if (state.IsInvalid() && state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
|
||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
m_blockman.setDirtyBlockIndex.insert(pindex);
|
||||
}
|
||||
return error("%s: %s", __func__, state.ToString());
|
||||
}
|
||||
@@ -4914,7 +4904,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
||||
index->nStatus |= BLOCK_OPT_WITNESS;
|
||||
}
|
||||
|
||||
setDirtyBlockIndex.insert(index);
|
||||
m_blockman.setDirtyBlockIndex.insert(index);
|
||||
// Changes to the block index will be flushed to disk after this call
|
||||
// returns in `ActivateSnapshot()`, when `MaybeRebalanceCaches()` is
|
||||
// called, since we've added a snapshot chainstate and therefore will
|
||||
|
||||
Reference in New Issue
Block a user