@@ -493,6 +493,17 @@ impl<Descriptor: SocketDescriptor, RM: Deref, L: Deref> PeerManager<Descriptor,
493
493
}
494
494
}
495
495
496
+ /// A simple wrapper that optionally prints " from <pubkey>" for an optional pubkey.
497
+ /// This works around `format!()` taking a reference to each argument, preventing
498
+ /// `if let Some(node_id) = peer.their_node_id { format!(.., node_id) } else { .. }` from compiling
499
+ /// due to lifetime errors.
500
+ struct OptionalFromDebugger < ' a > ( & ' a Option < PublicKey > ) ;
501
+ impl core:: fmt:: Display for OptionalFromDebugger < ' _ > {
502
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> Result < ( ) , core:: fmt:: Error > {
503
+ if let Some ( node_id) = self . 0 { write ! ( f, " from {}" , log_pubkey!( node_id) ) } else { Ok ( ( ) ) }
504
+ }
505
+ }
506
+
496
507
impl < Descriptor : SocketDescriptor , CM : Deref , RM : Deref , L : Deref , CMH : Deref > PeerManager < Descriptor , CM , RM , L , CMH > where
497
508
CM :: Target : ChannelMessageHandler ,
498
509
RM :: Target : RoutingMessageHandler ,
@@ -804,19 +815,19 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
804
815
match e. action {
805
816
msgs:: ErrorAction :: DisconnectPeer { msg: _ } => {
806
817
//TODO: Try to push msg
807
- log_debug!( self . logger, "Error handling message; disconnecting peer with: {}" , e. err) ;
818
+ log_debug!( self . logger, "Error handling message{} ; disconnecting peer with: {}" , OptionalFromDebugger ( & peer . their_node_id ) , e. err) ;
808
819
return Err ( PeerHandleError { no_connection_possible: false } ) ;
809
820
} ,
810
821
msgs:: ErrorAction :: IgnoreAndLog ( level) => {
811
- log_given_level!( self . logger, level, "Error handling message; ignoring: {}" , e. err) ;
822
+ log_given_level!( self . logger, level, "Error handling message{} ; ignoring: {}" , OptionalFromDebugger ( & peer . their_node_id ) , e. err) ;
812
823
continue
813
824
} ,
814
825
msgs:: ErrorAction :: IgnoreError => {
815
- log_debug!( self . logger, "Error handling message; ignoring: {}" , e. err) ;
826
+ log_debug!( self . logger, "Error handling message{} ; ignoring: {}" , OptionalFromDebugger ( & peer . their_node_id ) , e. err) ;
816
827
continue ;
817
828
} ,
818
829
msgs:: ErrorAction :: SendErrorMessage { msg } => {
819
- log_debug!( self . logger, "Error handling message; sending error message with: {}" , e. err) ;
830
+ log_debug!( self . logger, "Error handling message{} ; sending error message with: {}" , OptionalFromDebugger ( & peer . their_node_id ) , e. err) ;
820
831
self . enqueue_message( peer, & msg) ;
821
832
continue ;
822
833
} ,
@@ -982,7 +993,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
982
993
return Err ( PeerHandleError { no_connection_possible : false } . into ( ) ) ;
983
994
}
984
995
985
- log_info ! ( self . logger, "Received peer Init message: {}" , msg. features) ;
996
+ log_info ! ( self . logger, "Received peer Init message from {} : {}" , log_pubkey! ( peer . their_node_id . unwrap ( ) ) , msg. features) ;
986
997
987
998
if msg. features . initial_routing_sync ( ) {
988
999
peer. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
0 commit comments