Skip to content

Commit

Permalink
Let a node opt out of tx invs before we get a their bloom filter
Browse files Browse the repository at this point in the history
Note that the default value for fRelayTxes is false, meaning we
now no longer relay tx inv messages before receiving the remote
peer's version message.
  • Loading branch information
TheBlueMatt committed Jan 16, 2013
1 parent b02ddbe commit 4c8fc1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,6 +2838,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vRecv >> pfrom->strSubVer;
if (!vRecv.empty())
vRecv >> pfrom->nStartingHeight;
if (!vRecv.empty())
vRecv >> pfrom->fRelayTxes; // set to true after we get the first filter* message
else
pfrom->fRelayTxes = true;

if (pfrom->fInbound && addrMe.IsRoutable())
{
Expand Down Expand Up @@ -3391,6 +3395,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
delete pfrom->pfilter;
pfrom->pfilter = new CBloomFilter(filter);
}
pfrom->fRelayTxes = true;
}


Expand Down Expand Up @@ -3419,6 +3424,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
LOCK(pfrom->cs_filter);
delete pfrom->pfilter;
pfrom->pfilter = NULL;
pfrom->fRelayTxes = true;
}


Expand Down
2 changes: 2 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,8 @@ void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataSt
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if(!pnode->fRelayTxes)
continue;
LOCK(pnode->cs_filter);
if (pnode->pfilter)
{
Expand Down
6 changes: 6 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class CNode
bool fNetworkNode;
bool fSuccessfullyConnected;
bool fDisconnect;
// We use fRelayTxes for two purposes -
// a) it allows us to not relay tx invs before receiving the peer's version message
// b) the peer may tell us in their version message that we should not relay tx invs
// until they have initialized their bloom filter.
bool fRelayTxes;
CSemaphoreGrant grantOutbound;
CCriticalSection cs_filter;
CBloomFilter* pfilter;
Expand Down Expand Up @@ -211,6 +216,7 @@ class CNode
nStartingHeight = -1;
fGetAddr = false;
nMisbehavior = 0;
fRelayTxes = false;
setInventoryKnown.max_size(SendBufferSize() / 1000);
pfilter = NULL;

Expand Down

0 comments on commit 4c8fc1a

Please sign in to comment.