Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
| 3140 | |
| 3141 | /** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */ |
| 3142 | void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) |
| 3143 | { |
| 3144 | pindexNew->nTx = block.vtx.size(); |
| 3145 | pindexNew->nChainTx = 0; |
| 3146 | pindexNew->nFile = pos.nFile; |
| 3147 | pindexNew->nDataPos = pos.nPos; |
| 3148 | pindexNew->nUndoPos = 0; |
| 3149 | pindexNew->nStatus |= BLOCK_HAVE_DATA; |
| 3150 | if (IsWitnessEnabled(pindexNew->pprev, consensusParams)) { |
| 3151 | pindexNew->nStatus |= BLOCK_OPT_WITNESS; |
| 3152 | } |
| 3153 | pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS); |
| 3154 | setDirtyBlockIndex.insert(pindexNew); |
| 3155 | |
| 3156 | if (pindexNew->pprev == nullptr || pindexNew->pprev->nChainTx) { |
| 3157 | // If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS. |
| 3158 | std::deque<CBlockIndex*> queue; |
| 3159 | queue.push_back(pindexNew); |
| 3160 | |
| 3161 | // Recursively process any descendant blocks that now may be eligible to be connected. |
| 3162 | while (!queue.empty()) { |
| 3163 | CBlockIndex *pindex = queue.front(); |
| 3164 | queue.pop_front(); |
| 3165 | pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx; |
| 3166 | { |
| 3167 | LOCK(cs_nBlockSequenceId); |
| 3168 | pindex->nSequenceId = nBlockSequenceId++; |
| 3169 | } |
| 3170 | if (chainActive.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) { |
| 3171 | setBlockIndexCandidates.insert(pindex); |
| 3172 | } |
| 3173 | std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex); |
| 3174 | while (range.first != range.second) { |
| 3175 | std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first; |
| 3176 | queue.push_back(it->second); |
| 3177 | range.first++; |
| 3178 | mapBlocksUnlinked.erase(it); |
| 3179 | } |
| 3180 | } |
| 3181 | } else { |
| 3182 | if (pindexNew->pprev && pindexNew->pprev->IsValid(BLOCK_VALID_TREE)) { |
| 3183 | mapBlocksUnlinked.insert(std::make_pair(pindexNew->pprev, pindexNew)); |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) |
| 3189 | { |
nothing calls this directly
no test coverage detected