diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 663dbb7634b..e4c57c0336d 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3935,7 +3935,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, AddKnownTx(*peer, inv.hash); if (!m_chainman.IsInitialBlockDownload()) { - const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time, /*p2p_inv=*/true)}; + const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time)}; LogDebug(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); } } else { diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index 2d066cab53f..1ae833a6be6 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -136,9 +136,8 @@ public: /** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received. * Also called internally when a transaction is missing parents so that we can request them. - * @param[in] p2p_inv When true, only add this announcement if we don't already have the tx. * Returns true if this was a dropped inv (p2p_inv=true and we already have the tx), false otherwise. */ - bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv); + bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now); /** Get getdata requests to send. */ std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index c7eacff4b6b..82443115bad 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -39,9 +39,9 @@ void TxDownloadManager::DisconnectedPeer(NodeId nodeid) { m_impl->DisconnectedPeer(nodeid); } -bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv) +bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now) { - return m_impl->AddTxAnnouncement(peer, gtxid, now, p2p_inv); + return m_impl->AddTxAnnouncement(peer, gtxid, now); } std::vector TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) { @@ -172,14 +172,13 @@ void TxDownloadManagerImpl::DisconnectedPeer(NodeId nodeid) } -bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv) +bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now) { // If this is an orphan we are trying to resolve, consider this peer as a orphan resolution candidate instead. - // - received as an p2p inv // - is wtxid matching something in orphanage // - exists in orphanage // - peer can be an orphan resolution candidate - if (p2p_inv && gtxid.IsWtxid()) { + if (gtxid.IsWtxid()) { if (auto orphan_tx{m_orphanage.GetTx(Wtxid::FromUint256(gtxid.GetHash()))}) { auto unique_parents{GetUniqueParents(*orphan_tx)}; std::erase_if(unique_parents, [&](const auto& txid){ @@ -205,7 +204,7 @@ bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, } // If this is an inv received from a peer and we already have it, we can drop it. - if (p2p_inv && AlreadyHaveTx(gtxid, /*include_reconsiderable=*/true)) return true; + if (AlreadyHaveTx(gtxid, /*include_reconsiderable=*/true)) return true; auto it = m_peer_info.find(peer); if (it == m_peer_info.end()) return false; diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index e5e487c4792..ab563b22415 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -163,7 +163,7 @@ public: /** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received. * Also called internally when a transaction is missing parents so that we can request them. */ - bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now, bool p2p_inv); + bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now); /** Get getdata requests to send. */ std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); diff --git a/src/test/fuzz/txdownloadman.cpp b/src/test/fuzz/txdownloadman.cpp index 8a4d7d55c26..f78cd71ce9c 100644 --- a/src/test/fuzz/txdownloadman.cpp +++ b/src/test/fuzz/txdownloadman.cpp @@ -227,7 +227,7 @@ FUZZ_TARGET(txdownloadman, .init = initialize) GenTxid gtxid = fuzzed_data_provider.ConsumeBool() ? GenTxid::Txid(rand_tx->GetHash()) : GenTxid::Wtxid(rand_tx->GetWitnessHash()); - txdownloadman.AddTxAnnouncement(rand_peer, gtxid, time, /*p2p_inv=*/fuzzed_data_provider.ConsumeBool()); + txdownloadman.AddTxAnnouncement(rand_peer, gtxid, time); }, [&] { txdownloadman.GetRequestsToSend(rand_peer, time); @@ -370,7 +370,7 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize) GenTxid gtxid = fuzzed_data_provider.ConsumeBool() ? GenTxid::Txid(rand_tx->GetHash()) : GenTxid::Wtxid(rand_tx->GetWitnessHash()); - txdownload_impl.AddTxAnnouncement(rand_peer, gtxid, time, /*p2p_inv=*/fuzzed_data_provider.ConsumeBool()); + txdownload_impl.AddTxAnnouncement(rand_peer, gtxid, time); }, [&] { const auto getdata_requests = txdownload_impl.GetRequestsToSend(rand_peer, time); diff --git a/src/test/txdownload_tests.cpp b/src/test/txdownload_tests.cpp index 88064b5a5f8..463eb210139 100644 --- a/src/test/txdownload_tests.cpp +++ b/src/test/txdownload_tests.cpp @@ -146,8 +146,8 @@ BOOST_FIXTURE_TEST_CASE(tx_rejection_types, TestChain100Setup) /*txid_recon=*/txdownload_impl.RecentRejectsReconsiderableFilter().contains(parent_txid), /*wtxid_recon=*/txdownload_impl.RecentRejectsReconsiderableFilter().contains(parent_wtxid), /*keep=*/keep, - /*txid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Txid(parent_txid), now, /*p2p_inv=*/true), - /*wtxid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Wtxid(parent_wtxid), now, /*p2p_inv=*/true), + /*txid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Txid(parent_txid), now), + /*wtxid_inv=*/txdownload_impl.AddTxAnnouncement(nodeid, GenTxid::Wtxid(parent_wtxid), now), }; BOOST_TEST_MESSAGE("Testing behavior for " << result << (segwit_parent ? " segwit " : " nonsegwit")); actual_behavior.CheckEqual(expected_behavior, /*segwit=*/segwit_parent);