@@ -89,6 +89,7 @@ pub mod logger;
8989mod message_handler;
9090pub mod payment;
9191mod peer_store;
92+ mod scoring;
9293mod sweep;
9394mod tx_broadcaster;
9495mod types;
@@ -122,7 +123,8 @@ pub use builder::NodeBuilder as Builder;
122123
123124use chain:: ChainSource ;
124125use config:: {
125- default_user_config, may_announce_channel, ChannelConfig , Config , NODE_ANN_BCAST_INTERVAL ,
126+ default_user_config, may_announce_channel, ChannelConfig , Config ,
127+ EXTERNAL_SCORES_SYNC_INTERVAL , EXTERNAL_SCORES_SYNC_TIMEOUT_SECS , NODE_ANN_BCAST_INTERVAL ,
126128 PEER_RECONNECTION_INTERVAL , RGS_SYNC_INTERVAL ,
127129} ;
128130use connection:: ConnectionManager ;
@@ -137,6 +139,7 @@ use payment::{
137139 UnifiedQrPayment ,
138140} ;
139141use peer_store:: { PeerInfo , PeerStore } ;
142+ use scoring:: ScoringSource ;
140143use types:: {
141144 Broadcaster , BumpTransactionEventHandler , ChainMonitor , ChannelManager , DynStore , Graph ,
142145 KeysManager , OnionMessenger , PeerManager , Router , Scorer , Sweeper , Wallet ,
@@ -190,6 +193,7 @@ pub struct Node {
190193 keys_manager : Arc < KeysManager > ,
191194 network_graph : Arc < Graph > ,
192195 gossip_source : Arc < GossipSource > ,
196+ scoring_source : Option < Arc < ScoringSource > > ,
193197 liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
194198 kv_store : Arc < DynStore > ,
195199 logger : Arc < Logger > ,
@@ -304,6 +308,10 @@ impl Node {
304308 } ) ;
305309 }
306310
311+ if self . scoring_source . is_some ( ) {
312+ self . setup_external_scores_syncing ( & runtime) ;
313+ }
314+
307315 if let Some ( listening_addresses) = & self . config . listening_addresses {
308316 // Setup networking
309317 let peer_manager_connection_handler = Arc :: clone ( & self . peer_manager ) ;
@@ -634,6 +642,42 @@ impl Node {
634642 Ok ( ( ) )
635643 }
636644
645+ /// Spawn a background task to sync external scores.
646+ fn setup_external_scores_syncing ( & self , runtime : & tokio:: runtime:: Runtime ) {
647+ let scoring_source = Arc :: clone ( & self . scoring_source . as_ref ( ) . unwrap ( ) ) ;
648+ log_info ! (
649+ self . logger,
650+ "External scores background syncing from {} enabled" ,
651+ scoring_source. get_url( )
652+ ) ;
653+
654+ let external_scores_sync_logger = Arc :: clone ( & self . logger ) ;
655+ let mut stop_sync = self . stop_sender . subscribe ( ) ;
656+
657+ runtime. spawn ( async move {
658+ let mut interval = tokio:: time:: interval ( EXTERNAL_SCORES_SYNC_INTERVAL ) ;
659+ loop {
660+ tokio:: select! {
661+ _ = stop_sync. changed( ) => {
662+ log_trace!(
663+ external_scores_sync_logger,
664+ "Stopping background syncing external scores." ,
665+ ) ;
666+ return ;
667+ }
668+ _ = interval. tick( ) => {
669+ log_trace!(
670+ external_scores_sync_logger,
671+ "Background sync of external scores started." ,
672+ ) ;
673+
674+ scoring_source. sync_external_scores( ) . await ;
675+ }
676+ }
677+ }
678+ } ) ;
679+ }
680+
637681 /// Disconnects all peers, stops all running background tasks, and shuts down [`Node`].
638682 ///
639683 /// After this returns most API methods will return [`Error::NotRunning`].
@@ -725,6 +769,7 @@ impl Node {
725769 locked_node_metrics. latest_fee_rate_cache_update_timestamp ;
726770 let latest_rgs_snapshot_timestamp =
727771 locked_node_metrics. latest_rgs_snapshot_timestamp . map ( |val| val as u64 ) ;
772+ let latest_scores_sync_timestamp = locked_node_metrics. latest_scores_sync_timestamp ;
728773 let latest_node_announcement_broadcast_timestamp =
729774 locked_node_metrics. latest_node_announcement_broadcast_timestamp ;
730775 let latest_channel_monitor_archival_height =
@@ -738,6 +783,7 @@ impl Node {
738783 latest_onchain_wallet_sync_timestamp,
739784 latest_fee_rate_cache_update_timestamp,
740785 latest_rgs_snapshot_timestamp,
786+ latest_scores_sync_timestamp,
741787 latest_node_announcement_broadcast_timestamp,
742788 latest_channel_monitor_archival_height,
743789 }
@@ -1547,6 +1593,8 @@ pub struct NodeStatus {
15471593 ///
15481594 /// Will be `None` if RGS isn't configured or the snapshot hasn't been updated yet.
15491595 pub latest_rgs_snapshot_timestamp : Option < u64 > ,
1596+ /// The timestamp, in seconds since start of the UNIX epoch, when we last successfully merged external scores.
1597+ pub latest_scores_sync_timestamp : Option < u64 > ,
15501598 /// The timestamp, in seconds since start of the UNIX epoch, when we last broadcasted a node
15511599 /// announcement.
15521600 ///
@@ -1565,6 +1613,7 @@ pub(crate) struct NodeMetrics {
15651613 latest_onchain_wallet_sync_timestamp : Option < u64 > ,
15661614 latest_fee_rate_cache_update_timestamp : Option < u64 > ,
15671615 latest_rgs_snapshot_timestamp : Option < u32 > ,
1616+ latest_scores_sync_timestamp : Option < u64 > ,
15681617 latest_node_announcement_broadcast_timestamp : Option < u64 > ,
15691618 latest_channel_monitor_archival_height : Option < u32 > ,
15701619}
@@ -1576,6 +1625,7 @@ impl Default for NodeMetrics {
15761625 latest_onchain_wallet_sync_timestamp : None ,
15771626 latest_fee_rate_cache_update_timestamp : None ,
15781627 latest_rgs_snapshot_timestamp : None ,
1628+ latest_scores_sync_timestamp : None ,
15791629 latest_node_announcement_broadcast_timestamp : None ,
15801630 latest_channel_monitor_archival_height : None ,
15811631 }
@@ -1589,6 +1639,7 @@ impl_writeable_tlv_based!(NodeMetrics, {
15891639 ( 6 , latest_rgs_snapshot_timestamp, option) ,
15901640 ( 8 , latest_node_announcement_broadcast_timestamp, option) ,
15911641 ( 10 , latest_channel_monitor_archival_height, option) ,
1642+ ( 12 , latest_scores_sync_timestamp, option) ,
15921643} ) ;
15931644
15941645pub ( crate ) fn total_anchor_channels_reserve_sats (
0 commit comments