@@ -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,8 +123,9 @@ 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- PEER_RECONNECTION_INTERVAL , RGS_SYNC_INTERVAL ,
126+ default_user_config, may_announce_channel, ChannelConfig , Config ,
127+ EXTERNAL_PATHFINDING_SCORES_SYNC_INTERVAL , EXTERNAL_PATHFINDING_SCORES_SYNC_TIMEOUT_SECS ,
128+ NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL , RGS_SYNC_INTERVAL ,
127129} ;
128130use connection:: ConnectionManager ;
129131use event:: { EventHandler , EventQueue } ;
@@ -137,6 +139,7 @@ use payment::{
137139 UnifiedQrPayment ,
138140} ;
139141use peer_store:: { PeerInfo , PeerStore } ;
142+ use scoring:: setup_background_pathfinding_scores_sync;
140143use types:: {
141144 Broadcaster , BumpTransactionEventHandler , ChainMonitor , ChannelManager , DynStore , Graph ,
142145 KeysManager , OnionMessenger , PeerManager , Router , Scorer , Sweeper , Wallet ,
@@ -169,6 +172,11 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
169172#[ cfg( feature = "uniffi" ) ]
170173uniffi:: include_scaffolding!( "ldk_node" ) ;
171174
175+ #[ derive( Debug , Clone ) ]
176+ struct PathfindingScoresSyncConfig {
177+ url : String ,
178+ }
179+
172180/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
173181///
174182/// Needs to be initialized and instantiated through [`Builder::build`].
@@ -190,6 +198,7 @@ pub struct Node {
190198 keys_manager : Arc < KeysManager > ,
191199 network_graph : Arc < Graph > ,
192200 gossip_source : Arc < GossipSource > ,
201+ pathfinding_scores_sync_config : Option < PathfindingScoresSyncConfig > ,
193202 liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
194203 kv_store : Arc < DynStore > ,
195204 logger : Arc < Logger > ,
@@ -304,6 +313,18 @@ impl Node {
304313 } ) ;
305314 }
306315
316+ if let Some ( pathfinding_scores_sync_config) = self . pathfinding_scores_sync_config . as_ref ( ) {
317+ setup_background_pathfinding_scores_sync (
318+ pathfinding_scores_sync_config. url . clone ( ) ,
319+ self . scorer . clone ( ) ,
320+ self . node_metrics . clone ( ) ,
321+ self . kv_store . clone ( ) ,
322+ self . logger . clone ( ) ,
323+ & runtime,
324+ & self . stop_sender ,
325+ ) ;
326+ }
327+
307328 if let Some ( listening_addresses) = & self . config . listening_addresses {
308329 // Setup networking
309330 let peer_manager_connection_handler = Arc :: clone ( & self . peer_manager ) ;
@@ -725,6 +746,8 @@ impl Node {
725746 locked_node_metrics. latest_fee_rate_cache_update_timestamp ;
726747 let latest_rgs_snapshot_timestamp =
727748 locked_node_metrics. latest_rgs_snapshot_timestamp . map ( |val| val as u64 ) ;
749+ let latest_pathfinding_scores_sync_timestamp =
750+ locked_node_metrics. latest_pathfinding_scores_sync_timestamp ;
728751 let latest_node_announcement_broadcast_timestamp =
729752 locked_node_metrics. latest_node_announcement_broadcast_timestamp ;
730753 let latest_channel_monitor_archival_height =
@@ -738,6 +761,7 @@ impl Node {
738761 latest_onchain_wallet_sync_timestamp,
739762 latest_fee_rate_cache_update_timestamp,
740763 latest_rgs_snapshot_timestamp,
764+ latest_pathfinding_scores_sync_timestamp,
741765 latest_node_announcement_broadcast_timestamp,
742766 latest_channel_monitor_archival_height,
743767 }
@@ -1547,6 +1571,8 @@ pub struct NodeStatus {
15471571 ///
15481572 /// Will be `None` if RGS isn't configured or the snapshot hasn't been updated yet.
15491573 pub latest_rgs_snapshot_timestamp : Option < u64 > ,
1574+ /// The timestamp, in seconds since start of the UNIX epoch, when we last successfully merged external scores.
1575+ pub latest_pathfinding_scores_sync_timestamp : Option < u64 > ,
15501576 /// The timestamp, in seconds since start of the UNIX epoch, when we last broadcasted a node
15511577 /// announcement.
15521578 ///
@@ -1565,6 +1591,7 @@ pub(crate) struct NodeMetrics {
15651591 latest_onchain_wallet_sync_timestamp : Option < u64 > ,
15661592 latest_fee_rate_cache_update_timestamp : Option < u64 > ,
15671593 latest_rgs_snapshot_timestamp : Option < u32 > ,
1594+ latest_pathfinding_scores_sync_timestamp : Option < u64 > ,
15681595 latest_node_announcement_broadcast_timestamp : Option < u64 > ,
15691596 latest_channel_monitor_archival_height : Option < u32 > ,
15701597}
@@ -1576,6 +1603,7 @@ impl Default for NodeMetrics {
15761603 latest_onchain_wallet_sync_timestamp : None ,
15771604 latest_fee_rate_cache_update_timestamp : None ,
15781605 latest_rgs_snapshot_timestamp : None ,
1606+ latest_pathfinding_scores_sync_timestamp : None ,
15791607 latest_node_announcement_broadcast_timestamp : None ,
15801608 latest_channel_monitor_archival_height : None ,
15811609 }
@@ -1584,6 +1612,7 @@ impl Default for NodeMetrics {
15841612
15851613impl_writeable_tlv_based ! ( NodeMetrics , {
15861614 ( 0 , latest_lightning_wallet_sync_timestamp, option) ,
1615+ ( 1 , latest_pathfinding_scores_sync_timestamp, option) ,
15871616 ( 2 , latest_onchain_wallet_sync_timestamp, option) ,
15881617 ( 4 , latest_fee_rate_cache_update_timestamp, option) ,
15891618 ( 6 , latest_rgs_snapshot_timestamp, option) ,
0 commit comments