Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,614 Lines • ▼ Show 20 Lines | void CChainState::PruneBlockIndexCandidates() { | ||||
// in setBlockIndexCandidates. | // in setBlockIndexCandidates. | ||||
assert(!setBlockIndexCandidates.empty()); | assert(!setBlockIndexCandidates.empty()); | ||||
} | } | ||||
/** | /** | ||||
* Try to make some progress towards making pindexMostWork the active block. | * Try to make some progress towards making pindexMostWork the active block. | ||||
* pblock is either nullptr or a pointer to a CBlock corresponding to | * pblock is either nullptr or a pointer to a CBlock corresponding to | ||||
* pindexMostWork. | * pindexMostWork. | ||||
* | |||||
* @returns true unless a system error occurred | |||||
*/ | */ | ||||
bool CChainState::ActivateBestChainStep( | bool CChainState::ActivateBestChainStep( | ||||
const Config &config, BlockValidationState &state, | const Config &config, BlockValidationState &state, | ||||
CBlockIndex *pindexMostWork, const std::shared_ptr<const CBlock> &pblock, | CBlockIndex *pindexMostWork, const std::shared_ptr<const CBlock> &pblock, | ||||
bool &fInvalidFound, ConnectTrace &connectTrace) { | bool &fInvalidFound, ConnectTrace &connectTrace) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CBlockIndex *pindexOldTip = m_chain.Tip(); | const CBlockIndex *pindexOldTip = m_chain.Tip(); | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | |||||
static void LimitValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main) { | static void LimitValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main) { | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
if (GetMainSignals().CallbacksPending() > 10) { | if (GetMainSignals().CallbacksPending() > 10) { | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* 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 | |||||
* 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, | ||||
BlockValidationState &state, | BlockValidationState &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! | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | do { | ||||
std::shared_ptr<const CBlock> nullBlockPtr; | std::shared_ptr<const CBlock> nullBlockPtr; | ||||
if (!ActivateBestChainStep( | if (!ActivateBestChainStep( | ||||
config, state, pindexMostWork, | config, state, pindexMostWork, | ||||
pblock && pblock->GetHash() == | pblock && pblock->GetHash() == | ||||
pindexMostWork->GetBlockHash() | pindexMostWork->GetBlockHash() | ||||
? pblock | ? pblock | ||||
: nullBlockPtr, | : nullBlockPtr, | ||||
fInvalidFound, connectTrace)) { | fInvalidFound, connectTrace)) { | ||||
// A system error occurred | |||||
return false; | return false; | ||||
} | } | ||||
blocks_connected = true; | blocks_connected = true; | ||||
if (fInvalidFound) { | if (fInvalidFound) { | ||||
// Wipe cache, we may need another branch now. | // Wipe cache, we may need another branch now. | ||||
pindexMostWork = nullptr; | pindexMostWork = nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,927 Lines • Show Last 20 Lines |