| 3046 | } |
| 3047 | |
| 3048 | bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { |
| 3049 | AssertLockHeld(cs_main); |
| 3050 | |
| 3051 | // Mark the block itself as invalid. |
| 3052 | pindex->nStatus |= BLOCK_FAILED_VALID; |
| 3053 | setDirtyBlockIndex.insert(pindex); |
| 3054 | setBlockIndexCandidates.erase(pindex); |
| 3055 | |
| 3056 | while (chainActive.Contains(pindex)) { |
| 3057 | CBlockIndex *pindexWalk = chainActive.Tip(); |
| 3058 | pindexWalk->nStatus |= BLOCK_FAILED_CHILD; |
| 3059 | setDirtyBlockIndex.insert(pindexWalk); |
| 3060 | setBlockIndexCandidates.erase(pindexWalk); |
| 3061 | // ActivateBestChain considers blocks already in chainActive |
| 3062 | // unconditionally valid already, so force disconnect away from it. |
| 3063 | if (!DisconnectTip(state)) { |
| 3064 | mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS); |
| 3065 | return false; |
| 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | mempool.TrimToSize(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000); |
| 3070 | |
| 3071 | // The resulting new best tip may not be in setBlockIndexCandidates anymore, so |
| 3072 | // add it again. |
| 3073 | BlockMap::iterator it = mapBlockIndex.begin(); |
| 3074 | while (it != mapBlockIndex.end()) { |
| 3075 | if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) { |
| 3076 | setBlockIndexCandidates.insert(it->second); |
| 3077 | } |
| 3078 | it++; |
| 3079 | } |
| 3080 | |
| 3081 | InvalidChainFound(pindex); |
| 3082 | mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS); |
| 3083 | return true; |
| 3084 | } |
| 3085 | |
| 3086 | bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { |
| 3087 | AssertLockHeld(cs_main); |
no test coverage detected