From: Matt Corallo Date: Mon, 30 Jan 2023 17:56:46 +0000 (+0000) Subject: Don't apply gossip backpressure to non-channel-announcing peers X-Git-Tag: v0.0.114-beta~22^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c21480f7d3659091e7ebd0fdd71aa4de21866e75;p=rust-lightning Don't apply gossip backpressure to non-channel-announcing peers When we apply the new gossip-async-check backpressure on peer connections, if a peer has never sent us a `channel_announcement` at all, we really shouldn't delay reading their messages. This does so by tracking, on a per-peer basis, whether they've sent us a channel_announcement, and resetting that state whenever we're not backlogged. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 1bbb30b6b..cecf4332e 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -413,6 +413,12 @@ struct Peer { awaiting_pong_timer_tick_intervals: i8, received_message_since_timer_tick: bool, sent_gossip_timestamp_filter: bool, + + /// Indicates we've received a `channel_announcement` since the last time we had + /// [`PeerManager::gossip_processing_backlogged`] set (or, really, that we've received a + /// `channel_announcement` at all - we set this unconditionally but unset it every time we + /// check if we're gossip-processing-backlogged). + received_channel_announce_since_backlogged: bool, } impl Peer { @@ -449,8 +455,12 @@ impl Peer { /// Returns whether we should be reading bytes from this peer, based on whether its outbound /// buffer still has space and we don't need to pause reads to get some writes out. - fn should_read(&self) -> bool { - self.pending_outbound_buffer.len() < OUTBOUND_BUFFER_LIMIT_READ_PAUSE + fn should_read(&mut self, gossip_processing_backlogged: bool) -> bool { + if !gossip_processing_backlogged { + self.received_channel_announce_since_backlogged = false; + } + self.pending_outbound_buffer.len() < OUTBOUND_BUFFER_LIMIT_READ_PAUSE && + (!gossip_processing_backlogged || !self.received_channel_announce_since_backlogged) } /// Determines if we should push additional gossip background sync (aka "backfill") onto a peer's @@ -799,6 +809,8 @@ impl bool { - !self.gossip_processing_backlogged.load(Ordering::Relaxed) && peer.should_read() + fn peer_should_read(&self, peer: &mut Peer) -> bool { + peer.should_read(self.gossip_processing_backlogged.load(Ordering::Relaxed)) } fn update_gossip_backlogged(&self) { @@ -922,10 +936,10 @@ impl { if force_one_write && !have_written { - let should_read = self.peer_should_read(&peer); if should_read { let data_sent = descriptor.send_data(&[], should_read); debug_assert_eq!(data_sent, 0, "Can't write more than no data"); @@ -937,7 +951,7 @@ impl