@@ -75,8 +75,11 @@ static const unsigned int MAX_INV_SZ = 50000;
75
75
/* * Maximum number of in-flight transaction requests from a peer. It is not a hard limit, but the threshold at which
76
76
* point the OVERLOADED_PEER_TX_DELAY kicks in. */
77
77
static constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100 ;
78
- /* * Maximum number of announced transactions from a peer */
79
- static constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 2 * MAX_INV_SZ;
78
+ /* * Maximum number of transactions to consider for requesting, per peer. It provides a reasonable DoS limit to
79
+ * per-peer memory usage spent on announcements, while covering peers continuously sending INVs at the maximum
80
+ * rate (by our own policy, see INVENTORY_BROADCAST_PER_SECOND) for several minutes, while not receiving
81
+ * the actual transaction (from any peer) in response to requests for them. */
82
+ static constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000 ;
80
83
/* * How long to delay requesting transactions via txids, if we have wtxid-relaying peers */
81
84
static constexpr auto TXID_RELAY_DELAY = std::chrono::seconds{2 };
82
85
/* * How long to delay requesting transactions from non-preferred peers */
@@ -754,7 +757,7 @@ void PeerManager::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid, std
754
757
{
755
758
AssertLockHeld (::cs_main); // For m_txrequest
756
759
NodeId nodeid = node.GetId ();
757
- if (m_txrequest.Count (nodeid) >= MAX_PEER_TX_ANNOUNCEMENTS) {
760
+ if (!node. HasPermission (PF_RELAY) && m_txrequest.Count (nodeid) >= MAX_PEER_TX_ANNOUNCEMENTS) {
758
761
// Too many queued announcements from this peer
759
762
return ;
760
763
}
@@ -766,12 +769,13 @@ void PeerManager::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid, std
766
769
// - NONPREF_PEER_TX_DELAY for announcements from non-preferred connections
767
770
// - TXID_RELAY_DELAY for announcements from txid peers while wtxid peers are available
768
771
// - OVERLOADED_PEER_TX_DELAY for announcements from peers which have at least
769
- // MAX_PEER_TX_REQUEST_IN_FLIGHT requests in flight.
772
+ // MAX_PEER_TX_REQUEST_IN_FLIGHT requests in flight (and don't have PF_RELAY) .
770
773
auto delay = std::chrono::microseconds{0 };
771
774
const bool preferred = state->fPreferredDownload ;
772
775
if (!preferred) delay += NONPREF_PEER_TX_DELAY;
773
776
if (!state->m_wtxid_relay && g_wtxid_relay_peers > 0 ) delay += TXID_RELAY_DELAY;
774
- const bool overloaded = m_txrequest.CountInFlight (nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT;
777
+ const bool overloaded = !node.HasPermission (PF_RELAY) &&
778
+ m_txrequest.CountInFlight (nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT;
775
779
if (overloaded) delay += OVERLOADED_PEER_TX_DELAY;
776
780
m_txrequest.ReceivedInv (nodeid, gtxid, preferred, current_time + delay);
777
781
}
0 commit comments