net_processing: process unique tx INVs only

There is no reason we should process conflicting
advertisements for transactions, as they cannot be both
accepted into our mempool.

Avoid processing these and doing spurious work.
This commit is contained in:
Gregory Sanders
2026-07-14 13:43:48 -04:00
committed by Greg Sanders
parent 975a314667
commit 1278a5970d
2 changed files with 77 additions and 0 deletions

View File

@@ -57,6 +57,7 @@
#include <txmempool.h>
#include <uint256.h>
#include <util/check.h>
#include <util/hasher.h>
#include <util/strencodings.h>
#include <util/time.h>
#include <util/tokenbucket.h>
@@ -85,6 +86,7 @@
#include <set>
#include <span>
#include <typeinfo>
#include <unordered_set>
#include <utility>
using kernel::ChainstateRole;
@@ -842,6 +844,8 @@ private:
FastRandomContext m_rng GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
/** Copied into short-lived tx INV deduplication sets to avoid generating salts per message. */
const SaltedUint256Hasher m_txhash_hasher;
FeeFilterRounder m_fee_filter_rounder GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
const CChainParams& m_chainparams;
@@ -4337,6 +4341,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
}
const bool reject_tx_invs{RejectIncomingTxs(pfrom)};
std::unordered_set<uint256, SaltedUint256Hasher> seen_txids{0, m_txhash_hasher};
std::unordered_set<uint256, SaltedUint256Hasher> seen_wtxids{0, m_txhash_hasher};
LOCK2(cs_main, m_tx_download_mutex);
@@ -4375,6 +4381,9 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
pfrom.fDisconnect = true;
return;
}
// MSG_WITNESS_TX is treated as a txid, despite only being specified for getdata.
auto& seen_hashes{inv.IsMsgWtx() ? seen_wtxids : seen_txids};
if (!seen_hashes.insert(inv.hash).second) continue;
const GenTxid gtxid = ToGenTxid(inv);
AddKnownTx(peer, inv.hash);