@@ -298,23 +298,27 @@ const OUTBOUND_BUFFER_LIMIT_READ_PAUSE: usize = 10;
298
298
/// the peer.
299
299
const OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP : usize = OUTBOUND_BUFFER_LIMIT_READ_PAUSE * FORWARD_INIT_SYNC_BUFFER_SIZE_LIMIT ;
300
300
301
- /// If we've sent a ping, and are still awaiting a response, we (or our peer) may need to churn our
302
- /// (or their) way through the socket receive buffer before receiving the ping.
301
+ /// If we've sent a ping, and are still awaiting a response, we may need to churn our way through
302
+ /// the socket receive buffer before receiving the ping.
303
303
///
304
304
/// On a fairly old Arm64 board, with Linux defaults, this can take as long as 20 seconds, not
305
- /// including any network delays or outbound traffic.
305
+ /// including any network delays, outbound traffic, or the same for messages from other peers .
306
306
///
307
307
/// Thus, to avoid needlessly disconnecting a peer, we allow a peer to take this many timer ticks
308
- /// to respond to a ping, as long as they send us at least one message during each tick or if we
309
- /// sent a lot of messages, ensuring we aren't actually just disconnected. With a timer tick
310
- /// interval of five seconds, this translates to about 30 seconds.
311
- pub const MAX_BUFFER_DRAIN_TICK_INTERVALS : i8 = 6 ;
308
+ /// per connected peer to respond to a ping, as long as they send us at least one message during
309
+ /// each tick, ensuring we aren't actually just disconnected.
310
+ /// With a timer tick interval of five seconds, this translates to about 30 seconds per connected
311
+ /// peer.
312
+ ///
313
+ /// When we improve parallelism somewhat we should reduce this to e.g. this many timer ticks per
314
+ /// two connected peers, assuming most LDK-running systems have at least two cores.
315
+ const MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER : i8 = 6 ;
312
316
313
317
/// This is the minimum number of messages we expect a peer to be able to handle within one timer
314
318
/// tick. Once we have sent this many messages since the last ping, we send a ping right away to
315
319
/// ensures we don't just fill up our send buffer and leave the peer with too many messages to
316
320
/// process before the next ping.
317
- pub const BUFFER_DRAIN_MSGS_PER_TICK : usize = 32 ;
321
+ const BUFFER_DRAIN_MSGS_PER_TICK : usize = 32 ;
318
322
319
323
struct Peer {
320
324
channel_encryptor : PeerChannelEncryptor ,
@@ -1523,6 +1527,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
1523
1527
let node_id_to_descriptor = & mut peers. node_id_to_descriptor ;
1524
1528
let peers = & mut peers. peers ;
1525
1529
let mut descriptors_needing_disconnect = Vec :: new ( ) ;
1530
+ let peer_count = peers. len ( ) ;
1526
1531
1527
1532
peers. retain ( |descriptor, peer| {
1528
1533
if !peer. channel_encryptor . is_ready_for_encryption ( ) {
@@ -1531,7 +1536,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
1531
1536
}
1532
1537
1533
1538
if ( peer. awaiting_pong_tick_intervals > 0 && !peer. received_message_since_timer_tick )
1534
- || peer. awaiting_pong_tick_intervals > MAX_BUFFER_DRAIN_TICK_INTERVALS
1539
+ || peer. awaiting_pong_tick_intervals as u64 >
1540
+ MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER as u64 * peer_count as u64
1535
1541
{
1536
1542
descriptors_needing_disconnect. push ( descriptor. clone ( ) ) ;
1537
1543
match peer. their_node_id {
0 commit comments