MCPcopy Create free account
hub / github.com/ElementsProject/elements / SanityCheck

Method SanityCheck

src/txrequest.cpp:324–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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