diff --git a/src/net.h b/src/net.h index afbbc028796e..03ef7069c181 100644 --- a/src/net.h +++ b/src/net.h @@ -887,10 +887,15 @@ class CNode void AddInventoryKnown(const CInv& inv) + { + AddInventoryKnown(inv.hash); + } + + void AddInventoryKnown(const uint256& hash) { { LOCK(cs_inventory); - filterInventoryKnown.insert(inv.hash); + filterInventoryKnown.insert(hash); } } @@ -908,8 +913,12 @@ class CNode LogPrint("net", "PushInventory -- inv: %s peer=%d\n", inv.ToString(), id); vInventoryBlockToSend.push_back(inv.hash); } else { - LogPrint("net", "PushInventory -- inv: %s peer=%d\n", inv.ToString(), id); - vInventoryOtherToSend.push_back(inv); + if (!filterInventoryKnown.contains(inv.hash)) { + LogPrint("net", "PushInventory -- inv: %s peer=%d\n", inv.ToString(), id); + vInventoryOtherToSend.push_back(inv); + } else { + LogPrint("net", "PushInventory -- filtered inv: %s peer=%d\n", inv.ToString(), id); + } } } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1a32aa25236a..b71c76d35a78 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3431,7 +3431,11 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr // Send non-tx/non-block inventory items for (const auto& inv : pto->vInventoryOtherToSend) { + if (pto->filterInventoryKnown.contains(inv.hash)) { + continue; + } vInv.push_back(inv); + pto->filterInventoryKnown.insert(inv.hash); if (vInv.size() == MAX_INV_SZ) { connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv)); vInv.clear();