Skip to content

Commit 6798dff

Browse files
committed
Prevent stall from peer failure/inability to respond to inventory.
1 parent 148f769 commit 6798dff

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/protocols/protocol_block_in.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,13 @@ bool protocol_block_in::handle_receive_block(const code& ec,
315315
message->validation.originator = nonce();
316316
chain_.organize(message, BIND2(handle_store_block, _1, message));
317317

318-
// Sending a new request will reset the timer as necessary.
318+
// Sending a new request will reset the timer upon inventory->get_data, but
319+
// we need to time out the lack of response to those requests when stale.
320+
// So we rest the timer in case of cleared and for not cleared.
321+
reset_timer();
322+
319323
if (cleared)
320324
send_get_blocks(null_hash);
321-
else
322-
reset_timer();
323325

324326
return true;
325327
}
@@ -419,6 +421,17 @@ void protocol_block_in::handle_timeout(const code& ec)
419421
<< "] exceeded configured block latency.";
420422
stop(ec);
421423
}
424+
425+
// Can only end up here if peer did not respond to inventory or get_data.
426+
// At this point we are caught up with an honest peer. But if we are stale
427+
// we should try another peer and not just keep pounding this one.
428+
if (chain_.is_stale())
429+
stop(error::channel_stopped);
430+
431+
// If we are not stale then we are either good or stalled until peer sends
432+
// an announcement. There is no sense pinging a broken peer, so we either
433+
// drop the peer after a certain mount of time (above 10 minutes) or rely
434+
// on other peers to keep us moving and periodically age out connections.
422435
}
423436

424437
void protocol_block_in::handle_stop(const code&)

0 commit comments

Comments
 (0)