| 10 | #include "compacttxfinder.h" |
| 11 | |
| 12 | void CompactBlockProcessor::operator()(CDataStream& vRecv, const CTxMemPool& mempool, |
| 13 | uint64_t currMaxBlockSize, int activeChainHeight) |
| 14 | { |
| 15 | CompactBlock block; |
| 16 | vRecv >> block; |
| 17 | |
| 18 | const uint256 hash = block.header.GetHash(); |
| 19 | |
| 20 | LogPrintf("received compactblock %s from peer=%d\n", |
| 21 | hash.ToString(), worker.nodeID()); |
| 22 | |
| 23 | try { |
| 24 | validateCompactBlock(block, currMaxBlockSize); |
| 25 | } |
| 26 | catch (const std::exception& e) { |
| 27 | LogPrint("thin", "Invalid compact block %s\n", e.what()); |
| 28 | rejectBlock(hash, e.what(), 20); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | if (requestConnectHeaders(block.header)) { |
| 33 | worker.stopWork(hash); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | if (!setToWork(block.header, activeChainHeight)) |
| 38 | return; |
| 39 | |
| 40 | from.AddInventoryKnown(CInv(MSG_CMPCT_BLOCK, hash)); |
| 41 | |
| 42 | std::unique_ptr<CompactStub> stub; |
| 43 | try { |
| 44 | CompactTxFinder txfinder(mempool, |
| 45 | block.shorttxidk0, block.shorttxidk1); |
| 46 | |
| 47 | stub.reset(new CompactStub(block)); |
| 48 | worker.buildStub(*stub, txfinder, from); |
| 49 | } |
| 50 | catch (const thinblock_error& e) { |
| 51 | rejectBlock(hash, e.what(), 10); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (!worker.isWorkingOn(hash)) { |
| 56 | // Stub had enough data to finish |
| 57 | // the block. |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | // Request missing |
| 62 | std::vector<std::pair<int, ThinTx> > missing = worker.getTxsMissing(hash); |
| 63 | |
| 64 | CompactReRequest req; |
| 65 | req.blockhash = hash; |
| 66 | |
| 67 | for (auto& t : missing) |
| 68 | req.indexes.push_back(t.first /* index in block */); |
| 69 |
nothing calls this directly
no test coverage detected