Skip to content

Commit 3a41926

Browse files
committed
[refactor] move notfound processing to txdownload
1 parent 042a97c commit 3a41926

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,16 +5133,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
51335133
if (msg_type == NetMsgType::NOTFOUND) {
51345134
std::vector<CInv> vInv;
51355135
vRecv >> vInv;
5136+
std::vector<uint256> tx_invs;
51365137
if (vInv.size() <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5137-
LOCK(m_tx_download_mutex);
51385138
for (CInv &inv : vInv) {
51395139
if (inv.IsGenTxMsg()) {
5140-
// If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as
5141-
// completed in TxRequestTracker.
5142-
m_txdownloadman.GetTxRequestRef().ReceivedResponse(pfrom.GetId(), inv.hash);
5140+
tx_invs.emplace_back(inv.hash);
51435141
}
51445142
}
51455143
}
5144+
LOCK(m_tx_download_mutex);
5145+
m_txdownloadman.ReceivedNotFound(pfrom.GetId(), tx_invs);
51465146
return;
51475147
}
51485148

src/node/txdownloadman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class TxDownloadManager {
108108

109109
/** Get getdata requests to send. */
110110
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
111+
112+
/** Should be called when a notfound for a tx has been received. */
113+
void ReceivedNotFound(NodeId nodeid, const std::vector<uint256>& txhashes);
111114
};
112115
} // namespace node
113116
#endif // BITCOIN_NODE_TXDOWNLOADMAN_H

src/node/txdownloadman_impl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ std::vector<GenTxid> TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::ch
6767
{
6868
return m_impl->GetRequestsToSend(nodeid, current_time);
6969
}
70+
void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector<uint256>& txhashes)
71+
{
72+
m_impl->ReceivedNotFound(nodeid, txhashes);
73+
}
7074

7175
// TxDownloadManagerImpl
7276
void TxDownloadManagerImpl::ActiveTipChange()
@@ -205,4 +209,13 @@ std::vector<GenTxid> TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std
205209
}
206210
return requests;
207211
}
212+
213+
void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector<uint256>& txhashes)
214+
{
215+
for (const auto& txhash : txhashes) {
216+
// If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as
217+
// completed in TxRequestTracker.
218+
m_txrequest.ReceivedResponse(nodeid, txhash);
219+
}
220+
}
208221
} // namespace node

src/node/txdownloadman_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class TxDownloadManagerImpl {
156156

157157
/** Get getdata requests to send. */
158158
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
159+
160+
/** Marks a tx as ReceivedResponse in txrequest. */
161+
void ReceivedNotFound(NodeId nodeid, const std::vector<uint256>& txhashes);
159162
};
160163
} // namespace node
161164
#endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H

0 commit comments

Comments
 (0)