Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | public: | ||||
CBlockIndex *pindexBestParked = nullptr; | CBlockIndex *pindexBestParked = nullptr; | ||||
bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree); | bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree); | ||||
bool ActivateBestChain( | bool ActivateBestChain( | ||||
const Config &config, CValidationState &state, | const Config &config, CValidationState &state, | ||||
std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>()); | std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>()); | ||||
/** | |||||
* If a block header hasn't already been seen, call CheckBlockHeader on it, | |||||
* ensure that it doesn't descend from an invalid block, and then add it to | |||||
* mapBlockIndex. | |||||
*/ | |||||
bool AcceptBlockHeader(const Config &config, const CBlockHeader &block, | bool AcceptBlockHeader(const Config &config, const CBlockHeader &block, | ||||
CValidationState &state, CBlockIndex **ppindex); | CValidationState &state, CBlockIndex **ppindex); | ||||
bool AcceptBlock(const Config &config, | bool AcceptBlock(const Config &config, | ||||
const std::shared_ptr<const CBlock> &pblock, | const std::shared_ptr<const CBlock> &pblock, | ||||
CValidationState &state, bool fRequested, | CValidationState &state, bool fRequested, | ||||
const FlatFilePos *dbp, bool *fNewBlock); | const FlatFilePos *dbp, bool *fNewBlock); | ||||
// Block (dis)connection on a given view: | // Block (dis)connection on a given view: | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | bool ConnectTip(const Config &config, CValidationState &state, | ||||
ConnectTrace &connectTrace, | ConnectTrace &connectTrace, | ||||
DisconnectedBlockTransactions &disconnectpool) | DisconnectedBlockTransactions &disconnectpool) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
CBlockIndex *AddToBlockIndex(const CBlockHeader &block) | CBlockIndex *AddToBlockIndex(const CBlockHeader &block) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** Create a new block index entry for a given block hash */ | /** Create a new block index entry for a given block hash */ | ||||
CBlockIndex *InsertBlockIndex(const uint256 &hash); | CBlockIndex *InsertBlockIndex(const uint256 &hash); | ||||
/** | |||||
* Make various assertions about the state of the block index. | |||||
* | |||||
* By default this only executes fully when using the Regtest chain; see: | |||||
* fCheckBlockIndex. | |||||
*/ | |||||
void CheckBlockIndex(const Consensus::Params &consensusParams); | void CheckBlockIndex(const Consensus::Params &consensusParams); | ||||
void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) | void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
CBlockIndex *FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | CBlockIndex *FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, | bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, | ||||
CBlockIndex *pindexNew, | CBlockIndex *pindexNew, | ||||
const FlatFilePos &pos) | const FlatFilePos &pos) | ||||
▲ Show 20 Lines • Show All 2,653 Lines • ▼ Show 20 Lines | if (fNotify) { | ||||
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader); | uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Make the best chain active, in multiple steps. The result is either failure | * Make the best chain active, in multiple steps. The result is either failure | ||||
* or an activated best chain. pblock is either nullptr or a pointer to a block | * or an activated best chain. pblock is either nullptr or a pointer to a block | ||||
* that is already loaded (to avoid loading it again from disk). | * that is already loaded (to avoid loading it again from disk). | ||||
* | |||||
* ActivateBestChain is split into steps (see ActivateBestChainStep) so that | |||||
* we avoid holding cs_main for an extended period of time; the length of this | |||||
* call may be quite long during reindexing or a substantial reorg. | |||||
*/ | */ | ||||
bool CChainState::ActivateBestChain(const Config &config, | bool CChainState::ActivateBestChain(const Config &config, | ||||
CValidationState &state, | CValidationState &state, | ||||
std::shared_ptr<const CBlock> pblock) { | std::shared_ptr<const CBlock> pblock) { | ||||
// Note that while we're often called here from ProcessNewBlock, this is | // Note that while we're often called here from ProcessNewBlock, this is | ||||
// far from a guarantee. Things in the P2P/RPC will often end up calling | // far from a guarantee. Things in the P2P/RPC will often end up calling | ||||
// us in the middle of ProcessNewBlock - do not assume pblock is set | // us in the middle of ProcessNewBlock - do not assume pblock is set | ||||
// sanely for performance or correctness! | // sanely for performance or correctness! | ||||
▲ Show 20 Lines • Show All 960 Lines • ▼ Show 20 Lines | if (hash != chainparams.GetConsensus().hashGenesisBlock) { | ||||
} | } | ||||
if (!ContextualCheckBlockHeader(chainparams, block, state, pindexPrev, | if (!ContextualCheckBlockHeader(chainparams, block, state, pindexPrev, | ||||
GetAdjustedTime())) { | GetAdjustedTime())) { | ||||
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", | return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", | ||||
__func__, hash.ToString(), FormatStateMessage(state)); | __func__, hash.ToString(), FormatStateMessage(state)); | ||||
} | } | ||||
// If the previous block index isn't valid, determine if it descends | |||||
// from any block which has been found invalid (g_failed_blocks), then | |||||
// mark pindexPrev and any blocks between them as failed. | |||||
if (!pindexPrev->IsValid(BlockValidity::SCRIPTS)) { | if (!pindexPrev->IsValid(BlockValidity::SCRIPTS)) { | ||||
for (const CBlockIndex *failedit : m_failed_blocks) { | for (const CBlockIndex *failedit : m_failed_blocks) { | ||||
if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) { | if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) { | ||||
assert(failedit->nStatus.hasFailed()); | assert(failedit->nStatus.hasFailed()); | ||||
CBlockIndex *invalid_walk = pindexPrev; | CBlockIndex *invalid_walk = pindexPrev; | ||||
while (invalid_walk != failedit) { | while (invalid_walk != failedit) { | ||||
invalid_walk->nStatus = | invalid_walk->nStatus = | ||||
invalid_walk->nStatus.withFailedParent(); | invalid_walk->nStatus.withFailedParent(); | ||||
▲ Show 20 Lines • Show All 1,889 Lines • Show Last 20 Lines |