Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
* library, callbacks via the validation interface, or read/write-to-disk | * library, callbacks via the validation interface, or read/write-to-disk | ||||
* functions (eventually this will also be via callbacks). | * functions (eventually this will also be via callbacks). | ||||
*/ | */ | ||||
class CChainState { | class CChainState { | ||||
private: | 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 or parked though, and pruning nodes may be missing | ||||
* for the block. | * the data for the block; these will get cleaned during FindMostWorkChain. | ||||
*/ | */ | ||||
std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates; | ||||
/** | /** | ||||
* the ChainState CriticalSection | * the ChainState CriticalSection | ||||
* A lock that must be held when modifying this ChainState - held in | * A lock that must be held when modifying this ChainState - held in | ||||
* ActivateBestChain() | * ActivateBestChain() | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 2,540 Lines • ▼ Show 20 Lines | do { | ||||
bool fMissingData = !pindexTest->nStatus.hasData(); | bool fMissingData = !pindexTest->nStatus.hasData(); | ||||
if (!(fInvalidChain || fParkedChain || fMissingData)) { | if (!(fInvalidChain || fParkedChain || fMissingData)) { | ||||
// The current block is acceptable, move to the parent, up to | // The current block is acceptable, move to the parent, up to | ||||
// the fork point. | // the fork point. | ||||
pindexTest = pindexTest->pprev; | pindexTest = pindexTest->pprev; | ||||
continue; | continue; | ||||
} | } | ||||
// Candidate chain is not usable (either invalid or missing data) | // Candidate chain is not usable (either invalid or parked or | ||||
// missing data) | |||||
hasValidAncestor = false; | hasValidAncestor = false; | ||||
setBlockIndexCandidates.erase(pindexTest); | setBlockIndexCandidates.erase(pindexTest); | ||||
if (fInvalidChain && | if (fInvalidChain && | ||||
(pindexBestInvalid == nullptr || | (pindexBestInvalid == nullptr || | ||||
pindexNew->nChainWork > pindexBestInvalid->nChainWork)) { | pindexNew->nChainWork > pindexBestInvalid->nChainWork)) { | ||||
pindexBestInvalid = pindexNew; | pindexBestInvalid = pindexNew; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,682 Lines • ▼ Show 20 Lines | while (pindex != nullptr) { | ||||
assert(pindexFirstNotScriptsValid == nullptr); | assert(pindexFirstNotScriptsValid == nullptr); | ||||
} | } | ||||
if (pindexFirstInvalid == nullptr) { | if (pindexFirstInvalid == nullptr) { | ||||
// Checks for not-invalid blocks. | // Checks for not-invalid blocks. | ||||
// The failed mask cannot be set for blocks without invalid parents. | // The failed mask cannot be set for blocks without invalid parents. | ||||
assert(!pindex->nStatus.isInvalid()); | assert(!pindex->nStatus.isInvalid()); | ||||
} | } | ||||
if (pindexFirstParked == nullptr) { | if (pindexFirstParked == nullptr) { | ||||
// Checks for not-invalid blocks. | // Checks for not-parked blocks. | ||||
// The failed mask cannot be set for blocks without invalid parents. | // The parked mask cannot be set for blocks without parked parents. | ||||
// (i.e., hasParkedParent only if an ancestor is properly parked). | |||||
assert(!pindex->nStatus.isOnParkedChain()); | assert(!pindex->nStatus.isOnParkedChain()); | ||||
} | } | ||||
if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && | if (!CBlockIndexWorkComparator()(pindex, chainActive.Tip()) && | ||||
pindexFirstNeverProcessed == nullptr) { | pindexFirstNeverProcessed == nullptr) { | ||||
if (pindexFirstInvalid == nullptr) { | if (pindexFirstInvalid == nullptr) { | ||||
// If this block sorts at least as good as the current tip and | // If this block sorts at least as good as the current tip and | ||||
// is valid and we have all data for its parents, it must be in | // is valid and we have all data for its parents, it must be in | ||||
// setBlockIndexCandidates or be parked. | // setBlockIndexCandidates or be parked. | ||||
▲ Show 20 Lines • Show All 345 Lines • Show Last 20 Lines |