@@ -89,6 +89,7 @@ pub mod logger;
89
89
mod message_handler;
90
90
pub mod payment;
91
91
mod peer_store;
92
+ mod scoring;
92
93
mod sweep;
93
94
mod tx_broadcaster;
94
95
mod types;
@@ -122,7 +123,8 @@ pub use builder::NodeBuilder as Builder;
122
123
123
124
use chain:: ChainSource ;
124
125
use 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 ,
126
128
PEER_RECONNECTION_INTERVAL , RGS_SYNC_INTERVAL ,
127
129
} ;
128
130
use connection:: ConnectionManager ;
@@ -137,6 +139,7 @@ use payment::{
137
139
UnifiedQrPayment ,
138
140
} ;
139
141
use peer_store:: { PeerInfo , PeerStore } ;
142
+ use scoring:: ScoringSource ;
140
143
use types:: {
141
144
Broadcaster , BumpTransactionEventHandler , ChainMonitor , ChannelManager , DynStore , Graph ,
142
145
KeysManager , OnionMessenger , PeerManager , Router , Scorer , Sweeper , Wallet ,
@@ -190,6 +193,7 @@ pub struct Node {
190
193
keys_manager : Arc < KeysManager > ,
191
194
network_graph : Arc < Graph > ,
192
195
gossip_source : Arc < GossipSource > ,
196
+ scoring_source : Option < Arc < ScoringSource > > ,
193
197
liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
194
198
kv_store : Arc < DynStore > ,
195
199
logger : Arc < Logger > ,
@@ -304,6 +308,11 @@ impl Node {
304
308
} ) ;
305
309
}
306
310
311
+ // If scoring source is set
312
+ if self . scoring_source . is_some ( ) {
313
+ self . setup_external_scores_syncing ( & runtime) ;
314
+ }
315
+
307
316
if let Some ( listening_addresses) = & self . config . listening_addresses {
308
317
// Setup networking
309
318
let peer_manager_connection_handler = Arc :: clone ( & self . peer_manager ) ;
@@ -634,6 +643,42 @@ impl Node {
634
643
Ok ( ( ) )
635
644
}
636
645
646
+ /// Spawn a background task to sync external scores from the given `url`.
647
+ fn setup_external_scores_syncing ( & self , runtime : & tokio:: runtime:: Runtime ) {
648
+ let scoring_source = Arc :: clone ( & self . scoring_source . as_ref ( ) . unwrap ( ) ) ;
649
+ log_info ! (
650
+ self . logger,
651
+ "External scores background syncing from {} enabled" ,
652
+ scoring_source. get_url( )
653
+ ) ;
654
+
655
+ let external_scores_sync_logger = Arc :: clone ( & self . logger ) ;
656
+ let mut stop_sync = self . stop_sender . subscribe ( ) ;
657
+
658
+ runtime. spawn ( async move {
659
+ let mut interval = tokio:: time:: interval ( EXTERNAL_SCORES_SYNC_INTERVAL ) ;
660
+ loop {
661
+ tokio:: select! {
662
+ _ = stop_sync. changed( ) => {
663
+ log_trace!(
664
+ external_scores_sync_logger,
665
+ "Stopping background syncing external scores." ,
666
+ ) ;
667
+ return ;
668
+ }
669
+ _ = interval. tick( ) => {
670
+ log_trace!(
671
+ external_scores_sync_logger,
672
+ "Background sync of external scores started." ,
673
+ ) ;
674
+
675
+ scoring_source. sync_external_scores( ) . await ;
676
+ }
677
+ }
678
+ }
679
+ } ) ;
680
+ }
681
+
637
682
/// Disconnects all peers, stops all running background tasks, and shuts down [`Node`].
638
683
///
639
684
/// After this returns most API methods will return [`Error::NotRunning`].
@@ -725,6 +770,7 @@ impl Node {
725
770
locked_node_metrics. latest_fee_rate_cache_update_timestamp ;
726
771
let latest_rgs_snapshot_timestamp =
727
772
locked_node_metrics. latest_rgs_snapshot_timestamp . map ( |val| val as u64 ) ;
773
+ let latest_scores_sync_timestamp = locked_node_metrics. latest_scores_sync_timestamp ;
728
774
let latest_node_announcement_broadcast_timestamp =
729
775
locked_node_metrics. latest_node_announcement_broadcast_timestamp ;
730
776
let latest_channel_monitor_archival_height =
@@ -738,6 +784,7 @@ impl Node {
738
784
latest_onchain_wallet_sync_timestamp,
739
785
latest_fee_rate_cache_update_timestamp,
740
786
latest_rgs_snapshot_timestamp,
787
+ latest_scores_sync_timestamp,
741
788
latest_node_announcement_broadcast_timestamp,
742
789
latest_channel_monitor_archival_height,
743
790
}
@@ -1547,6 +1594,8 @@ pub struct NodeStatus {
1547
1594
///
1548
1595
/// Will be `None` if RGS isn't configured or the snapshot hasn't been updated yet.
1549
1596
pub latest_rgs_snapshot_timestamp : Option < u64 > ,
1597
+ /// The timestamp, in seconds since start of the UNIX epoch, when we last successfully merged external scores.
1598
+ pub latest_scores_sync_timestamp : Option < u64 > ,
1550
1599
/// The timestamp, in seconds since start of the UNIX epoch, when we last broadcasted a node
1551
1600
/// announcement.
1552
1601
///
@@ -1565,6 +1614,7 @@ pub(crate) struct NodeMetrics {
1565
1614
latest_onchain_wallet_sync_timestamp : Option < u64 > ,
1566
1615
latest_fee_rate_cache_update_timestamp : Option < u64 > ,
1567
1616
latest_rgs_snapshot_timestamp : Option < u32 > ,
1617
+ latest_scores_sync_timestamp : Option < u64 > ,
1568
1618
latest_node_announcement_broadcast_timestamp : Option < u64 > ,
1569
1619
latest_channel_monitor_archival_height : Option < u32 > ,
1570
1620
}
@@ -1576,6 +1626,7 @@ impl Default for NodeMetrics {
1576
1626
latest_onchain_wallet_sync_timestamp : None ,
1577
1627
latest_fee_rate_cache_update_timestamp : None ,
1578
1628
latest_rgs_snapshot_timestamp : None ,
1629
+ latest_scores_sync_timestamp : None ,
1579
1630
latest_node_announcement_broadcast_timestamp : None ,
1580
1631
latest_channel_monitor_archival_height : None ,
1581
1632
}
@@ -1589,6 +1640,7 @@ impl_writeable_tlv_based!(NodeMetrics, {
1589
1640
( 6 , latest_rgs_snapshot_timestamp, option) ,
1590
1641
( 8 , latest_node_announcement_broadcast_timestamp, option) ,
1591
1642
( 10 , latest_channel_monitor_archival_height, option) ,
1643
+ ( 12 , latest_scores_sync_timestamp, option) ,
1592
1644
} ) ;
1593
1645
1594
1646
pub ( crate ) fn total_anchor_channels_reserve_sats (
0 commit comments