| 36 | } |
| 37 | |
| 38 | bool BlockProcessor::setToWork(const CBlockHeader& header, int activeChainHeight) { |
| 39 | |
| 40 | const uint256 hash = header.GetHash(); |
| 41 | |
| 42 | if (HaveBlockData(hash)) { |
| 43 | LogPrint("thin", "already had block %s, " |
| 44 | "ignoring %s peer=%d\n", |
| 45 | hash.ToString(), netcmd, from.id); |
| 46 | worker.stopWork(hash); |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | bool isAnnouncement = !worker.isWorkingOn(hash); |
| 51 | |
| 52 | // Don't treat block as announcement, will trigger |
| 53 | // direct block fetch. |
| 54 | bool treatAsAnnouncement = false; |
| 55 | CBlockIndex* index = processHeader(header, treatAsAnnouncement); |
| 56 | if (!index) |
| 57 | return false; |
| 58 | |
| 59 | if (isAnnouncement && index->nHeight <= activeChainHeight + 2) { |
| 60 | // Accept block announcement. |
| 61 | LogPrint("thin", "received %s %s announcement peer=%d\n", |
| 62 | netcmd, hash.ToString(), from.id); |
| 63 | worker.addWork(hash); |
| 64 | return true; |
| 65 | } |
| 66 | else if (isAnnouncement) { |
| 67 | // Be conservative about block announcements to protect against DoS. |
| 68 | // We have processed the header, so the block will be re-downloaded |
| 69 | // later if we really want it. |
| 70 | LogPrint("thin", "ignoring block announcement %s, height %d is too far " |
| 71 | "away from active chain %d peer=%d\n", hash.ToString(), |
| 72 | index->nHeight, activeChainHeight, from.id); |
| 73 | return false; |
| 74 | } |
| 75 | else { |
| 76 | // this is a block we have requested. |
| 77 | return true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | bool BlockProcessor::requestConnectHeaders(const CBlockHeader& header) { |
| 82 | bool needPrevHeaders = headerProcessor.requestConnectHeaders(header, from); |
nothing calls this directly
no test coverage detected