| 517 | } |
| 518 | |
| 519 | void static InvalidBlockFound(CBlockIndex *pIndex, CBlock &block, const CValidationState &state) { |
| 520 | int32_t nDoS = 0; |
| 521 | if (state.IsInvalid(nDoS)) { |
| 522 | LOCK(cs_mapNodeState); |
| 523 | map<uint256, NodeId>::iterator it = mapBlockSource.find(pIndex->GetBlockHash()); |
| 524 | if (it != mapBlockSource.end() && State(it->second)) { |
| 525 | CBlockReject reject = {state.GetRejectCode(), state.GetRejectReason(), pIndex->GetBlockHash()}; |
| 526 | State(it->second)->rejects.push_back(reject); |
| 527 | if (nDoS > 0) { |
| 528 | LogPrint(BCLog::INFO, "Misebehaving: found invalid block, hash:%s, Misbehavior add %d\n", it->first.GetHex(), |
| 529 | nDoS); |
| 530 | Misbehaving(it->second, nDoS); |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | if (!state.CorruptionPossible()) { |
| 536 | pIndex->nStatus |= BLOCK_FAILED_VALID; |
| 537 | const auto &bpRegid = GetBlockBpRegid(block); |
| 538 | pCdMan->pBlockIndexDb->WriteBlockIndex(CDiskBlockIndex(pIndex, block, bpRegid)); |
| 539 | setBlockIndexValid.erase(pIndex); |
| 540 | InvalidChainFound(pIndex); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | bool InvalidateBlockIndex(CBlockIndex *pIndex) { |
| 545 | pIndex->nStatus |= BLOCK_FAILED_VALID; |
no test coverage detected