Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
| 4143 | |
| 4144 | /** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */ |
| 4145 | bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBlockIndex* pindexNew, const CDiskBlockPos& pos) |
| 4146 | { |
| 4147 | if (block.IsProofOfStake()) |
| 4148 | pindexNew->SetProofOfStake(); |
| 4149 | pindexNew->nTx = block.vtx.size(); |
| 4150 | pindexNew->nChainTx = 0; |
| 4151 | pindexNew->nFile = pos.nFile; |
| 4152 | pindexNew->nDataPos = pos.nPos; |
| 4153 | pindexNew->nUndoPos = 0; |
| 4154 | pindexNew->nStatus |= BLOCK_HAVE_DATA; |
| 4155 | if (IsWitnessEnabled(pindexNew->pprev, Params().GetConsensus())) { |
| 4156 | pindexNew->nStatus |= BLOCK_OPT_WITNESS; |
| 4157 | } |
| 4158 | pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS); |
| 4159 | setDirtyBlockIndex.insert(pindexNew); |
| 4160 | |
| 4161 | if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) { |
| 4162 | // If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS. |
| 4163 | deque<CBlockIndex*> queue; |
| 4164 | queue.push_back(pindexNew); |
| 4165 | |
| 4166 | // Recursively process any descendant blocks that now may be eligible to be connected. |
| 4167 | while (!queue.empty()) { |
| 4168 | CBlockIndex* pindex = queue.front(); |
| 4169 | queue.pop_front(); |
| 4170 | pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx; |
| 4171 | { |
| 4172 | LOCK(cs_nBlockSequenceId); |
| 4173 | pindex->nSequenceId = nBlockSequenceId++; |
| 4174 | } |
| 4175 | if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) { |
| 4176 | setBlockIndexCandidates.insert(pindex); |
| 4177 | } |
| 4178 | std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex); |
| 4179 | while (range.first != range.second) { |
| 4180 | std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first; |
| 4181 | queue.push_back(it->second); |
| 4182 | range.first++; |
| 4183 | mapBlocksUnlinked.erase(it); |
| 4184 | } |
| 4185 | } |
| 4186 | } else { |
| 4187 | if (pindexNew->pprev && pindexNew->pprev->IsValid(BLOCK_VALID_TREE)) { |
| 4188 | mapBlocksUnlinked.insert(std::make_pair(pindexNew->pprev, pindexNew)); |
| 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | return true; |
| 4193 | } |
| 4194 | |
| 4195 | bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) |
| 4196 | { |
no test coverage detected