Skip to content

Commit 74d0482

Browse files
gmaxwellfurszy
authored andcommitted
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 3b3bf63 commit 74d0482

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/net.cpp

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

24882488
void CNode::AskFor(const CInv& inv)
24892489
{
2490-
if (mapAskFor.size() > MAPASKFOR_MAX_SZ)
2490+
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ)
24912491
return;
2492-
// a peer may not occupy multiple positions in an inv's request queue
2492+
// a peer may not have multiple non-responded queue positions for a single inv item
24932493
if (!setAskFor.insert(inv.hash).second)
24942494
return;
24952495

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static const bool DEFAULT_UPNP = false;
6969
#endif
7070
/** The maximum number of entries in mapAskFor */
7171
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
72+
/** The maximum number of entries in setAskFor (larger due to getdata latency)*/
73+
static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ;
7274
/** The maximum number of peer connections to maintain. */
7375
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
7476
/** Disconnected peers are added to setOffsetDisconnectedPeers only if node has less than ENOUGH_CONNECTIONS */

src/net_processing.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
15081508
bool fMissingInputs = false;
15091509
CValidationState state;
15101510

1511+
pfrom->setAskFor.erase(inv.hash);
15111512
mapAlreadyAskedFor.erase(inv);
15121513

15131514
if (ptx->ContainsZerocoins()) {
@@ -2370,8 +2371,10 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
23702371
connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
23712372
vGetData.clear();
23722373
}
2374+
} else {
2375+
//If we're not going to ask, don't expect a response.
2376+
pto->setAskFor.erase(inv.hash);
23732377
}
2374-
pto->setAskFor.erase(inv.hash);
23752378
pto->mapAskFor.erase(pto->mapAskFor.begin());
23762379
}
23772380
if (!vGetData.empty())

0 commit comments

Comments
 (0)