MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / buildStub

Method buildStub

src/thinblockmanager.cpp:61–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59};
60
61void ThinBlockManager::buildStub(const StubData& s, const TxFinder& txFinder,
62 ThinBlockWorker& worker, CNode& from)
63{
64 uint256 h = s.header().GetHash();
65 assert(builders.count(h));
66 if (builders[h].builder)
67 {
68 try {
69 builders[h].builder->replaceWantedTx(s.allTransactions());
70 }
71 catch (const thinblock_error& e) {
72 LogPrintf("Error: Thinblock stub mismatch: %s. Giving up on downloading block %s\n",
73 e.what(), h.ToString());
74 std::cerr << "thinblock error" << e.what() << std::endl;
75
76 // FIXME: If this actually happens, we should mark
77 // all workers working on block as misbehaving. We don't know
78 // who provided a bad stub.
79 removeIfExists(h);
80 return;
81 }
82
83 // The stub may provide transactions we're missing.
84 std::vector<CTransaction> provided = s.missingProvided();
85 for (auto& tx : provided)
86 builders[h].builder->addTransaction(tx);
87 }
88 else {
89 WrappedFinder wfinder(s.missingProvided(), txFinder);
90 builders[h].builder.reset(new ThinBlockBuilder(
91 s.header(), s.allTransactions(), wfinder));
92
93 // Node was first to provide us
94 // a thin block. Select for block announcements with thin blocks.
95 requestBlockAnnouncements(worker, from);
96 }
97
98 if (builders[h].builder->numTxsMissing() == 0)
99 finishBlock(h, *builders[h].builder);
100}
101
102bool ThinBlockManager::isStubBuilt(const uint256& block) {
103 if (!builders.count(block))

Callers

nothing calls this directly

Calls 10

countMethod · 0.80
replaceWantedTxMethod · 0.80
addTransactionMethod · 0.80
resetMethod · 0.80
numTxsMissingMethod · 0.80
GetHashMethod · 0.45
headerMethod · 0.45
allTransactionsMethod · 0.45
ToStringMethod · 0.45
missingProvidedMethod · 0.45

Tested by

no test coverage detected