Skip to content

Commit 82b3f62

Browse files
authored
Merge pull request #3309 from TheBlueMatt/2024-09-always-print-why
Always print why we disconnect explicitly
2 parents a6dea2f + 7efefd7 commit 82b3f62

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
13331333
match self.do_read_event(peer_descriptor, data) {
13341334
Ok(res) => Ok(res),
13351335
Err(e) => {
1336-
log_trace!(self.logger, "Disconnecting peer due to a protocol error (usually a duplicate connection).");
1337-
self.disconnect_event_internal(peer_descriptor);
1336+
self.disconnect_event_internal(peer_descriptor, "of a protocol error");
13381337
Err(e)
13391338
}
13401339
}
@@ -2435,7 +2434,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
24352434

24362435
/// Indicates that the given socket descriptor's connection is now closed.
24372436
pub fn socket_disconnected(&self, descriptor: &Descriptor) {
2438-
self.disconnect_event_internal(descriptor);
2437+
self.disconnect_event_internal(descriptor, "the socket was disconnected");
24392438
}
24402439

24412440
fn do_disconnect(&self, mut descriptor: Descriptor, peer: &Peer, reason: &'static str) {
@@ -2455,7 +2454,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
24552454
descriptor.disconnect_socket();
24562455
}
24572456

2458-
fn disconnect_event_internal(&self, descriptor: &Descriptor) {
2457+
fn disconnect_event_internal(&self, descriptor: &Descriptor, reason: &'static str) {
24592458
let mut peers = self.peers.write().unwrap();
24602459
let peer_option = peers.remove(descriptor);
24612460
match peer_option {
@@ -2467,7 +2466,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
24672466
Some(peer_lock) => {
24682467
let peer = peer_lock.lock().unwrap();
24692468
if let Some((node_id, _)) = peer.their_node_id {
2470-
log_trace!(WithContext::from(&self.logger, Some(node_id), None, None), "Handling disconnection of peer {}", log_pubkey!(node_id));
2469+
let logger = WithContext::from(&self.logger, Some(node_id), None, None);
2470+
log_trace!(logger, "Handling disconnection of peer {} because {}", log_pubkey!(node_id), reason);
24712471
let removed = self.node_id_to_descriptor.lock().unwrap().remove(&node_id);
24722472
debug_assert!(removed.is_some(), "descriptor maps should be consistent");
24732473
if !peer.handshake_complete() { return; }

0 commit comments

Comments
 (0)