Skip to content

Commit ef5859a

Browse files
Add utility for when to drop gossip
1 parent f792de6 commit ef5859a

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
@@ -393,6 +393,14 @@ impl Peer {
393393
InitSyncTracker::NodesSyncing(pk) => pk < node_id,
394394
}
395395
}
396+
/// Returns whether this peer's buffer is full and we should drop gossip messages.
397+
fn buffer_full_drop_gossip(&self) -> bool {
398+
if self.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
399+
|| self.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO {
400+
return false
401+
}
402+
true
403+
}
396404
}
397405

398406
/// SimpleArcPeerManager is useful when you need a PeerManager with a static lifetime, e.g.
@@ -1333,9 +1341,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
13331341
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
13341342
continue
13351343
}
1336-
if peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
1337-
|| peer.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO
1338-
{
1344+
if peer.buffer_full_drop_gossip() {
13391345
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13401346
continue;
13411347
}
@@ -1359,9 +1365,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
13591365
!peer.should_forward_node_announcement(msg.contents.node_id) {
13601366
continue
13611367
}
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-
{
1368+
if peer.buffer_full_drop_gossip() {
13651369
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13661370
continue;
13671371
}
@@ -1384,9 +1388,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
13841388
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
13851389
continue
13861390
}
1387-
if peer.pending_outbound_buffer.len() > OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP
1388-
|| peer.msgs_sent_since_pong > BUFFER_DRAIN_MSGS_PER_TICK * FORWARD_INIT_SYNC_BUFFER_LIMIT_RATIO
1389-
{
1391+
if peer.buffer_full_drop_gossip() {
13901392
log_gossip!(self.logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
13911393
continue;
13921394
}

0 commit comments

Comments
 (0)