Skip to content

Commit

Permalink
Fix panic when peer is mid-handshake
Browse files Browse the repository at this point in the history
Peer::their_node_id is set to Some during the handshake process.
However, df3ab2e accesses the field
unconditionally, causing a panic. This may be triggered if a gossip
message is received mid-handshake from another peer or if the user calls
broadcast_node_announcement during this time. The latter tends to be
executed on a timer.

Ensure that Peer::their_node_id is only accessed once the handshake is
complete.
  • Loading branch information
jkczyz committed Jan 22, 2024
1 parent 5c83348 commit 3dee0cf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,13 +1835,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM

for (_, peer_mutex) in peers.iter() {
let mut peer = peer_mutex.lock().unwrap();
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if !peer.handshake_complete() ||
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
continue
}
debug_assert!(peer.their_node_id.is_some());
debug_assert!(peer.channel_encryptor.is_ready_for_encryption());
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if peer.buffer_full_drop_gossip_broadcast() {
log_gossip!(logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
continue;
Expand All @@ -1863,13 +1863,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM

for (_, peer_mutex) in peers.iter() {
let mut peer = peer_mutex.lock().unwrap();
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if !peer.handshake_complete() ||
!peer.should_forward_node_announcement(msg.contents.node_id) {
continue
}
debug_assert!(peer.their_node_id.is_some());
debug_assert!(peer.channel_encryptor.is_ready_for_encryption());
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if peer.buffer_full_drop_gossip_broadcast() {
log_gossip!(logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
continue;
Expand All @@ -1891,13 +1891,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM

for (_, peer_mutex) in peers.iter() {
let mut peer = peer_mutex.lock().unwrap();
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if !peer.handshake_complete() ||
!peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
continue
}
debug_assert!(peer.their_node_id.is_some());
debug_assert!(peer.channel_encryptor.is_ready_for_encryption());
let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None);
if peer.buffer_full_drop_gossip_broadcast() {
log_gossip!(logger, "Skipping broadcast message to {:?} as its outbound buffer is full", peer.their_node_id);
continue;
Expand Down

0 comments on commit 3dee0cf

Please sign in to comment.