MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SanityCheck

Method SanityCheck

src/txrequest.cpp:314–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312
313public:
314 void SanityCheck() const
315 {
316 // Recompute m_peerdata from m_index. This verifies the data in it as it should just be caching statistics
317 // on m_index. It also verifies the invariant that no PeerInfo announcements with m_total==0 exist.
318 assert(m_peerinfo == RecomputePeerInfo(m_index));
319
320 // Calculate per-txhash statistics from m_index, and validate invariants.
321 for (auto& item : ComputeTxHashInfo(m_index, m_computer)) {
322 TxHashInfo& info = item.second;
323
324 // Cannot have only COMPLETED peer (txhash should have been forgotten already)
325 assert(info.m_candidate_delayed + info.m_candidate_ready + info.m_candidate_best + info.m_requested > 0);
326
327 // Can have at most 1 CANDIDATE_BEST/REQUESTED peer
328 assert(info.m_candidate_best + info.m_requested <= 1);
329
330 // If there are any CANDIDATE_READY announcements, there must be exactly one CANDIDATE_BEST or REQUESTED
331 // announcement.
332 if (info.m_candidate_ready > 0) {
333 assert(info.m_candidate_best + info.m_requested == 1);
334 }
335
336 // If there is both a CANDIDATE_READY and a CANDIDATE_BEST announcement, the CANDIDATE_BEST one must be
337 // at least as good (equal or higher priority) as the best CANDIDATE_READY.
338 if (info.m_candidate_ready && info.m_candidate_best) {
339 assert(info.m_priority_candidate_best >= info.m_priority_best_candidate_ready);
340 }
341
342 // No txhash can have been announced by the same peer twice.
343 std::sort(info.m_peers.begin(), info.m_peers.end());
344 assert(std::adjacent_find(info.m_peers.begin(), info.m_peers.end()) == info.m_peers.end());
345 }
346 }
347
348 void PostGetRequestableSanityCheck(std::chrono::microseconds now) const
349 {

Callers

nothing calls this directly

Calls 4

RecomputePeerInfoFunction · 0.85
ComputeTxHashInfoFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected