@@ -89,22 +89,6 @@ static constexpr auto PING_INTERVAL{2min};
89
89
static const unsigned int MAX_LOCATOR_SZ = 101 ;
90
90
/* * The maximum number of entries in an 'inv' protocol message */
91
91
static const unsigned int MAX_INV_SZ = 50000 ;
92
- /* * Maximum number of in-flight transaction requests from a peer. It is not a hard limit, but the threshold at which
93
- * point the OVERLOADED_PEER_TX_DELAY kicks in. */
94
- static constexpr int32_t MAX_PEER_TX_REQUEST_IN_FLIGHT = 100 ;
95
- /* * Maximum number of transactions to consider for requesting, per peer. It provides a reasonable DoS limit to
96
- * per-peer memory usage spent on announcements, while covering peers continuously sending INVs at the maximum
97
- * rate (by our own policy, see INVENTORY_BROADCAST_PER_SECOND) for several minutes, while not receiving
98
- * the actual transaction (from any peer) in response to requests for them. */
99
- static constexpr int32_t MAX_PEER_TX_ANNOUNCEMENTS = 5000 ;
100
- /* * How long to delay requesting transactions via txids, if we have wtxid-relaying peers */
101
- static constexpr auto TXID_RELAY_DELAY{2s};
102
- /* * How long to delay requesting transactions from non-preferred peers */
103
- static constexpr auto NONPREF_PEER_TX_DELAY{2s};
104
- /* * How long to delay requesting transactions from overloaded peers (see MAX_PEER_TX_REQUEST_IN_FLIGHT). */
105
- static constexpr auto OVERLOADED_PEER_TX_DELAY{2s};
106
- /* * How long to wait before downloading a transaction from an additional peer */
107
- static constexpr auto GETDATA_TX_INTERVAL{60s};
108
92
/* * Limit to avoid sending big packets. Not used in processing incoming GETDATA for compatibility */
109
93
static const unsigned int MAX_GETDATA_SZ = 1000 ;
110
94
/* * Number of blocks that can be requested at any given time from a single peer. */
@@ -156,7 +140,7 @@ static constexpr unsigned int INVENTORY_BROADCAST_TARGET = INVENTORY_BROADCAST_P
156
140
/* * Maximum number of inventory items to send per transmission. */
157
141
static constexpr unsigned int INVENTORY_BROADCAST_MAX = 1000 ;
158
142
static_assert (INVENTORY_BROADCAST_MAX >= INVENTORY_BROADCAST_TARGET, " INVENTORY_BROADCAST_MAX too low" );
159
- static_assert (INVENTORY_BROADCAST_MAX <= MAX_PEER_TX_ANNOUNCEMENTS, " INVENTORY_BROADCAST_MAX too high" );
143
+ static_assert (INVENTORY_BROADCAST_MAX <= node:: MAX_PEER_TX_ANNOUNCEMENTS, " INVENTORY_BROADCAST_MAX too high" );
160
144
/* * Average delay between feefilter broadcasts in seconds. */
161
145
static constexpr auto AVG_FEEFILTER_BROADCAST_INTERVAL{10min};
162
146
/* * Maximum feefilter broadcast delay after significant change. */
@@ -720,12 +704,6 @@ class PeerManagerImpl final : public PeerManager
720
704
721
705
void SendBlockTransactions (CNode& pfrom, Peer& peer, const CBlock& block, const BlockTransactionsRequest& req);
722
706
723
- /* * Register with TxRequestTracker that an INV has been received from a
724
- * peer. The announcement parameters are decided in PeerManager and then
725
- * passed to TxRequestTracker. */
726
- void AddTxAnnouncement (const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time)
727
- EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_tx_download_mutex);
728
-
729
707
/* * Send a message to a peer */
730
708
void PushMessage (CNode& node, CSerializedNetMsg&& msg) const { m_connman.PushMessage (&node, std::move (msg)); }
731
709
template <typename ... Args>
@@ -1571,36 +1549,6 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
1571
1549
}
1572
1550
}
1573
1551
1574
- void PeerManagerImpl::AddTxAnnouncement (const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time)
1575
- {
1576
- AssertLockHeld (::cs_main); // for State
1577
- AssertLockHeld (m_tx_download_mutex); // For m_txrequest
1578
- NodeId nodeid = node.GetId ();
1579
-
1580
- auto & m_txrequest = m_txdownloadman.GetTxRequestRef ();
1581
- if (!node.HasPermission (NetPermissionFlags::Relay) && m_txrequest.Count (nodeid) >= MAX_PEER_TX_ANNOUNCEMENTS) {
1582
- // Too many queued announcements from this peer
1583
- return ;
1584
- }
1585
- const CNodeState* state = State (nodeid);
1586
-
1587
- // Decide the TxRequestTracker parameters for this announcement:
1588
- // - "preferred": if fPreferredDownload is set (= outbound, or NetPermissionFlags::NoBan permission)
1589
- // - "reqtime": current time plus delays for:
1590
- // - NONPREF_PEER_TX_DELAY for announcements from non-preferred connections
1591
- // - TXID_RELAY_DELAY for txid announcements while wtxid peers are available
1592
- // - OVERLOADED_PEER_TX_DELAY for announcements from peers which have at least
1593
- // MAX_PEER_TX_REQUEST_IN_FLIGHT requests in flight (and don't have NetPermissionFlags::Relay).
1594
- auto delay{0us};
1595
- const bool preferred = state->fPreferredDownload ;
1596
- if (!preferred) delay += NONPREF_PEER_TX_DELAY;
1597
- if (!gtxid.IsWtxid () && m_wtxid_relay_peers > 0 ) delay += TXID_RELAY_DELAY;
1598
- const bool overloaded = !node.HasPermission (NetPermissionFlags::Relay) &&
1599
- m_txrequest.CountInFlight (nodeid) >= MAX_PEER_TX_REQUEST_IN_FLIGHT;
1600
- if (overloaded) delay += OVERLOADED_PEER_TX_DELAY;
1601
- m_txrequest.ReceivedInv (nodeid, gtxid, preferred, current_time + delay);
1602
- }
1603
-
1604
1552
void PeerManagerImpl::UpdateLastBlockAnnounceTime (NodeId node, int64_t time_in_seconds)
1605
1553
{
1606
1554
LOCK (cs_main);
@@ -4133,11 +4081,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4133
4081
AddKnownTx (*peer, inv.hash );
4134
4082
4135
4083
if (!m_chainman.IsInitialBlockDownload ()) {
4136
- const bool fAlreadyHave = m_txdownloadman.AlreadyHaveTx ( gtxid, /* include_reconsiderable =*/ true );
4084
+ const bool fAlreadyHave { m_txdownloadman.AddTxAnnouncement (pfrom. GetId (), gtxid, current_time, /* p2p_inv =*/ true )} ;
4137
4085
LogDebug (BCLog::NET, " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom.GetId ());
4138
- if (!fAlreadyHave ) {
4139
- AddTxAnnouncement (pfrom, gtxid, current_time);
4140
- }
4141
4086
}
4142
4087
} else {
4143
4088
LogDebug (BCLog::NET, " Unknown inv type \" %s\" received from peer=%d\n " , inv.ToString (), pfrom.GetId ());
@@ -4546,7 +4491,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4546
4491
AddKnownTx (*peer, parent_txid);
4547
4492
// Exclude m_lazy_recent_rejects_reconsiderable: the missing parent may have been
4548
4493
// previously rejected for being too low feerate. This orphan might CPFP it.
4549
- if (!m_txdownloadman.AlreadyHaveTx (gtxid, /* include_reconsiderable=*/ false )) AddTxAnnouncement (pfrom, gtxid, current_time);
4494
+ if (!m_txdownloadman.AlreadyHaveTx (gtxid, /* include_reconsiderable=*/ false )) {
4495
+ m_txdownloadman.AddTxAnnouncement (pfrom.GetId (), gtxid, current_time, /* p2p_inv=*/ false );
4496
+ }
4550
4497
}
4551
4498
4552
4499
if (m_orphanage.AddTx (ptx, pfrom.GetId ())) {
@@ -5186,7 +5133,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
5186
5133
if (msg_type == NetMsgType::NOTFOUND) {
5187
5134
std::vector<CInv> vInv;
5188
5135
vRecv >> vInv;
5189
- if (vInv.size () <= MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5136
+ if (vInv.size () <= node:: MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5190
5137
LOCK (m_tx_download_mutex);
5191
5138
for (CInv &inv : vInv) {
5192
5139
if (inv.IsGenTxMsg ()) {
@@ -6210,31 +6157,14 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
6210
6157
//
6211
6158
{
6212
6159
LOCK (m_tx_download_mutex);
6213
- std::vector<std::pair<NodeId, GenTxid>> expired;
6214
- auto requestable = m_txdownloadman.GetTxRequestRef ().GetRequestable (pto->GetId (), current_time, &expired);
6215
- for (const auto & entry : expired) {
6216
- LogDebug (BCLog::NET, " timeout of inflight %s %s from peer=%d\n " , entry.second .IsWtxid () ? " wtx" : " tx" ,
6217
- entry.second .GetHash ().ToString (), entry.first );
6218
- }
6219
- for (const GenTxid& gtxid : requestable) {
6220
- // Exclude m_lazy_recent_rejects_reconsiderable: we may be requesting a missing parent
6221
- // that was previously rejected for being too low feerate.
6222
- if (!m_txdownloadman.AlreadyHaveTx (gtxid, /* include_reconsiderable=*/ false )) {
6223
- LogDebug (BCLog::NET, " Requesting %s %s peer=%d\n " , gtxid.IsWtxid () ? " wtx" : " tx" ,
6224
- gtxid.GetHash ().ToString (), pto->GetId ());
6225
- vGetData.emplace_back (gtxid.IsWtxid () ? MSG_WTX : (MSG_TX | GetFetchFlags (*peer)), gtxid.GetHash ());
6226
- if (vGetData.size () >= MAX_GETDATA_SZ) {
6227
- MakeAndPushMessage (*pto, NetMsgType::GETDATA, vGetData);
6228
- vGetData.clear ();
6229
- }
6230
- m_txdownloadman.GetTxRequestRef ().RequestedTx (pto->GetId (), gtxid.GetHash (), current_time + GETDATA_TX_INTERVAL);
6231
- } else {
6232
- // We have already seen this transaction, no need to download. This is just a belt-and-suspenders, as
6233
- // this should already be called whenever a transaction becomes AlreadyHaveTx().
6234
- m_txdownloadman.GetTxRequestRef ().ForgetTxHash (gtxid.GetHash ());
6160
+ for (const GenTxid& gtxid : m_txdownloadman.GetRequestsToSend (pto->GetId (), current_time)) {
6161
+ vGetData.emplace_back (gtxid.IsWtxid () ? MSG_WTX : (MSG_TX | GetFetchFlags (*peer)), gtxid.GetHash ());
6162
+ if (vGetData.size () >= MAX_GETDATA_SZ) {
6163
+ MakeAndPushMessage (*pto, NetMsgType::GETDATA, vGetData);
6164
+ vGetData.clear ();
6235
6165
}
6236
6166
}
6237
- } // release m_tx_download_mutex
6167
+ }
6238
6168
6239
6169
if (!vGetData.empty ())
6240
6170
MakeAndPushMessage (*pto, NetMsgType::GETDATA, vGetData);
0 commit comments