Replace setInventoryKnown with a rolling bloom filter.

Github-Pull: #7133
Rebased-From: ec73ef37ec e20672479e 6b849350ab b6a0da45db d41e44c9ac aa4b0c26b0
This commit is contained in:
Gregory Maxwell
2015-11-26 05:25:30 +00:00
committed by Wladimir J. van der Laan
parent 6ba25d2886
commit f31955d9da
8 changed files with 16 additions and 166 deletions

View File

@@ -4187,8 +4187,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
@@ -5568,7 +5567,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 (inv.type == MSG_TX && pto->filterInventoryKnown.contains(inv.hash))
continue;
// trickle out tx inv to protect privacy
@@ -5589,15 +5588,13 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
}
// returns true if wasn't already contained in the set
if (pto->setInventoryKnown.insert(inv).second)
pto->filterInventoryKnown.insert(inv.hash);
vInv.push_back(inv);
if (vInv.size() >= 1000)
{
vInv.push_back(inv);
if (vInv.size() >= 1000)
{
pto->PushMessage("inv", vInv);
vInv.clear();
}
pto->PushMessage("inv", vInv);
vInv.clear();
}
}
pto->vInventoryToSend = vInvWait;