mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-18 13:27:33 +01:00
[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.
This commit is contained in:
parent
b1f0f3c288
commit
6951ddcefd
@ -574,6 +574,23 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<NodeId> GetCandidatePeers(const CTransactionRef& tx) const
|
||||||
|
{
|
||||||
|
// Search by txid and, if the tx has a witness, wtxid
|
||||||
|
std::vector<uint256> hashes{tx->GetHash().ToUint256()};
|
||||||
|
if (tx->HasWitness()) hashes.emplace_back(tx->GetWitnessHash().ToUint256());
|
||||||
|
|
||||||
|
std::vector<NodeId> result_peers;
|
||||||
|
for (const uint256& txhash : hashes) {
|
||||||
|
auto it = m_index.get<ByTxHash>().lower_bound(ByTxHashView{txhash, State::CANDIDATE_DELAYED, 0});
|
||||||
|
while (it != m_index.get<ByTxHash>().end() && it->m_txhash == txhash && it->GetState() != State::COMPLETED) {
|
||||||
|
result_peers.push_back(it->m_peer);
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result_peers;
|
||||||
|
}
|
||||||
|
|
||||||
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
|
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
|
||||||
std::chrono::microseconds reqtime)
|
std::chrono::microseconds reqtime)
|
||||||
{
|
{
|
||||||
@ -721,6 +738,7 @@ size_t TxRequestTracker::CountInFlight(NodeId peer) const { return m_impl->Count
|
|||||||
size_t TxRequestTracker::CountCandidates(NodeId peer) const { return m_impl->CountCandidates(peer); }
|
size_t TxRequestTracker::CountCandidates(NodeId peer) const { return m_impl->CountCandidates(peer); }
|
||||||
size_t TxRequestTracker::Count(NodeId peer) const { return m_impl->Count(peer); }
|
size_t TxRequestTracker::Count(NodeId peer) const { return m_impl->Count(peer); }
|
||||||
size_t TxRequestTracker::Size() const { return m_impl->Size(); }
|
size_t TxRequestTracker::Size() const { return m_impl->Size(); }
|
||||||
|
std::vector<NodeId> TxRequestTracker::GetCandidatePeers(const CTransactionRef& tx) const { return m_impl->GetCandidatePeers(tx); }
|
||||||
void TxRequestTracker::SanityCheck() const { m_impl->SanityCheck(); }
|
void TxRequestTracker::SanityCheck() const { m_impl->SanityCheck(); }
|
||||||
|
|
||||||
void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds now) const
|
void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds now) const
|
||||||
|
@ -195,6 +195,9 @@ public:
|
|||||||
/** Count how many announcements are being tracked in total across all peers and transaction hashes. */
|
/** Count how many announcements are being tracked in total across all peers and transaction hashes. */
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
|
|
||||||
|
/** For some tx return all peers with non-COMPLETED announcements for its txid or wtxid. The resulting vector may contain duplicate NodeIds. */
|
||||||
|
std::vector<NodeId> GetCandidatePeers(const CTransactionRef& tx) const;
|
||||||
|
|
||||||
/** Access to the internal priority computation (testing only) */
|
/** Access to the internal priority computation (testing only) */
|
||||||
uint64_t ComputePriority(const uint256& txhash, NodeId peer, bool preferred) const;
|
uint64_t ComputePriority(const uint256& txhash, NodeId peer, bool preferred) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user