@@ -1665,13 +1665,16 @@ where
16651665
16661666 /// Append a message to a peer's pending outbound/write buffer
16671667 fn enqueue_message < M : wire:: Type > ( & self , peer : & mut Peer , message : & M ) {
1668- // `unwrap` SAFETY: `their_node_id` is guaranteed to be `Some` after the handshake
1669- let node_id = peer. their_node_id . unwrap ( ) . 0 ;
1670- let logger = WithContext :: from ( & self . logger , Some ( node_id) , None , None ) ;
1671- if is_gossip_msg ( message. type_id ( ) ) {
1672- log_gossip ! ( logger, "Enqueueing message {:?} to {}" , message, log_pubkey!( node_id) ) ;
1668+ let their_node_id = peer. their_node_id . map ( |p| p. 0 ) ;
1669+ if let Some ( node_id) = their_node_id {
1670+ let logger = WithContext :: from ( & self . logger , their_node_id, None , None ) ;
1671+ if is_gossip_msg ( message. type_id ( ) ) {
1672+ log_gossip ! ( logger, "Enqueueing message {:?} to {}" , message, log_pubkey!( node_id) ) ;
1673+ } else {
1674+ log_trace ! ( logger, "Enqueueing message {:?} to {}" , message, log_pubkey!( node_id) ) ;
1675+ }
16731676 } else {
1674- log_trace ! ( logger , "Enqueueing message {:?} to {}" , message , log_pubkey! ( node_id ) ) ;
1677+ debug_assert ! ( false , "node_id should be set by the time we send a message" ) ;
16751678 }
16761679 peer. msgs_sent_since_pong += 1 ;
16771680 peer. pending_outbound_buffer . push_back ( peer. channel_encryptor . encrypt_message ( message) ) ;
@@ -1774,7 +1777,12 @@ where
17741777
17751778 macro_rules! insert_node_id {
17761779 ( ) => {
1777- let their_node_id = peer. their_node_id. unwrap( ) . 0 ;
1780+ let their_node_id = if let Some ( ( node_id, _) ) = peer. their_node_id {
1781+ node_id
1782+ } else {
1783+ debug_assert!( false , "Should have a node_id to insert" ) ;
1784+ return Err ( PeerHandleError { } ) ;
1785+ } ;
17781786 let logger = WithContext :: from( & self . logger, Some ( their_node_id) , None , None ) ;
17791787 match self . node_id_to_descriptor. lock( ) . unwrap( ) . entry( their_node_id) {
17801788 hash_map:: Entry :: Occupied ( e) => {
0 commit comments