Skip to content

Commit 1b5118b

Browse files
committed
Merge pull request #7079
ebb25f4 Limit setAskFor and retire requested entries only when a getdata returns. (Gregory Maxwell) 5029698 prevent peer flooding request queue for an inv (kazcw)
2 parents c143c49 + ebb25f4 commit 1b5118b

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,6 +4675,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46754675
bool fMissingInputs = false;
46764676
CValidationState state;
46774677

4678+
pfrom->setAskFor.erase(inv.hash);
46784679
mapAlreadyAskedFor.erase(inv);
46794680

46804681
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
@@ -5623,6 +5624,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
56235624
pto->PushMessage("getdata", vGetData);
56245625
vGetData.clear();
56255626
}
5627+
} else {
5628+
//If we're not going to ask, don't expect a response.
5629+
pto->setAskFor.erase(inv.hash);
56265630
}
56275631
pto->mapAskFor.erase(pto->mapAskFor.begin());
56285632
}

src/net.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2407,8 +2407,12 @@ CNode::~CNode()
24072407

24082408
void CNode::AskFor(const CInv& inv)
24092409
{
2410-
if (mapAskFor.size() > MAPASKFOR_MAX_SZ)
2410+
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ)
24112411
return;
2412+
// a peer may not have multiple non-responded queue positions for a single inv item
2413+
if (!setAskFor.insert(inv.hash).second)
2414+
return;
2415+
24122416
// We're using mapAskFor as a priority queue,
24132417
// the key is the earliest time the request can be sent
24142418
int64_t nRequestTime;

src/net.h

Lines changed: 3 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 */
@@ -389,6 +391,7 @@ class CNode
389391
mruset<CInv> setInventoryKnown;
390392
std::vector<CInv> vInventoryToSend;
391393
CCriticalSection cs_inventory;
394+
std::set<uint256> setAskFor;
392395
std::multimap<int64_t, CInv> mapAskFor;
393396
// Used for headers announcements - unfiltered blocks to relay
394397
// Also protected by cs_inventory

0 commit comments

Comments
 (0)