Skip to content

Commit c907704

Browse files
committed
DOS: Respect max per-peer blocks in flight limit
Don't allow immediate inv driven block downloads if a peer already has MAX_BLOCKS_IN_TRANSIT_PER_PEER active downloads. Prevents bogus inv spam from blowing up block transfer tracking data structures.
1 parent 4444b87 commit c907704

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3574,7 +3574,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
35743574
// doing this will result in the received block being rejected as an orphan in case it is
35753575
// not a direct successor.
35763576
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), inv.hash);
3577-
if (chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - Params().TargetSpacing() * 20) {
3577+
CNodeState *nodestate = State(pfrom->GetId());
3578+
if (chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - Params().TargetSpacing() * 20 &&
3579+
nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
35783580
vToFetch.push_back(inv);
35793581
// Mark block as in flight already, even though the actual "getdata" message only goes out
35803582
// later (within the same cs_main lock, though).

0 commit comments

Comments
 (0)