Skip to content

Commit 5029698

Browse files
kazcwgmaxwell
authored andcommitted
prevent peer flooding request queue for an inv
mapAlreadyAskedFor does not keep track of which peer has a request queued for a particular tx. As a result, a peer can blind a node to a tx indefinitely by sending many invs for the same tx, and then never replying to getdatas for it. Each inv received will be placed 2 minutes farther back in mapAlreadyAskedFor, so a short message containing 10 invs would render that tx unavailable for 20 minutes. This is fixed by disallowing a peer from having more than one entry for a particular inv in mapAlreadyAskedFor at a time.
1 parent 0b0fc17 commit 5029698

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,6 +5226,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
52265226
vGetData.clear();
52275227
}
52285228
}
5229+
pto->setAskFor.erase(inv.hash);
52295230
pto->mapAskFor.erase(pto->mapAskFor.begin());
52305231
}
52315232
if (!vGetData.empty())

src/net.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,10 @@ void CNode::AskFor(const CInv& inv)
24102410
{
24112411
if (mapAskFor.size() > MAPASKFOR_MAX_SZ)
24122412
return;
2413+
// a peer may not occupy multiple positions in an inv's request queue
2414+
if (!setAskFor.insert(inv.hash).second)
2415+
return;
2416+
24132417
// We're using mapAskFor as a priority queue,
24142418
// the key is the earliest time the request can be sent
24152419
int64_t nRequestTime;

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ class CNode
382382
mruset<CInv> setInventoryKnown;
383383
std::vector<CInv> vInventoryToSend;
384384
CCriticalSection cs_inventory;
385+
std::set<uint256> setAskFor;
385386
std::multimap<int64_t, CInv> mapAskFor;
386387

387388
// Ping time measurement:

0 commit comments

Comments
 (0)