Skip to content

Commit ec73ef3

Browse files
gmaxwellsipa
authored andcommitted
Replace setInventoryKnown with a rolling bloom filter.
Mruset setInventoryKnown was reduced to a remarkably small 1000 entries as a side effect of sendbuffer size reductions in 2012. This removes setInventoryKnown filtering from merkleBlock responses because false positives there are especially unattractive and also because I'm not sure if there aren't race conditions around the relay pool that would cause some transactions there to be suppressed. (Also, ProcessGetData was accessing setInventoryKnown without taking the required lock.)
1 parent a775182 commit ec73ef3

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,8 +4138,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
41384138
// however we MUST always provide at least what the remote peer needs
41394139
typedef std::pair<unsigned int, uint256> PairType;
41404140
BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
4141-
if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second)))
4142-
pfrom->PushMessage("tx", block.vtx[pair.first]);
4141+
pfrom->PushMessage("tx", block.vtx[pair.first]);
41434142
}
41444143
// else
41454144
// no response
@@ -5511,7 +5510,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
55115510
vInvWait.reserve(pto->vInventoryToSend.size());
55125511
BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend)
55135512
{
5514-
if (pto->setInventoryKnown.count(inv))
5513+
if (pto->setInventoryKnown.contains(inv.hash))
55155514
continue;
55165515

55175516
// trickle out tx inv to protect privacy
@@ -5532,9 +5531,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
55325531
}
55335532
}
55345533

5535-
// returns true if wasn't already contained in the set
5536-
if (pto->setInventoryKnown.insert(inv).second)
5534+
if (!pto->setInventoryKnown.contains(inv.hash))
55375535
{
5536+
pto->setInventoryKnown.insert(inv.hash);
55385537
vInv.push_back(inv);
55395538
if (vInv.size() >= 1000)
55405539
{

src/net.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", DEFAULT_MAX
23422342
CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
23432343
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
23442344
addrKnown(5000, 0.001),
2345-
setInventoryKnown(SendBufferSize() / 1000)
2345+
setInventoryKnown(50000, 0.000001)
23462346
{
23472347
nServices = 0;
23482348
hSocket = hSocketIn;
@@ -2369,6 +2369,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23692369
nSendOffset = 0;
23702370
hashContinue = uint256();
23712371
nStartingHeight = -1;
2372+
setInventoryKnown.reset();
23722373
fGetAddr = false;
23732374
fRelayTxes = false;
23742375
pfilter = new CBloomFilter();

src/net.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class CNode
386386
std::set<uint256> setKnown;
387387

388388
// inventory based relay
389-
mruset<CInv> setInventoryKnown;
389+
CRollingBloomFilter setInventoryKnown;
390390
std::vector<CInv> vInventoryToSend;
391391
CCriticalSection cs_inventory;
392392
std::multimap<int64_t, CInv> mapAskFor;
@@ -494,15 +494,15 @@ class CNode
494494
{
495495
{
496496
LOCK(cs_inventory);
497-
setInventoryKnown.insert(inv);
497+
setInventoryKnown.insert(inv.hash);
498498
}
499499
}
500500

501501
void PushInventory(const CInv& inv)
502502
{
503503
{
504504
LOCK(cs_inventory);
505-
if (!setInventoryKnown.count(inv))
505+
if (!setInventoryKnown.contains(inv.hash))
506506
vInventoryToSend.push_back(inv);
507507
}
508508
}

0 commit comments

Comments
 (0)