Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for | * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for | ||||
* itself and all ancestors) and as good as our current tip or better. | * itself and all ancestors) and as good as our current tip or better. | ||||
* Entries may be failed, though, and pruning nodes may be missing the data | * Entries may be failed, though, and pruning nodes may be missing the data | ||||
* for the block. | * for the block. | ||||
*/ | */ | ||||
std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | ||||
/** | |||||
* the ChainState CriticalSection | |||||
* A lock that must be held when modifying this ChainState - held in | |||||
* ActivateBestChain() | |||||
*/ | |||||
CCriticalSection m_cs_chainstate; | |||||
public: | public: | ||||
CChain chainActive; | CChain chainActive; | ||||
BlockMap mapBlockIndex; | BlockMap mapBlockIndex; | ||||
std::multimap<CBlockIndex *, CBlockIndex *> mapBlocksUnlinked; | std::multimap<CBlockIndex *, CBlockIndex *> mapBlocksUnlinked; | ||||
CBlockIndex *pindexBestInvalid = nullptr; | CBlockIndex *pindexBestInvalid = nullptr; | ||||
CBlockIndex *pindexBestParked = nullptr; | CBlockIndex *pindexBestParked = nullptr; | ||||
bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree); | bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree); | ||||
▲ Show 20 Lines • Show All 2,557 Lines • ▼ Show 20 Lines | |||||
* 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. | ||||
*/ | */ | ||||
bool CChainState::ActivateBestChainStep( | bool CChainState::ActivateBestChainStep( | ||||
const Config &config, CValidationState &state, CBlockIndex *pindexMostWork, | const Config &config, CValidationState &state, CBlockIndex *pindexMostWork, | ||||
const std::shared_ptr<const CBlock> &pblock, bool &fInvalidFound, | const std::shared_ptr<const CBlock> &pblock, bool &fInvalidFound, | ||||
ConnectTrace &connectTrace) { | ConnectTrace &connectTrace) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CBlockIndex *pindexOldTip = chainActive.Tip(); | const CBlockIndex *pindexOldTip = chainActive.Tip(); | ||||
const CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork); | const CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork); | ||||
// Disconnect active blocks which are no longer in the best chain. | // Disconnect active blocks which are no longer in the best chain. | ||||
bool fBlocksDisconnected = false; | bool fBlocksDisconnected = false; | ||||
DisconnectedBlockTransactions disconnectpool; | DisconnectedBlockTransactions disconnectpool; | ||||
while (chainActive.Tip() && chainActive.Tip() != pindexFork) { | while (chainActive.Tip() && chainActive.Tip() != pindexFork) { | ||||
if (!DisconnectTip(config, state, &disconnectpool)) { | if (!DisconnectTip(config, state, &disconnectpool)) { | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | 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! | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
// ABC maintains a fair degree of expensive-to-calculate internal state | |||||
// because this function periodically releases cs_main so that it does not | |||||
// lock up other threads for too long during large connects - and to allow | |||||
// for e.g. the callback queue to drain we use m_cs_chainstate to enforce | |||||
// mutual exclusion so that only one caller may execute this function at a | |||||
// time | |||||
LOCK(m_cs_chainstate); | |||||
CBlockIndex *pindexMostWork = nullptr; | CBlockIndex *pindexMostWork = nullptr; | ||||
CBlockIndex *pindexNewTip = nullptr; | CBlockIndex *pindexNewTip = nullptr; | ||||
int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); | int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); | ||||
do { | do { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
if (GetMainSignals().CallbacksPending() > 10) { | if (GetMainSignals().CallbacksPending() > 10) { | ||||
// Block until the validation queue drains. This should largely | // Block until the validation queue drains. This should largely | ||||
▲ Show 20 Lines • Show All 2,851 Lines • Show Last 20 Lines |