From: Matt Corallo Date: Thu, 10 Jun 2021 18:26:57 +0000 (+0000) Subject: Skip forwarding gossip messages to peers if their buffer is over-full X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=a6fcb741547c3c624676ab6ebe563b9f2c25229a;p=rust-lightning Skip forwarding gossip messages to peers if their buffer is over-full --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index c7300aed3..8695ffdb8 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -234,6 +234,13 @@ enum InitSyncTracker{ NodesSyncing(PublicKey), } +/// When the outbound buffer has this many messages, we'll stop reading bytes from the peer until +/// we manage to send messages until we reach this limit. +const OUTBOUND_BUFFER_LIMIT_READ_PAUSE: usize = 10; +/// When the outbound buffer has this many messages, we'll simply skip relaying gossip messages to +/// the peer. +const OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP: usize = 20; + struct Peer { channel_encryptor: PeerChannelEncryptor, their_node_id: Option, @@ -532,13 +539,12 @@ impl PeerManager {}, InitSyncTracker::ChannelsSyncing(c) if c < 0xffff_ffff_ffff_ffff => { - let steps = ((MSG_BUFF_SIZE - peer.pending_outbound_buffer.len() + 2) / 3) as u8; + let steps = ((OUTBOUND_BUFFER_LIMIT_READ_PAUSE - peer.pending_outbound_buffer.len() + 2) / 3) as u8; let all_messages = self.message_handler.route_handler.get_next_channel_announcements(c, steps); for &(ref announce, ref update_a_option, ref update_b_option) in all_messages.iter() { encode_and_send_msg!(announce); @@ -555,7 +561,7 @@ impl PeerManager { - let steps = (MSG_BUFF_SIZE - peer.pending_outbound_buffer.len()) as u8; + let steps = (OUTBOUND_BUFFER_LIMIT_READ_PAUSE - peer.pending_outbound_buffer.len()) as u8; let all_messages = self.message_handler.route_handler.get_next_node_announcements(None, steps); for msg in all_messages.iter() { encode_and_send_msg!(msg); @@ -567,7 +573,7 @@ impl PeerManager unreachable!(), InitSyncTracker::NodesSyncing(key) => { - let steps = (MSG_BUFF_SIZE - peer.pending_outbound_buffer.len()) as u8; + let steps = (OUTBOUND_BUFFER_LIMIT_READ_PAUSE - peer.pending_outbound_buffer.len()) as u8; let all_messages = self.message_handler.route_handler.get_next_node_announcements(Some(&key), steps); for msg in all_messages.iter() { encode_and_send_msg!(msg); @@ -586,7 +592,7 @@ impl PeerManager buff, }; - let should_be_reading = peer.pending_outbound_buffer.len() < MSG_BUFF_SIZE; + let should_be_reading = peer.pending_outbound_buffer.len() < OUTBOUND_BUFFER_LIMIT_READ_PAUSE; let pending = &next_buff[peer.pending_outbound_buffer_first_msg_offset..]; let data_sent = descriptor.send_data(pending, should_be_reading); peer.pending_outbound_buffer_first_msg_offset += data_sent; @@ -815,7 +821,7 @@ impl PeerManager 10 // pause_read + peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_READ_PAUSE // pause_read } }; @@ -1028,6 +1034,9 @@ impl PeerManager OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP { + continue; + } if peer.their_node_id.as_ref() == Some(&msg.contents.node_id_1) || peer.their_node_id.as_ref() == Some(&msg.contents.node_id_2) { continue; @@ -1047,6 +1056,9 @@ impl PeerManager OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP { + continue; + } if peer.their_node_id.as_ref() == Some(&msg.contents.node_id) { continue; } @@ -1065,6 +1077,9 @@ impl PeerManager OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP { + continue; + } if except_node.is_some() && peer.their_node_id.as_ref() == except_node { continue; }