@@ -187,15 +187,8 @@ bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid,
187
187
188
188
if (unique_parents.empty ()) return true ;
189
189
190
- if (auto delay{OrphanResolutionCandidate (peer, Wtxid::FromUint256 (gtxid.GetHash ()), unique_parents.size ())}) {
191
- m_orphanage.AddAnnouncer (Wtxid::FromUint256 (gtxid.GetHash ()), peer);
192
-
193
- const auto & info = m_peer_info.at (peer).m_connection_info ;
194
- for (const auto & parent_txid : unique_parents) {
195
- m_txrequest.ReceivedInv (peer, GenTxid::Txid (parent_txid), info.m_preferred , now + *delay);
196
- }
197
-
198
- LogDebug (BCLog::TXPACKAGES, " added peer=%d as a candidate for resolving orphan %s\n " , peer, gtxid.GetHash ().ToString ());
190
+ if (OrphanResolutionCandidate (unique_parents, orphan_tx->GetWitnessHash (), peer, now)) {
191
+ m_orphanage.AddAnnouncer (orphan_tx->GetWitnessHash (), peer);
199
192
}
200
193
201
194
// Return even if the peer isn't an orphan resolution candidate. This would be caught by AlreadyHaveTx.
@@ -231,21 +224,23 @@ bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid,
231
224
return false ;
232
225
}
233
226
234
- std::optional<std::chrono::seconds> TxDownloadManagerImpl::OrphanResolutionCandidate (NodeId nodeid , const Wtxid& orphan_wtxid, size_t num_parents )
227
+ bool TxDownloadManagerImpl::OrphanResolutionCandidate (const std::vector<Txid>& unique_parents , const Wtxid& wtxid, NodeId nodeid, std::chrono::microseconds now )
235
228
{
236
- if (m_peer_info.count (nodeid) == 0 ) return std::nullopt;
237
- if (m_orphanage.HaveTxFromPeer (orphan_wtxid, nodeid)) return std::nullopt;
229
+ auto it_peer = m_peer_info.find (nodeid);
230
+ if (it_peer == m_peer_info.end ()) return false ;
231
+ if (m_orphanage.HaveTxFromPeer (wtxid, nodeid)) return false ;
238
232
239
233
const auto & peer_entry = m_peer_info.at (nodeid);
240
234
const auto & info = peer_entry.m_connection_info ;
235
+
241
236
// TODO: add delays and limits based on the amount of orphan resolution we are already doing
242
237
// with this peer, how much they are using the orphanage, etc.
243
238
if (!info.m_relay_permissions ) {
244
239
// This mirrors the delaying and dropping behavior in AddTxAnnouncement in order to preserve
245
240
// existing behavior: drop if we are tracking too many invs for this peer already. Each
246
241
// orphan resolution involves at least 1 transaction request which may or may not be
247
242
// currently tracked in m_txrequest, so we include that in the count.
248
- if (m_txrequest.Count (nodeid) + num_parents > MAX_PEER_TX_ANNOUNCEMENTS) return std::nullopt ;
243
+ if (m_txrequest.Count (nodeid) + unique_parents. size () > MAX_PEER_TX_ANNOUNCEMENTS) return false ;
249
244
}
250
245
251
246
std::chrono::seconds delay{0s};
@@ -258,7 +253,13 @@ std::optional<std::chrono::seconds> TxDownloadManagerImpl::OrphanResolutionCandi
258
253
const bool overloaded = !info.m_relay_permissions && m_txrequest.CountInFlight (nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT;
259
254
if (overloaded) delay += OVERLOADED_PEER_TX_DELAY;
260
255
261
- return delay;
256
+ // Treat finding orphan resolution candidate as equivalent to the peer announcing all missing parents.
257
+ // In the future, orphan resolution may include more explicit steps
258
+ for (const auto & parent_txid : unique_parents) {
259
+ m_txrequest.ReceivedInv (nodeid, GenTxid::Txid (parent_txid), info.m_preferred , now + delay);
260
+ }
261
+ LogDebug (BCLog::TXPACKAGES, " added peer=%d as a candidate for resolving orphan %s\n " , nodeid, wtxid.ToString ());
262
+ return true ;
262
263
}
263
264
264
265
std::vector<GenTxid> TxDownloadManagerImpl::GetRequestsToSend (NodeId nodeid, std::chrono::microseconds current_time)
@@ -401,17 +402,8 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
401
402
add_extra_compact_tx &= !m_orphanage.HaveTx (wtxid);
402
403
403
404
auto add_orphan_reso_candidate = [&](const CTransactionRef& orphan_tx, const std::vector<Txid>& unique_parents, NodeId nodeid, std::chrono::microseconds now) {
404
- const auto & wtxid = orphan_tx->GetWitnessHash ();
405
- if (auto delay{OrphanResolutionCandidate (nodeid, wtxid, unique_parents.size ())}) {
406
- const auto & info = m_peer_info.at (nodeid).m_connection_info ;
405
+ if (OrphanResolutionCandidate (unique_parents, orphan_tx->GetWitnessHash (), nodeid, now)) {
407
406
m_orphanage.AddTx (orphan_tx, nodeid);
408
-
409
- // Treat finding orphan resolution candidate as equivalent to the peer announcing all missing parents
410
- // In the future, orphan resolution may include more explicit steps
411
- for (const auto & parent_txid : unique_parents) {
412
- m_txrequest.ReceivedInv (nodeid, GenTxid::Txid (parent_txid), info.m_preferred , now + *delay);
413
- }
414
- LogDebug (BCLog::TXPACKAGES, " added peer=%d as a candidate for resolving orphan %s\n " , nodeid, wtxid.ToString ());
415
407
}
416
408
};
417
409
0 commit comments