| 3830 | } |
| 3831 | |
| 3832 | bool static LoadBlockIndexDB(bool* fRebuildRequired) |
| 3833 | { |
| 3834 | const CChainParams& chainparams = Params(); |
| 3835 | if (!pblocktree->LoadBlockIndexGuts()) |
| 3836 | return false; |
| 3837 | |
| 3838 | boost::this_thread::interruption_point(); |
| 3839 | |
| 3840 | // Calculate nChainWork |
| 3841 | vector<pair<int, CBlockIndex*> > vSortedByHeight; |
| 3842 | vSortedByHeight.reserve(mapBlockIndex.size()); |
| 3843 | BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) |
| 3844 | { |
| 3845 | CBlockIndex* pindex = item.second; |
| 3846 | vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex)); |
| 3847 | } |
| 3848 | sort(vSortedByHeight.begin(), vSortedByHeight.end()); |
| 3849 | vector<pair<int, CBlockIndex*>>::iterator firstBIP100Entry = vSortedByHeight.end(); |
| 3850 | for (vector<pair<int, CBlockIndex*>>::iterator iter = vSortedByHeight.begin(); iter != vSortedByHeight.end(); iter++) |
| 3851 | { |
| 3852 | const PAIRTYPE(int, CBlockIndex*)& item = *iter; |
| 3853 | CBlockIndex* pindex = item.second; |
| 3854 | pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex); |
| 3855 | // We can link the chain of blocks for which we've received transactions at some point. |
| 3856 | // Pruned nodes may have deleted the block. |
| 3857 | if (pindex->nTx > 0) { |
| 3858 | if (pindex->pprev) { |
| 3859 | if (pindex->pprev->nChainTx) { |
| 3860 | pindex->nChainTx = pindex->pprev->nChainTx + pindex->nTx; |
| 3861 | } else { |
| 3862 | pindex->nChainTx = 0; |
| 3863 | mapBlocksUnlinked.insert(std::make_pair(pindex->pprev, pindex)); |
| 3864 | } |
| 3865 | } else { |
| 3866 | pindex->nChainTx = pindex->nTx; |
| 3867 | } |
| 3868 | } |
| 3869 | if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->nChainTx || pindex->pprev == NULL)) |
| 3870 | setBlockIndexCandidates.insert(pindex); |
| 3871 | if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork)) |
| 3872 | pindexBestInvalid = pindex; |
| 3873 | if (pindex->pprev) |
| 3874 | pindex->BuildSkip(); |
| 3875 | if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == NULL || CBlockIndexWorkComparator()(pindexBestHeader, pindex))) |
| 3876 | pindexBestHeader = pindex; |
| 3877 | if (!pindex->pprev || |
| 3878 | ((Opt().UAHFTime() != 0) && (pindex->pprev->GetMedianTimePast() < Opt().UAHFTime())) || |
| 3879 | ((Opt().UAHFTime() == 0) && (item.first < chainparams.GetConsensus().bip100ActivationHeight))) { |
| 3880 | pindex->nMaxBlockSize = MAX_BLOCK_SIZE; |
| 3881 | } else if (firstBIP100Entry == vSortedByHeight.end()) { |
| 3882 | firstBIP100Entry = iter; |
| 3883 | } |
| 3884 | } |
| 3885 | |
| 3886 | // Load block file info |
| 3887 | pblocktree->ReadLastBlockFile(nLastBlockFile); |
| 3888 | vinfoBlockFile.resize(nLastBlockFile + 1); |
| 3889 | LogPrintf("%s: last block file = %i\n", __func__, nLastBlockFile); |
no test coverage detected