| 59 | }; |
| 60 | |
| 61 | void 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 | |
| 102 | bool ThinBlockManager::isStubBuilt(const uint256& block) { |
| 103 | if (!builders.count(block)) |
nothing calls this directly
no test coverage detected