From fd9a0060f028a4c01bd88f58777dea34bdcbafd1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 9 Oct 2020 11:44:06 -0700 Subject: Report and verify expirations --- src/txrequest.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/txrequest.cpp') diff --git a/src/txrequest.cpp b/src/txrequest.cpp index cabdc6395..494786c20 100644 --- a/src/txrequest.cpp +++ b/src/txrequest.cpp @@ -291,6 +291,11 @@ std::map ComputeTxHashInfo(const Index& index, const Priori return ret; } +GenTxid ToGenTxid(const Announcement& ann) +{ + return {ann.m_is_wtxid, ann.m_txhash}; +} + } // namespace /** Actual implementation for TxRequestTracker's data structure. */ @@ -477,8 +482,10 @@ private: //! - REQUESTED annoucements with expiry <= now are turned into COMPLETED. //! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into CANDIDATE_{READY,BEST}. //! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned into CANDIDATE_DELAYED. - void SetTimePoint(std::chrono::microseconds now) + void SetTimePoint(std::chrono::microseconds now, std::vector>* expired) { + if (expired) expired->clear(); + // Iterate over all CANDIDATE_DELAYED and REQUESTED from old to new, as long as they're in the past, // and convert them to CANDIDATE_READY and COMPLETED respectively. while (!m_index.empty()) { @@ -486,6 +493,7 @@ private: if (it->m_state == State::CANDIDATE_DELAYED && it->m_time <= now) { PromoteCandidateReady(m_index.project(it)); } else if (it->m_state == State::REQUESTED && it->m_time <= now) { + if (expired) expired->emplace_back(it->m_peer, ToGenTxid(*it)); MakeCompleted(m_index.project(it)); } else { break; @@ -578,10 +586,11 @@ public: } //! Find the GenTxids to request now from peer. - std::vector GetRequestable(NodeId peer, std::chrono::microseconds now) + std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, + std::vector>* expired) { // Move time. - SetTimePoint(now); + SetTimePoint(now, expired); // Find all CANDIDATE_BEST announcements for this peer. std::vector selected; @@ -601,7 +610,7 @@ public: std::vector ret; ret.reserve(selected.size()); std::transform(selected.begin(), selected.end(), std::back_inserter(ret), [](const Announcement* ann) { - return GenTxid{ann->m_is_wtxid, ann->m_txhash}; + return ToGenTxid(*ann); }); return ret; } @@ -727,9 +736,10 @@ void TxRequestTracker::ReceivedResponse(NodeId peer, const uint256& txhash) m_impl->ReceivedResponse(peer, txhash); } -std::vector TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now) +std::vector TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now, + std::vector>* expired) { - return m_impl->GetRequestable(peer, now); + return m_impl->GetRequestable(peer, now, expired); } uint64_t TxRequestTracker::ComputePriority(const uint256& txhash, NodeId peer, bool preferred) const -- cgit v1.2.3