@@ -169,12 +169,15 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
169
169
// The timeout after which we abandon retrying failed payments.
170
170
const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
171
171
172
- // The time in between peer reconnection attempts.
172
+ // The time in- between peer reconnection attempts.
173
173
const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
174
174
175
175
// The time in-between RGS sync attempts.
176
176
const RGS_SYNC_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
177
177
178
+ // The time in-between node announcement broadcast attempts.
179
+ const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
180
+
178
181
// The length in bytes of our wallets' keys seed.
179
182
const WALLET_KEYS_SEED_LEN : usize = 64 ;
180
183
@@ -870,6 +873,7 @@ impl Node {
870
873
let mut stop_connect = self . stop_receiver . clone ( ) ;
871
874
runtime. spawn ( async move {
872
875
let mut interval = tokio:: time:: interval ( PEER_RECONNECTION_INTERVAL ) ;
876
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
873
877
loop {
874
878
tokio:: select! {
875
879
_ = stop_connect. changed( ) => {
@@ -902,6 +906,60 @@ impl Node {
902
906
}
903
907
} ) ;
904
908
909
+ // Regularly broadcast node announcements.
910
+ let bcast_cm = Arc :: clone ( & self . channel_manager ) ;
911
+ let bcast_pm = Arc :: clone ( & self . peer_manager ) ;
912
+ let bcast_config = Arc :: clone ( & self . config ) ;
913
+ let bcast_store = Arc :: clone ( & self . kv_store ) ;
914
+ let bcast_logger = Arc :: clone ( & self . logger ) ;
915
+ let mut stop_bcast = self . stop_receiver . clone ( ) ;
916
+ runtime. spawn ( async move {
917
+ // We check every 30 secs whether our last broadcast is NODE_ANN_BCAST_INTERVAL away.
918
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 30 ) ) ;
919
+ loop {
920
+ tokio:: select! {
921
+ _ = stop_bcast. changed( ) => {
922
+ return ;
923
+ }
924
+ _ = interval. tick( ) => {
925
+ let skip_broadcast = match io:: utils:: read_latest_node_ann_bcast_timestamp( Arc :: clone( & bcast_store) ) {
926
+ Ok ( latest_bcast_time_secs) => {
927
+ // Skip if the time hasn't elapsed yet.
928
+ let next_bcast_unix_time = SystemTime :: UNIX_EPOCH + Duration :: from_secs( latest_bcast_time_secs) + NODE_ANN_BCAST_INTERVAL ;
929
+ next_bcast_unix_time. elapsed( ) . is_err( )
930
+ }
931
+ Err ( _) => {
932
+ // Don't skip if we haven't broadcasted before.
933
+ false
934
+ }
935
+ } ;
936
+
937
+ if skip_broadcast {
938
+ continue ;
939
+ }
940
+
941
+ if bcast_cm. list_channels( ) . iter( ) . any( |chan| chan. is_public) {
942
+ // Skip if we don't have any public channels.
943
+ continue ;
944
+ }
945
+
946
+ if bcast_pm. get_peer_node_ids( ) . is_empty( ) {
947
+ // Skip if we don't have any connected peers to gossip to.
948
+ continue ;
949
+ }
950
+
951
+ let addresses =
952
+ bcast_config. listening_address. iter( ) . cloned( ) . map( |a| a. 0 ) . collect( ) ;
953
+ bcast_pm. broadcast_node_announcement( [ 0 ; 3 ] , [ 0 ; 32 ] , addresses) ;
954
+
955
+ let unix_time_secs = SystemTime :: now( ) . duration_since( SystemTime :: UNIX_EPOCH ) . unwrap( ) . as_secs( ) ;
956
+ io:: utils:: write_latest_node_ann_bcast_timestamp( unix_time_secs, Arc :: clone( & bcast_store) , Arc :: clone( & bcast_logger) )
957
+ . expect( "Persistence failed" ) ;
958
+ }
959
+ }
960
+ }
961
+ } ) ;
962
+
905
963
// Setup background processing
906
964
let background_persister = Arc :: clone ( & self . kv_store ) ;
907
965
let background_event_handler = Arc :: clone ( & event_handler) ;
0 commit comments