Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | private: | ||||
bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, | bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, | ||||
CBlockIndex *pindexNew, | CBlockIndex *pindexNew, | ||||
const FlatFilePos &pos) | const FlatFilePos &pos) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs, | bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs, | ||||
const Consensus::Params ¶ms) | const Consensus::Params ¶ms) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
//! Mark a block as not having block data | |||||
void EraseBlockData(CBlockIndex *index) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | |||||
} g_chainstate; | } g_chainstate; | ||||
/** | /** | ||||
* Global state | * Global state | ||||
* | * | ||||
* Mutex to guard access to validation specific variables, such as reading | * Mutex to guard access to validation specific variables, such as reading | ||||
* or changing the chainstate. | * or changing the chainstate. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 4,695 Lines • ▼ Show 20 Lines | bool CChainState::ReplayBlocks(const Consensus::Params ¶ms, | ||||
uiInterface.ShowProgress("", 100, false); | uiInterface.ShowProgress("", 100, false); | ||||
return true; | return true; | ||||
} | } | ||||
bool ReplayBlocks(const Consensus::Params ¶ms, CCoinsView *view) { | bool ReplayBlocks(const Consensus::Params ¶ms, CCoinsView *view) { | ||||
return g_chainstate.ReplayBlocks(params, view); | return g_chainstate.ReplayBlocks(params, view); | ||||
} | } | ||||
//! Helper for CChainState::RewindBlockIndex | |||||
void CChainState::EraseBlockData(CBlockIndex *index) { | |||||
AssertLockHeld(cs_main); | |||||
// Make sure this block isn't active | |||||
assert(!chainActive.Contains(index)); | |||||
// Reduce validity | |||||
index->nStatus = index->nStatus.withValidity( | |||||
std::min(index->nStatus.getValidity(), BlockValidity::TREE)); | |||||
// Remove have-data flags. | |||||
index->nStatus = index->nStatus.withData(false).withUndo(false); | |||||
// Remove storage location. | |||||
index->nFile = 0; | |||||
index->nDataPos = 0; | |||||
index->nUndoPos = 0; | |||||
// Remove various other things | |||||
index->nTx = 0; | |||||
index->nChainTx = 0; | |||||
index->nSequenceId = 0; | |||||
// Make sure it gets written. | |||||
setDirtyBlockIndex.insert(index); | |||||
// Update indexes | |||||
setBlockIndexCandidates.erase(index); | |||||
std::pair<std::multimap<CBlockIndex *, CBlockIndex *>::iterator, | |||||
std::multimap<CBlockIndex *, CBlockIndex *>::iterator> | |||||
ret = mapBlocksUnlinked.equal_range(index->pprev); | |||||
while (ret.first != ret.second) { | |||||
if (ret.first->second == index) { | |||||
mapBlocksUnlinked.erase(ret.first++); | |||||
} else { | |||||
++ret.first; | |||||
} | |||||
} | |||||
// Mark parent as eligible for main chain again | |||||
if (index->pprev && index->pprev->IsValid(BlockValidity::TRANSACTIONS) && | |||||
index->pprev->HaveTxsDownloaded()) { | |||||
setBlockIndexCandidates.insert(index->pprev); | |||||
} | |||||
} | |||||
bool CChainState::RewindBlockIndex(const Config &config) { | bool CChainState::RewindBlockIndex(const Config &config) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
int nHeight = chainActive.Height() + 1; | int nHeight = chainActive.Height() + 1; | ||||
// nHeight is now the height of the first insufficiently-validated block, or | // nHeight is now the height of the first insufficiently-validated block, or | ||||
// tipheight + 1 | // tipheight + 1 | ||||
▲ Show 20 Lines • Show All 845 Lines • Show Last 20 Lines |