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

Method DisconnectedPeer

src/txrequest.cpp:537–566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

535 Impl& operator=(const Impl&) = delete;
536
537 void DisconnectedPeer(NodeId peer)
538 {
539 auto& index = m_index.get<ByPeer>();
540 auto it = index.lower_bound(ByPeerView{peer, false, uint256::ZERO});
541 while (it != index.end() && it->m_peer == peer) {
542 // Check what to continue with after this iteration. 'it' will be deleted in what follows, so we need to
543 // decide what to continue with afterwards. There are a number of cases to consider:
544 // - std::next(it) is end() or belongs to a different peer. In that case, this is the last iteration
545 // of the loop (denote this by setting it_next to end()).
546 // - 'it' is not the only non-COMPLETED announcement for its txhash. This means it will be deleted, but
547 // no other Announcement objects will be modified. Continue with std::next(it) if it belongs to the
548 // same peer, but decide this ahead of time (as 'it' may change position in what follows).
549 // - 'it' is the only non-COMPLETED announcement for its txhash. This means it will be deleted along
550 // with all other announcements for the same txhash - which may include std::next(it). However, other
551 // than 'it', no announcements for the same peer can be affected (due to (peer, txhash) uniqueness).
552 // In other words, the situation where std::next(it) is deleted can only occur if std::next(it)
553 // belongs to a different peer but the same txhash as 'it'. This is covered by the first bulletpoint
554 // already, and we'll have set it_next to end().
555 auto it_next = (std::next(it) == index.end() || std::next(it)->m_peer != peer) ? index.end() :
556 std::next(it);
557 // If the announcement isn't already COMPLETED, first make it COMPLETED (which will mark other
558 // CANDIDATEs as CANDIDATE_BEST, or delete all of a txhash's announcements if no non-COMPLETED ones are
559 // left).
560 if (MakeCompleted(m_index.project<ByTxHash>(it))) {
561 // Then actually delete the announcement (unless it was already deleted by MakeCompleted).
562 Erase<ByPeer>(it);
563 }
564 it = it_next;
565 }
566 }
567
568 void ForgetTxHash(const uint256& txhash)
569 {

Callers

nothing calls this directly

Calls 2

lower_boundMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected