@@ -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,10 @@ impl Node {
304
308
} ) ;
305
309
}
306
310
311
+ if self . scoring_source . is_some ( ) {
312
+ self . setup_external_scores_syncing ( & runtime) ;
313
+ }
314
+
307
315
if let Some ( listening_addresses) = & self . config . listening_addresses {
308
316
// Setup networking
309
317
let peer_manager_connection_handler = Arc :: clone ( & self . peer_manager ) ;
@@ -634,6 +642,42 @@ impl Node {
634
642
Ok ( ( ) )
635
643
}
636
644
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
+
637
681
/// Disconnects all peers, stops all running background tasks, and shuts down [`Node`].
638
682
///
639
683
/// After this returns most API methods will return [`Error::NotRunning`].
@@ -725,6 +769,7 @@ impl Node {
725
769
locked_node_metrics. latest_fee_rate_cache_update_timestamp ;
726
770
let latest_rgs_snapshot_timestamp =
727
771
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 ;
728
773
let latest_node_announcement_broadcast_timestamp =
729
774
locked_node_metrics. latest_node_announcement_broadcast_timestamp ;
730
775
let latest_channel_monitor_archival_height =
@@ -738,6 +783,7 @@ impl Node {
738
783
latest_onchain_wallet_sync_timestamp,
739
784
latest_fee_rate_cache_update_timestamp,
740
785
latest_rgs_snapshot_timestamp,
786
+ latest_scores_sync_timestamp,
741
787
latest_node_announcement_broadcast_timestamp,
742
788
latest_channel_monitor_archival_height,
743
789
}
@@ -1547,6 +1593,8 @@ pub struct NodeStatus {
1547
1593
///
1548
1594
/// Will be `None` if RGS isn't configured or the snapshot hasn't been updated yet.
1549
1595
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 > ,
1550
1598
/// The timestamp, in seconds since start of the UNIX epoch, when we last broadcasted a node
1551
1599
/// announcement.
1552
1600
///
@@ -1565,6 +1613,7 @@ pub(crate) struct NodeMetrics {
1565
1613
latest_onchain_wallet_sync_timestamp : Option < u64 > ,
1566
1614
latest_fee_rate_cache_update_timestamp : Option < u64 > ,
1567
1615
latest_rgs_snapshot_timestamp : Option < u32 > ,
1616
+ latest_scores_sync_timestamp : Option < u64 > ,
1568
1617
latest_node_announcement_broadcast_timestamp : Option < u64 > ,
1569
1618
latest_channel_monitor_archival_height : Option < u32 > ,
1570
1619
}
@@ -1576,6 +1625,7 @@ impl Default for NodeMetrics {
1576
1625
latest_onchain_wallet_sync_timestamp : None ,
1577
1626
latest_fee_rate_cache_update_timestamp : None ,
1578
1627
latest_rgs_snapshot_timestamp : None ,
1628
+ latest_scores_sync_timestamp : None ,
1579
1629
latest_node_announcement_broadcast_timestamp : None ,
1580
1630
latest_channel_monitor_archival_height : None ,
1581
1631
}
@@ -1589,6 +1639,7 @@ impl_writeable_tlv_based!(NodeMetrics, {
1589
1639
( 6 , latest_rgs_snapshot_timestamp, option) ,
1590
1640
( 8 , latest_node_announcement_broadcast_timestamp, option) ,
1591
1641
( 10 , latest_channel_monitor_archival_height, option) ,
1642
+ ( 12 , latest_scores_sync_timestamp, option) ,
1592
1643
} ) ;
1593
1644
1594
1645
pub ( crate ) fn total_anchor_channels_reserve_sats (
0 commit comments