Skip to content

Commit ebb25f4

Browse files
committed
Limit setAskFor and retire requested entries only when a getdata returns.
The setAskFor duplicate elimination was too eager and removed entries when we still had no getdata response, allowing the peer to keep INVing and not responding.
1 parent 5029698 commit ebb25f4

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4406,6 +4406,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44064406
bool fMissingInputs = false;
44074407
CValidationState state;
44084408

4409+
pfrom->setAskFor.erase(inv.hash);
44094410
mapAlreadyAskedFor.erase(inv);
44104411

44114412
// Check for recently rejected (and do other quick existence checks)
@@ -5225,8 +5226,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
52255226
pto->PushMessage("getdata", vGetData);
52265227
vGetData.clear();
52275228
}
5229+
} else {
5230+
//If we're not going to ask, don't expect a response.
5231+
pto->setAskFor.erase(inv.hash);
52285232
}
5229-
pto->setAskFor.erase(inv.hash);
52305233
pto->mapAskFor.erase(pto->mapAskFor.begin());
52315234
}
52325235
if (!vGetData.empty())

src/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,9 +2408,9 @@ CNode::~CNode()
24082408

24092409
void CNode::AskFor(const CInv& inv)
24102410
{
2411-
if (mapAskFor.size() > MAPASKFOR_MAX_SZ)
2411+
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ)
24122412
return;
2413-
// a peer may not occupy multiple positions in an inv's request queue
2413+
// a peer may not have multiple non-responded queue positions for a single inv item
24142414
if (!setAskFor.insert(inv.hash).second)
24152415
return;
24162416

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static const bool DEFAULT_UPNP = false;
5858
#endif
5959
/** The maximum number of entries in mapAskFor */
6060
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
61+
/** The maximum number of entries in setAskFor (larger due to getdata latency)*/
62+
static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ;
6163
/** The maximum number of peer connections to maintain. */
6264
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
6365
/** The default for -maxuploadtarget. 0 = Unlimited */

0 commit comments

Comments
 (0)