@@ -170,9 +170,12 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
170170// The timeout after which we abandon retrying failed payments.
171171const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
172172
173- // The time in between peer reconnection attempts.
173+ // The time in- between peer reconnection attempts.
174174const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
175175
176+ // The time in-between node announcement broadcast attempts.
177+ const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 10 ) ;
178+
176179// The length in bytes of our wallets' keys seed.
177180const WALLET_KEYS_SEED_LEN : usize = 64 ;
178181
@@ -749,10 +752,13 @@ impl Node {
749752 let stop_connect = Arc :: clone ( & stop_running) ;
750753 runtime. spawn ( async move {
751754 let mut interval = tokio:: time:: interval ( PEER_RECONNECTION_INTERVAL ) ;
755+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
752756 loop {
753757 if stop_connect. load ( Ordering :: Acquire ) {
754758 return ;
755759 }
760+
761+ interval. tick ( ) . await ;
756762 let pm_peers = connect_pm
757763 . get_peer_node_ids ( )
758764 . iter ( )
@@ -774,7 +780,33 @@ impl Node {
774780 . await ;
775781 }
776782 }
777- interval. tick ( ) . await ;
783+ }
784+ } ) ;
785+
786+ // Regularly broadcast node announcements.
787+ let bcast_cm = Arc :: clone ( & self . channel_manager ) ;
788+ let bcast_pm = Arc :: clone ( & self . peer_manager ) ;
789+ let bcast_config = Arc :: clone ( & self . config ) ;
790+ let stop_bcast = Arc :: clone ( & stop_running) ;
791+ runtime. spawn ( async move {
792+ let mut interval = tokio:: time:: interval ( NODE_ANN_BCAST_INTERVAL ) ;
793+ loop {
794+ if stop_bcast. load ( Ordering :: Acquire ) {
795+ return ;
796+ }
797+
798+ if bcast_cm. list_channels ( ) . iter ( ) . any ( |chan| chan. is_public ) {
799+ interval. tick ( ) . await ;
800+
801+ while bcast_pm. get_peer_node_ids ( ) . is_empty ( ) {
802+ // Sleep a bit and retry if we don't have any peers yet.
803+ tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
804+ }
805+
806+ let addresses =
807+ bcast_config. listening_address . iter ( ) . cloned ( ) . map ( |a| a. 0 ) . collect ( ) ;
808+ bcast_pm. broadcast_node_announcement ( [ 0 ; 3 ] , [ 0 ; 32 ] , addresses) ;
809+ }
778810 }
779811 } ) ;
780812
0 commit comments