Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
| Show First 20 Lines • Show All 2,917 Lines • ▼ Show 20 Lines | bool CChainState::ActivateBestChain(const Config &config, | ||||
| // 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); | ||||
| CBlockIndex *pindexMostWork = nullptr; | CBlockIndex *pindexMostWork = nullptr; | ||||
| CBlockIndex *pindexNewTip = nullptr; | CBlockIndex *pindexNewTip = nullptr; | ||||
| 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 | ||||
| // never happen in normal operation, however may happen during | // never happen in normal operation, however may happen during | ||||
| // reindex, causing memory blowup if we run too far ahead. | // reindex, causing memory blowup if we run too far ahead. | ||||
| SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | do { | ||||
| // Notify external listeners about the new tip. | // Notify external listeners about the new tip. | ||||
| GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, | GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, | ||||
| fInitialDownload); | fInitialDownload); | ||||
| // Always notify the UI if a new block tip was connected | // Always notify the UI if a new block tip was connected | ||||
| if (pindexFork != pindexNewTip) { | if (pindexFork != pindexNewTip) { | ||||
| uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip); | uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip); | ||||
| } | } | ||||
| if (nStopAtHeight && pindexNewTip && | |||||
| pindexNewTip->nHeight >= nStopAtHeight) { | |||||
| StartShutdown(); | |||||
| } | |||||
| } while (pindexNewTip != pindexMostWork); | } while (pindexNewTip != pindexMostWork); | ||||
| const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
| CheckBlockIndex(params.GetConsensus()); | CheckBlockIndex(params.GetConsensus()); | ||||
| // Write changes periodically to disk, after relay. | // Write changes periodically to disk, after relay. | ||||
| if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { | if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); | |||||
| if (nStopAtHeight && pindexNewTip && | |||||
| pindexNewTip->nHeight >= nStopAtHeight) { | |||||
| StartShutdown(); | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool ActivateBestChain(const Config &config, CValidationState &state, | bool ActivateBestChain(const Config &config, CValidationState &state, | ||||
| std::shared_ptr<const CBlock> pblock) { | std::shared_ptr<const CBlock> pblock) { | ||||
| return g_chainstate.ActivateBestChain(config, state, std::move(pblock)); | return g_chainstate.ActivateBestChain(config, state, std::move(pblock)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,691 Lines • Show Last 20 Lines | |||||