@@ -172,6 +172,9 @@ const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
172
172
// The time in-between peer reconnection attempts.
173
173
const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
174
174
175
+ // The time in-between RGS sync attempts.
176
+ const RGS_SYNC_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
177
+
175
178
// The time in-between node announcement broadcast attempts.
176
179
const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
177
180
@@ -550,7 +553,7 @@ impl Builder {
550
553
) ) ;
551
554
552
555
// Reset the RGS sync timestamp in case we somehow switch gossip sources
553
- io:: utils:: write_rgs_latest_sync_timestamp (
556
+ io:: utils:: write_latest_rgs_sync_timestamp (
554
557
0 ,
555
558
Arc :: clone ( & kv_store) ,
556
559
Arc :: clone ( & logger) ,
@@ -560,7 +563,7 @@ impl Builder {
560
563
}
561
564
GossipSourceConfig :: RapidGossipSync ( rgs_server) => {
562
565
let latest_sync_timestamp =
563
- io:: utils:: read_rgs_latest_sync_timestamp ( Arc :: clone ( & kv_store) ) . unwrap_or ( 0 ) ;
566
+ io:: utils:: read_latest_rgs_sync_timestamp ( Arc :: clone ( & kv_store) ) . unwrap_or ( 0 ) ;
564
567
Arc :: new ( GossipSource :: new_rgs (
565
568
rgs_server. clone ( ) ,
566
569
latest_sync_timestamp,
@@ -756,38 +759,39 @@ impl Node {
756
759
let gossip_source = Arc :: clone ( & self . gossip_source ) ;
757
760
let gossip_sync_store = Arc :: clone ( & self . kv_store ) ;
758
761
let gossip_sync_logger = Arc :: clone ( & self . logger ) ;
759
- let stop_gossip_sync = Arc :: clone ( & stop_running ) ;
762
+ let mut stop_gossip_sync = self . stop_receiver . clone ( ) ;
760
763
runtime. spawn ( async move {
764
+ let mut interval = tokio:: time:: interval ( RGS_SYNC_INTERVAL ) ;
761
765
loop {
762
- let gossip_sync_logger = Arc :: clone ( & gossip_sync_logger) ;
763
- let stop_gossip_sync = Arc :: clone ( & stop_gossip_sync) ;
764
- if stop_gossip_sync. load ( Ordering :: Acquire ) {
765
- return ;
766
- }
767
-
768
- let now = Instant :: now ( ) ;
769
- match gossip_source. update_rgs_snapshot ( ) . await {
770
- Ok ( updated_timestamp) => {
771
- log_info ! (
772
- gossip_sync_logger,
773
- "Background sync of RGS gossip data finished in {}ms." ,
774
- now. elapsed( ) . as_millis( )
775
- ) ;
776
- io:: utils:: write_rgs_latest_sync_timestamp (
777
- updated_timestamp,
778
- Arc :: clone ( & gossip_sync_store) ,
779
- Arc :: clone ( & gossip_sync_logger) ,
780
- )
781
- . expect ( "Persistence failed" ) ;
766
+ tokio:: select! {
767
+ _ = stop_gossip_sync. changed( ) => {
768
+ return ;
769
+ }
770
+ _ = interval. tick( ) => {
771
+ let gossip_sync_logger = Arc :: clone( & gossip_sync_logger) ;
772
+ let now = Instant :: now( ) ;
773
+ match gossip_source. update_rgs_snapshot( ) . await {
774
+ Ok ( updated_timestamp) => {
775
+ log_info!(
776
+ gossip_sync_logger,
777
+ "Background sync of RGS gossip data finished in {}ms." ,
778
+ now. elapsed( ) . as_millis( )
779
+ ) ;
780
+ io:: utils:: write_latest_rgs_sync_timestamp(
781
+ updated_timestamp,
782
+ Arc :: clone( & gossip_sync_store) ,
783
+ Arc :: clone( & gossip_sync_logger) ,
784
+ )
785
+ . expect( "Persistence failed" ) ;
786
+ }
787
+ Err ( e) => log_error!(
788
+ gossip_sync_logger,
789
+ "Background sync of RGS gossip data failed: {}" ,
790
+ e
791
+ ) ,
792
+ }
782
793
}
783
- Err ( e) => log_error ! (
784
- gossip_sync_logger,
785
- "Background sync of RGS gossip data failed: {}" ,
786
- e
787
- ) ,
788
794
}
789
-
790
- tokio:: time:: sleep ( Duration :: from_secs ( 60 * 60 ) ) . await ;
791
795
}
792
796
} ) ;
793
797
}
0 commit comments