Skip to content

Commit f7658d9

Browse files
committed
[cleanup] remove p2p_inv from AddTxAnnouncement
This param is no longer needed since orphan parent requests are added to the TxRequestTracker directly.
1 parent 063c132 commit f7658d9

6 files changed

+12
-14
lines changed

src/net_processing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
39353935
AddKnownTx(*peer, inv.hash);
39363936

39373937
if (!m_chainman.IsInitialBlockDownload()) {
3938-
const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time, /*p2p_inv=*/true)};
3938+
const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time)};
39393939
LogDebug(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
39403940
}
39413941
} else {

src/node/txdownloadman.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ class TxDownloadManager {
136136

137137
/** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received.
138138
* Also called internally when a transaction is missing parents so that we can request them.
139-
* @param[in] p2p_inv When true, only add this announcement if we don't already have the tx.
140139
* Returns true if this was a dropped inv (p2p_inv=true and we already have the tx), false otherwise. */
141-
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv);
140+
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now);
142141

143142
/** Get getdata requests to send. */
144143
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);

src/node/txdownloadman_impl.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void TxDownloadManager::DisconnectedPeer(NodeId nodeid)
3939
{
4040
m_impl->DisconnectedPeer(nodeid);
4141
}
42-
bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv)
42+
bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now)
4343
{
44-
return m_impl->AddTxAnnouncement(peer, gtxid, now, p2p_inv);
44+
return m_impl->AddTxAnnouncement(peer, gtxid, now);
4545
}
4646
std::vector<GenTxid> TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
4747
{
@@ -172,14 +172,13 @@ void TxDownloadManagerImpl::DisconnectedPeer(NodeId nodeid)
172172

173173
}
174174

175-
bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv)
175+
bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now)
176176
{
177177
// If this is an orphan we are trying to resolve, consider this peer as a orphan resolution candidate instead.
178-
// - received as an p2p inv
179178
// - is wtxid matching something in orphanage
180179
// - exists in orphanage
181180
// - peer can be an orphan resolution candidate
182-
if (p2p_inv && gtxid.IsWtxid()) {
181+
if (gtxid.IsWtxid()) {
183182
if (auto orphan_tx{m_orphanage.GetTx(Wtxid::FromUint256(gtxid.GetHash()))}) {
184183
auto unique_parents{GetUniqueParents(*orphan_tx)};
185184
std::erase_if(unique_parents, [&](const auto& txid){
@@ -205,7 +204,7 @@ bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid,
205204
}
206205

207206
// If this is an inv received from a peer and we already have it, we can drop it.
208-
if (p2p_inv && AlreadyHaveTx(gtxid, /*include_reconsiderable=*/true)) return true;
207+
if (AlreadyHaveTx(gtxid, /*include_reconsiderable=*/true)) return true;
209208

210209
auto it = m_peer_info.find(peer);
211210
if (it == m_peer_info.end()) return false;

src/node/txdownloadman_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class TxDownloadManagerImpl {
163163
/** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received.
164164
* Also called internally when a transaction is missing parents so that we can request them.
165165
*/
166-
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv);
166+
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now);
167167

168168
/** Get getdata requests to send. */
169169
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);

src/test/fuzz/txdownloadman.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ FUZZ_TARGET(txdownloadman, .init = initialize)
227227
GenTxid gtxid = fuzzed_data_provider.ConsumeBool() ?
228228
GenTxid::Txid(rand_tx->GetHash()) :
229229
GenTxid::Wtxid(rand_tx->GetWitnessHash());
230-
txdownloadman.AddTxAnnouncement(rand_peer, gtxid, time, /*p2p_inv=*/fuzzed_data_provider.ConsumeBool());
230+
txdownloadman.AddTxAnnouncement(rand_peer, gtxid, time);
231231
},
232232
[&] {
233233
txdownloadman.GetRequestsToSend(rand_peer, time);
@@ -370,7 +370,7 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize)
370370
GenTxid gtxid = fuzzed_data_provider.ConsumeBool() ?
371371
GenTxid::Txid(rand_tx->GetHash()) :
372372
GenTxid::Wtxid(rand_tx->GetWitnessHash());
373-
txdownload_impl.AddTxAnnouncement(rand_peer, gtxid, time, /*p2p_inv=*/fuzzed_data_provider.ConsumeBool());
373+
txdownload_impl.AddTxAnnouncement(rand_peer, gtxid, time);
374374
},
375375
[&] {
376376
const auto getdata_requests = txdownload_impl.GetRequestsToSend(rand_peer, time);

src/test/txdownload_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ BOOST_FIXTURE_TEST_CASE(tx_rejection_types, TestChain100Setup)
146146
/*txid_recon=*/txdownload_impl.RecentRejectsReconsiderableFilter().contains(parent_txid),
147147
/*wtxid_recon=*/txdownload_impl.RecentRejectsReconsiderableFilter().contains(parent_wtxid),
148148
/*keep=*/keep,
149-
/*txid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Txid(parent_txid), now, /*p2p_inv=*/true),
150-
/*wtxid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Wtxid(parent_wtxid), now, /*p2p_inv=*/true),
149+
/*txid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Txid(parent_txid), now),
150+
/*wtxid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Wtxid(parent_wtxid), now),
151151
};
152152
BOOST_TEST_MESSAGE("Testing behavior for " << result << (segwit_parent ? " segwit " : " nonsegwit"));
153153
actual_behavior.CheckEqual(expected_behavior, /*segwit=*/segwit_parent);

0 commit comments

Comments
 (0)