Skip to content

Commit 6951ddc

Browse files
committed
[txrequest] GetCandidatePeers
Needed for a later commit adding logic to ask the TxRequestTracker for a list of announcers. These announcers should know the parents of the transaction they announced.
1 parent b1f0f3c commit 6951ddc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/txrequest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,23 @@ class TxRequestTracker::Impl {
574574
}
575575
}
576576

577+
std::vector<NodeId> GetCandidatePeers(const CTransactionRef& tx) const
578+
{
579+
// Search by txid and, if the tx has a witness, wtxid
580+
std::vector<uint256> hashes{tx->GetHash().ToUint256()};
581+
if (tx->HasWitness()) hashes.emplace_back(tx->GetWitnessHash().ToUint256());
582+
583+
std::vector<NodeId> result_peers;
584+
for (const uint256& txhash : hashes) {
585+
auto it = m_index.get<ByTxHash>().lower_bound(ByTxHashView{txhash, State::CANDIDATE_DELAYED, 0});
586+
while (it != m_index.get<ByTxHash>().end() && it->m_txhash == txhash && it->GetState() != State::COMPLETED) {
587+
result_peers.push_back(it->m_peer);
588+
++it;
589+
}
590+
}
591+
return result_peers;
592+
}
593+
577594
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
578595
std::chrono::microseconds reqtime)
579596
{
@@ -721,6 +738,7 @@ size_t TxRequestTracker::CountInFlight(NodeId peer) const { return m_impl->Count
721738
size_t TxRequestTracker::CountCandidates(NodeId peer) const { return m_impl->CountCandidates(peer); }
722739
size_t TxRequestTracker::Count(NodeId peer) const { return m_impl->Count(peer); }
723740
size_t TxRequestTracker::Size() const { return m_impl->Size(); }
741+
std::vector<NodeId> TxRequestTracker::GetCandidatePeers(const CTransactionRef& tx) const { return m_impl->GetCandidatePeers(tx); }
724742
void TxRequestTracker::SanityCheck() const { m_impl->SanityCheck(); }
725743

726744
void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds now) const

src/txrequest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class TxRequestTracker {
195195
/** Count how many announcements are being tracked in total across all peers and transaction hashes. */
196196
size_t Size() const;
197197

198+
/** For some tx return all peers with non-COMPLETED announcements for its txid or wtxid. The resulting vector may contain duplicate NodeIds. */
199+
std::vector<NodeId> GetCandidatePeers(const CTransactionRef& tx) const;
200+
198201
/** Access to the internal priority computation (testing only) */
199202
uint64_t ComputePriority(const uint256& txhash, NodeId peer, bool preferred) const;
200203

0 commit comments

Comments
 (0)