MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / operator()

Method operator()

src/compactblockprocessor.cpp:12–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "compacttxfinder.h"
11
12void 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

Callers

nothing calls this directly

Calls 14

validateCompactBlockFunction · 0.85
AddInventoryKnownMethod · 0.80
resetMethod · 0.80
isWorkingOnMethod · 0.80
PushMessageMethod · 0.80
CInvClass · 0.70
GetHashMethod · 0.45
ToStringMethod · 0.45
nodeIDMethod · 0.45
stopWorkMethod · 0.45
buildStubMethod · 0.45
getTxsMissingMethod · 0.45

Tested by

no test coverage detected