| 3303 | } |
| 3304 | |
| 3305 | bool CChainState::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex) |
| 3306 | { |
| 3307 | AssertLockNotHeld(m_chainstate_mutex); |
| 3308 | AssertLockNotHeld(::cs_main); |
| 3309 | { |
| 3310 | LOCK(cs_main); |
| 3311 | if (pindex->nChainWork < m_chain.Tip()->nChainWork) { |
| 3312 | // Nothing to do, this block is not at the tip. |
| 3313 | return true; |
| 3314 | } |
| 3315 | if (m_chain.Tip()->nChainWork > nLastPreciousChainwork) { |
| 3316 | // The chain has been extended since the last call, reset the counter. |
| 3317 | nBlockReverseSequenceId = -1; |
| 3318 | } |
| 3319 | nLastPreciousChainwork = m_chain.Tip()->nChainWork; |
| 3320 | setBlockIndexCandidates.erase(pindex); |
| 3321 | pindex->nSequenceId = nBlockReverseSequenceId; |
| 3322 | if (nBlockReverseSequenceId > std::numeric_limits<int32_t>::min()) { |
| 3323 | // We can't keep reducing the counter if somebody really wants to |
| 3324 | // call preciousblock 2**31-1 times on the same set of tips... |
| 3325 | nBlockReverseSequenceId--; |
| 3326 | } |
| 3327 | if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveTxsDownloaded()) { |
| 3328 | setBlockIndexCandidates.insert(pindex); |
| 3329 | PruneBlockIndexCandidates(); |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | return ActivateBestChain(state, std::shared_ptr<const CBlock>()); |
| 3334 | } |
| 3335 | |
| 3336 | bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex) |
| 3337 | { |
no test coverage detected