1
+ use crate :: peer_store:: { PeerInfo , PeerStore } ;
1
2
use crate :: {
2
3
hex_utils, ChannelManager , Config , Error , KeysManager , NetworkGraph , UserChannelId , Wallet ,
3
4
} ;
@@ -251,6 +252,7 @@ where
251
252
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
252
253
logger : L ,
253
254
config : Arc < Config > ,
255
+ peer_store : Arc < PeerStore < K , L > > ,
254
256
}
255
257
256
258
impl < K : KVStore + Sync + Send + ' static , L : Deref > EventHandler < K , L >
@@ -262,6 +264,7 @@ where
262
264
channel_manager : Arc < ChannelManager < K > > , network_graph : Arc < NetworkGraph > ,
263
265
keys_manager : Arc < KeysManager > , payment_store : Arc < PaymentStore < K , L > > ,
264
266
runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > , logger : L , config : Arc < Config > ,
267
+ peer_store : Arc < PeerStore < K , L > > ,
265
268
) -> Self {
266
269
Self {
267
270
event_queue,
@@ -273,6 +276,7 @@ where
273
276
logger,
274
277
runtime,
275
278
config,
279
+ peer_store,
276
280
}
277
281
}
278
282
@@ -739,6 +743,37 @@ where
739
743
log_error ! ( self . logger, "Failed to push to event queue: {}" , e) ;
740
744
panic ! ( "Failed to push to event queue" ) ;
741
745
} ) ;
746
+ let network_graph = self . network_graph . read_only ( ) ;
747
+ let channels =
748
+ self . channel_manager . list_channels_with_counterparty ( & counterparty_node_id) ;
749
+ if let Some ( pending_channel) =
750
+ channels. into_iter ( ) . find ( |c| c. channel_id == channel_id)
751
+ {
752
+ if !pending_channel. is_outbound
753
+ && self . peer_store . get_peer ( & counterparty_node_id) . is_none ( )
754
+ {
755
+ if let Some ( address) = network_graph
756
+ . nodes ( )
757
+ . get ( & NodeId :: from_pubkey ( & counterparty_node_id) )
758
+ . and_then ( |node_info| node_info. announcement_info . as_ref ( ) )
759
+ . and_then ( |ann_info| ann_info. addresses ( ) . first ( ) )
760
+ {
761
+ let peer = PeerInfo {
762
+ node_id : counterparty_node_id,
763
+ address : address. clone ( ) ,
764
+ } ;
765
+
766
+ self . peer_store . add_peer ( peer) . unwrap_or_else ( |e| {
767
+ log_error ! (
768
+ self . logger,
769
+ "Failed to add peer {} to peer store: {}" ,
770
+ counterparty_node_id,
771
+ e
772
+ ) ;
773
+ } ) ;
774
+ }
775
+ }
776
+ }
742
777
}
743
778
LdkEvent :: ChannelReady {
744
779
channel_id, user_channel_id, counterparty_node_id, ..
0 commit comments