Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | const std::vector<std::string> CHECKLEVEL_DOC{ | ||||
"level 3 checks disconnection of tip blocks", | "level 3 checks disconnection of tip blocks", | ||||
"level 4 tries to reconnect the blocks", | "level 4 tries to reconnect the blocks", | ||||
"each level includes the checks of the previous levels", | "each level includes the checks of the previous levels", | ||||
}; | }; | ||||
GlobalMutex g_best_block_mutex; | GlobalMutex g_best_block_mutex; | ||||
std::condition_variable g_best_block_cv; | std::condition_variable g_best_block_cv; | ||||
uint256 g_best_block; | uint256 g_best_block; | ||||
bool fCheckBlockIndex = false; | |||||
BlockValidationOptions::BlockValidationOptions(const Config &config) | BlockValidationOptions::BlockValidationOptions(const Config &config) | ||||
: excessiveBlockSize(config.GetMaxBlockSize()), checkPoW(true), | : excessiveBlockSize(config.GetMaxBlockSize()), checkPoW(true), | ||||
checkMerkleRoot(true) {} | checkMerkleRoot(true) {} | ||||
const CBlockIndex * | const CBlockIndex * | ||||
Chainstate::FindForkInGlobalIndex(const CBlockLocator &locator) const { | Chainstate::FindForkInGlobalIndex(const CBlockLocator &locator) const { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
▲ Show 20 Lines • Show All 2,948 Lines • ▼ Show 20 Lines | static void LimitValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main) { | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
if (GetMainSignals().CallbacksPending() > 10) { | if (GetMainSignals().CallbacksPending() > 10) { | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
} | } | ||||
} | } | ||||
bool Chainstate::ActivateBestChain(BlockValidationState &state, | bool Chainstate::ActivateBestChain(BlockValidationState &state, | ||||
std::shared_ptr<const CBlock> pblock) { | std::shared_ptr<const CBlock> pblock, | ||||
bool skip_checkblockindex) { | |||||
AssertLockNotHeld(m_chainstate_mutex); | AssertLockNotHeld(m_chainstate_mutex); | ||||
// 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 93 Lines • ▼ Show 20 Lines | do { | ||||
} while (!m_chain.Tip() || | } while (!m_chain.Tip() || | ||||
(starting_tip && CBlockIndexWorkComparator()( | (starting_tip && CBlockIndexWorkComparator()( | ||||
m_chain.Tip(), starting_tip))); | m_chain.Tip(), starting_tip))); | ||||
// Check the index once we're done with the above loop, since | // Check the index once we're done with the above loop, since | ||||
// we're going to release cs_main soon. If the index is in a bad | // we're going to release cs_main soon. If the index is in a bad | ||||
// state now, then it's better to know immediately rather than | // state now, then it's better to know immediately rather than | ||||
// randomly have it cause a problem in a race. | // randomly have it cause a problem in a race. | ||||
if (!skip_checkblockindex) { | |||||
CheckBlockIndex(); | CheckBlockIndex(); | ||||
} | |||||
if (blocks_connected) { | if (blocks_connected) { | ||||
const CBlockIndex *pindexFork = m_chain.FindFork(starting_tip); | const CBlockIndex *pindexFork = m_chain.FindFork(starting_tip); | ||||
bool fInitialDownload = IsInitialBlockDownload(); | bool fInitialDownload = IsInitialBlockDownload(); | ||||
// Notify external listeners about the new tip. | // Notify external listeners about the new tip. | ||||
// Enqueue while holding cs_main to ensure that UpdatedBlockTip | // Enqueue while holding cs_main to ensure that UpdatedBlockTip | ||||
// is called in the order in which blocks are connected | // is called in the order in which blocks are connected | ||||
▲ Show 20 Lines • Show All 2,114 Lines • ▼ Show 20 Lines | try { | ||||
AbortNode(std::string("System error: ") + e.what()); | AbortNode(std::string("System error: ") + e.what()); | ||||
} | } | ||||
LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, | LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, | ||||
GetTimeMillis() - nStart); | GetTimeMillis() - nStart); | ||||
} | } | ||||
void Chainstate::CheckBlockIndex() { | void Chainstate::CheckBlockIndex() { | ||||
if (!fCheckBlockIndex) { | if (!m_chainman.ShouldCheckBlockIndex()) { | ||||
return; | return; | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
// During a reindex, we read the genesis block and call CheckBlockIndex | // During a reindex, we read the genesis block and call CheckBlockIndex | ||||
// before ActivateBestChain, so we have the genesis block in | // before ActivateBestChain, so we have the genesis block in | ||||
// m_blockman.m_block_index but no active chain. (A few of the tests when | // m_blockman.m_block_index but no active chain. (A few of the tests when | ||||
▲ Show 20 Lines • Show All 1,035 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Apply default chain params to nullopt members. | * Apply default chain params to nullopt members. | ||||
* This helps to avoid coding errors around the accidental use of the compare | * This helps to avoid coding errors around the accidental use of the compare | ||||
* operators that accept nullopt, thus ignoring the intended default value. | * operators that accept nullopt, thus ignoring the intended default value. | ||||
*/ | */ | ||||
static ChainstateManager::Options &&Flatten(ChainstateManager::Options &&opts) { | static ChainstateManager::Options &&Flatten(ChainstateManager::Options &&opts) { | ||||
if (!opts.check_block_index.has_value()) { | |||||
opts.check_block_index = | |||||
opts.config.GetChainParams().DefaultConsistencyChecks(); | |||||
} | |||||
if (!opts.minimum_chain_work.has_value()) { | if (!opts.minimum_chain_work.has_value()) { | ||||
opts.minimum_chain_work = UintToArith256( | opts.minimum_chain_work = UintToArith256( | ||||
opts.config.GetChainParams().GetConsensus().nMinimumChainWork); | opts.config.GetChainParams().GetConsensus().nMinimumChainWork); | ||||
} | } | ||||
if (!opts.assumed_valid_block.has_value()) { | if (!opts.assumed_valid_block.has_value()) { | ||||
opts.assumed_valid_block = | opts.assumed_valid_block = | ||||
opts.config.GetChainParams().GetConsensus().defaultAssumeValid; | opts.config.GetChainParams().GetConsensus().defaultAssumeValid; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |