Skip to content

Commit f38f96d

Browse files
Add utility for when to drop gossip
1 parent 28c9b56 commit f38f96d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ impl Peer {
378378
InitSyncTracker::NodesSyncing(pk) => pk < node_id,
379379
}
380380
}
381+
/// Returns whether this peer's buffer is full and we should drop gossip messages.
382+
fn buffer_full_drop_gossip(&self) -> bool {
383+
if self.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
384+
|| self.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO {
385+
return false
386+
}
387+
true
388+
}
381389
}
382390

383391
/// SimpleArcPeerManager is useful when you need a PeerManager with a static lifetime, e.g.
@@ -1308,9 +1316,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
13081316
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
13091317
continue
13101318
}
1311-
if peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
1312-
|| peer.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO
1313-
{
1319+
if peer.buffer_full_drop_gossip() {
13141320
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13151321
continue;
13161322
}
@@ -1334,9 +1340,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
13341340
!peer.should_forward_node_announcement(msg.contents.node_id) {
13351341
continue
13361342
}
1337-
if peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
1338-
|| peer.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO
1339-
{
1343+
if peer.buffer_full_drop_gossip() {
13401344
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13411345
continue;
13421346
}
@@ -1359,9 +1363,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
13591363
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
13601364
continue
13611365
}
1362-
if peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
1363-
|| peer.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO
1364-
{
1366+
if peer.buffer_full_drop_gossip() {
13651367
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13661368
continue;
13671369
}

0 commit comments

Comments
 (0)