| 224 | } |
| 225 | |
| 226 | bool TxDownloadManagerImpl::MaybeAddOrphanResolutionCandidate(const std::vector<Txid>& unique_parents, const Wtxid& wtxid, NodeId nodeid, std::chrono::microseconds now) |
| 227 | { |
| 228 | auto it_peer = m_peer_info.find(nodeid); |
| 229 | if (it_peer == m_peer_info.end()) return false; |
| 230 | if (m_orphanage->HaveTxFromPeer(wtxid, nodeid)) return false; |
| 231 | |
| 232 | const auto& peer_entry = m_peer_info.at(nodeid); |
| 233 | const auto& info = peer_entry.m_connection_info; |
| 234 | |
| 235 | // TODO: add delays and limits based on the amount of orphan resolution we are already doing |
| 236 | // with this peer, how much they are using the orphanage, etc. |
| 237 | if (!info.m_relay_permissions) { |
| 238 | // This mirrors the delaying and dropping behavior in AddTxAnnouncement in order to preserve |
| 239 | // existing behavior: drop if we are tracking too many invs for this peer already. Each |
| 240 | // orphan resolution involves at least 1 transaction request which may or may not be |
| 241 | // currently tracked in m_txrequest, so we include that in the count. |
| 242 | if (m_txrequest.Count(nodeid) + unique_parents.size() > MAX_PEER_TX_ANNOUNCEMENTS) return false; |
| 243 | } |
| 244 | |
| 245 | std::chrono::seconds delay{0s}; |
| 246 | if (!info.m_preferred) delay += NONPREF_PEER_TX_DELAY; |
| 247 | // The orphan wtxid is used, but resolution entails requesting the parents by txid. Sometimes |
| 248 | // parent and child are announced and thus requested around the same time, and we happen to |
| 249 | // receive child sooner. Waiting a few seconds may allow us to cancel the orphan resolution |
| 250 | // request if the parent arrives in that time. |
| 251 | if (m_num_wtxid_peers > 0) delay += TXID_RELAY_DELAY; |
| 252 | const bool overloaded = !info.m_relay_permissions && m_txrequest.CountInFlight(nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT; |
| 253 | if (overloaded) delay += OVERLOADED_PEER_TX_DELAY; |
| 254 | |
| 255 | // Treat finding orphan resolution candidate as equivalent to the peer announcing all missing parents. |
| 256 | // In the future, orphan resolution may include more explicit steps |
| 257 | for (const auto& parent_txid : unique_parents) { |
| 258 | m_txrequest.ReceivedInv(nodeid, parent_txid, info.m_preferred, now + delay); |
| 259 | } |
| 260 | LogDebug(BCLog::TXPACKAGES, "added peer=%d as a candidate for resolving orphan %s\n", nodeid, wtxid.ToString()); |
| 261 | return true; |
| 262 | } |
| 263 | |
| 264 | std::vector<GenTxid> TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) |
| 265 | { |
nothing calls this directly
no test coverage detected