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.)
This commit is contained in:
parent
b62e35dee8
commit
994a094379
|
@ -5510,8 +5510,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;
|
||||
for (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
|
||||
|
@ -6793,7 +6792,7 @@ bool SendMessages(const Consensus::Params& params, CNode* pto, bool fSendTrickle
|
|||
vInvWait.reserve(pto->vInventoryToSend.size());
|
||||
for (const CInv& inv : pto->vInventoryToSend)
|
||||
{
|
||||
if (pto->setInventoryKnown.count(inv))
|
||||
if (pto->setInventoryKnown.contains(inv.hash))
|
||||
continue;
|
||||
|
||||
// trickle out tx inv to protect privacy
|
||||
|
@ -6814,9 +6813,9 @@ bool SendMessages(const Consensus::Params& params, 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)
|
||||
{
|
||||
|
|
|
@ -2150,7 +2150,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
|
|||
addr(addrIn),
|
||||
nKeyedNetGroup(CalculateKeyedNetGroup(addrIn)),
|
||||
addrKnown(5000, 0.001),
|
||||
setInventoryKnown(SendBufferSize() / 1000)
|
||||
setInventoryKnown(50000, 0.000001)
|
||||
{
|
||||
nServices = 0;
|
||||
hSocket = hSocketIn;
|
||||
|
@ -2176,6 +2176,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
|
|||
nSendOffset = 0;
|
||||
hashContinue = uint256();
|
||||
nStartingHeight = -1;
|
||||
setInventoryKnown.reset();
|
||||
fGetAddr = false;
|
||||
fRelayTxes = false;
|
||||
fSentAddr = false;
|
||||
|
|
|
@ -333,7 +333,7 @@ public:
|
|||
std::set<uint256> setKnown;
|
||||
|
||||
// inventory based relay
|
||||
mruset<CInv> setInventoryKnown;
|
||||
CRollingBloomFilter setInventoryKnown;
|
||||
std::vector<CInv> vInventoryToSend;
|
||||
CCriticalSection cs_inventory;
|
||||
std::set<uint256> setAskFor;
|
||||
|
@ -445,7 +445,7 @@ public:
|
|||
{
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
setInventoryKnown.insert(inv);
|
||||
setInventoryKnown.insert(inv.hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,7 +453,7 @@ public:
|
|||
{
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
if (!setInventoryKnown.count(inv))
|
||||
if (!setInventoryKnown.contains(inv.hash))
|
||||
vInventoryToSend.push_back(inv);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue