Skip to content

Commit

Permalink
Replace setInventoryKnown with a rolling bloom filter.
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
gmaxwell authored and sipa committed Nov 30, 2015
1 parent a775182 commit ec73ef3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4138,8 +4138,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
// however we MUST always provide at least what the remote peer needs
typedef std::pair<unsigned int, uint256> PairType;
BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second)))
pfrom->PushMessage("tx", block.vtx[pair.first]);
pfrom->PushMessage("tx", block.vtx[pair.first]);
}
// else
// no response
Expand Down Expand Up @@ -5511,7 +5510,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
vInvWait.reserve(pto->vInventoryToSend.size());
BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend)
{
if (pto->setInventoryKnown.count(inv))
if (pto->setInventoryKnown.contains(inv.hash))
continue;

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

// returns true if wasn't already contained in the set
if (pto->setInventoryKnown.insert(inv).second)
if (!pto->setInventoryKnown.contains(inv.hash))
{
pto->setInventoryKnown.insert(inv.hash);
vInv.push_back(inv);
if (vInv.size() >= 1000)
{
Expand Down
3 changes: 2 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", DEFAULT_MAX
CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
addrKnown(5000, 0.001),
setInventoryKnown(SendBufferSize() / 1000)
setInventoryKnown(50000, 0.000001)
{
nServices = 0;
hSocket = hSocketIn;
Expand All @@ -2369,6 +2369,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
nSendOffset = 0;
hashContinue = uint256();
nStartingHeight = -1;
setInventoryKnown.reset();
fGetAddr = false;
fRelayTxes = false;
pfilter = new CBloomFilter();
Expand Down
6 changes: 3 additions & 3 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class CNode
std::set<uint256> setKnown;

// inventory based relay
mruset<CInv> setInventoryKnown;
CRollingBloomFilter setInventoryKnown;
std::vector<CInv> vInventoryToSend;
CCriticalSection cs_inventory;
std::multimap<int64_t, CInv> mapAskFor;
Expand Down Expand Up @@ -494,15 +494,15 @@ class CNode
{
{
LOCK(cs_inventory);
setInventoryKnown.insert(inv);
setInventoryKnown.insert(inv.hash);
}
}

void PushInventory(const CInv& inv)
{
{
LOCK(cs_inventory);
if (!setInventoryKnown.count(inv))
if (!setInventoryKnown.contains(inv.hash))
vInventoryToSend.push_back(inv);
}
}
Expand Down

0 comments on commit ec73ef3

Please sign in to comment.