Skip to content

Commit 686a586

Browse files
committed
Correct msgs_sent_since_pong tracking for gossip forwards
When we forward gossip messages, we use the already-encoded copy we have, pushing it onto the `gossip_broadcast_buffer`. When we have free socket buffer space, and there are no non-gossip messages pending, we'll remove it from the `gossip_broadcast_buffer` and push it onto the normal `pending_outbound_buffer` socket queue. Separately, we use `msgs_sent_since_pong` to ensure that our peer is being responsive and our messages are getting through with minimal latency. After we send 32 messages (if we've already received the `pong` for the last `ping` wensent), we send an extra `ping` and will only queue up an additional 32 forwarded gossip messages before we start dropping forwarded gossip on the floor. Previously, we (arguably) incorrectly incremented `msgs_sent_since_pong` when we pushed a message onto the `gossip_broadcast_buffer`, not when it was actually queued up in our `pending_outbound_buffer` immediate socket queue. This is fairly strange - the point of `msgs_sent_since_pong` is to keep peer latency low, we already independently enforce memory limits to ensure we drop forwarded gossip messages if a peer's message queues have grown too large. This means we potentially disconnect a peer for not draining the backlog forwarded-gossip socket queue fast enough, rather than simply dropping gossip. While this shouldn't be a big deal in practice, I do see (mostly Tor) peers disconnect on my node occasionally, and while its likely due to Tor circuits hanging and a disconnect is needed, the incorrect tracking here makes state analysis difficult as there are nearly always a flow of enough gossip messages to "send to the peer". Its also possible that this allows incredibly low bandwidth connections to stay afloat more durably.
1 parent 50391d3 commit 686a586

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,7 @@ where
15511551
}
15521552
if peer.should_buffer_gossip_broadcast() {
15531553
if let Some(msg) = peer.gossip_broadcast_buffer.pop_front() {
1554+
peer.msgs_sent_since_pong += 1;
15541555
peer.pending_outbound_buffer
15551556
.push_back(peer.channel_encryptor.encrypt_buffer(msg));
15561557
}
@@ -1714,12 +1715,6 @@ where
17141715
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(message));
17151716
}
17161717

1717-
/// Append a message to a peer's pending outbound/write gossip broadcast buffer
1718-
fn enqueue_encoded_gossip_broadcast(&self, peer: &mut Peer, encoded_message: MessageBuf) {
1719-
peer.msgs_sent_since_pong += 1;
1720-
peer.gossip_broadcast_buffer.push_back(encoded_message);
1721-
}
1722-
17231718
fn do_read_event(
17241719
&self, peer_descriptor: &mut Descriptor, data: &[u8],
17251720
) -> Result<bool, PeerHandleError> {
@@ -2689,10 +2684,8 @@ where
26892684
{
26902685
continue;
26912686
}
2692-
self.enqueue_encoded_gossip_broadcast(
2693-
&mut *peer,
2694-
MessageBuf::from_encoded(&encoded_msg),
2695-
);
2687+
let encoded_message = MessageBuf::from_encoded(&encoded_msg);
2688+
peer.gossip_broadcast_buffer.push_back(encoded_message);
26962689
}
26972690
},
26982691
wire::Message::NodeAnnouncement(ref msg) => {
@@ -2733,10 +2726,8 @@ where
27332726
{
27342727
continue;
27352728
}
2736-
self.enqueue_encoded_gossip_broadcast(
2737-
&mut *peer,
2738-
MessageBuf::from_encoded(&encoded_msg),
2739-
);
2729+
let encoded_message = MessageBuf::from_encoded(&encoded_msg);
2730+
peer.gossip_broadcast_buffer.push_back(encoded_message);
27402731
}
27412732
},
27422733
wire::Message::ChannelUpdate(ref msg) => {
@@ -2772,10 +2763,8 @@ where
27722763
{
27732764
continue;
27742765
}
2775-
self.enqueue_encoded_gossip_broadcast(
2776-
&mut *peer,
2777-
MessageBuf::from_encoded(&encoded_msg),
2778-
);
2766+
let encoded_message = MessageBuf::from_encoded(&encoded_msg);
2767+
peer.gossip_broadcast_buffer.push_back(encoded_message);
27792768
}
27802769
},
27812770
_ => {

0 commit comments

Comments
 (0)