@@ -27,7 +27,8 @@ use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
2727use lightning:: routing:: gossip:: NodeAlias ;
2828use lightning:: routing:: router:: DefaultRouter ;
2929use lightning:: routing:: scoring:: {
30- ProbabilisticScorer , ProbabilisticScoringDecayParameters , ProbabilisticScoringFeeParameters ,
30+ CombinedScorer , ProbabilisticScorer , ProbabilisticScoringDecayParameters ,
31+ ProbabilisticScoringFeeParameters ,
3132} ;
3233use lightning:: sign:: { EntropySource , NodeSigner } ;
3334use lightning:: util:: persist:: {
@@ -110,6 +111,11 @@ enum GossipSourceConfig {
110111 RapidGossipSync ( String ) ,
111112}
112113
114+ #[ derive( Debug , Clone ) ]
115+ struct PathfindingScoresSyncConfig {
116+ url : String ,
117+ }
118+
113119#[ derive( Debug , Clone , Default ) ]
114120struct LiquiditySourceConfig {
115121 // Act as an LSPS1 client connecting to the given service.
@@ -243,6 +249,7 @@ pub struct NodeBuilder {
243249 log_writer_config : Option < LogWriterConfig > ,
244250 async_payments_role : Option < AsyncPaymentsRole > ,
245251 runtime_handle : Option < tokio:: runtime:: Handle > ,
252+ pathfinding_scores_sync_config : Option < PathfindingScoresSyncConfig > ,
246253}
247254
248255impl NodeBuilder {
@@ -260,6 +267,7 @@ impl NodeBuilder {
260267 let liquidity_source_config = None ;
261268 let log_writer_config = None ;
262269 let runtime_handle = None ;
270+ let pathfinding_scores_sync_config = None ;
263271 Self {
264272 config,
265273 entropy_source_config,
@@ -269,6 +277,7 @@ impl NodeBuilder {
269277 log_writer_config,
270278 runtime_handle,
271279 async_payments_role : None ,
280+ pathfinding_scores_sync_config,
272281 }
273282 }
274283
@@ -411,6 +420,14 @@ impl NodeBuilder {
411420 self
412421 }
413422
423+ /// Configures the [`Node`] instance to source its external scores from the given URL.
424+ ///
425+ /// The external scores are merged into the local scoring system to improve routing.
426+ pub fn set_pathfinding_scores_source ( & mut self , url : String ) -> & mut Self {
427+ self . pathfinding_scores_sync_config = Some ( PathfindingScoresSyncConfig { url } ) ;
428+ self
429+ }
430+
414431 /// Configures the [`Node`] instance to source inbound liquidity from the given
415432 /// [bLIP-51 / LSPS1] service.
416433 ///
@@ -718,6 +735,7 @@ impl NodeBuilder {
718735 self . chain_data_source_config . as_ref ( ) ,
719736 self . gossip_source_config . as_ref ( ) ,
720737 self . liquidity_source_config . as_ref ( ) ,
738+ self . pathfinding_scores_sync_config . as_ref ( ) ,
721739 self . async_payments_role ,
722740 seed_bytes,
723741 runtime,
@@ -751,6 +769,7 @@ impl NodeBuilder {
751769 self . chain_data_source_config . as_ref ( ) ,
752770 self . gossip_source_config . as_ref ( ) ,
753771 self . liquidity_source_config . as_ref ( ) ,
772+ self . pathfinding_scores_sync_config . as_ref ( ) ,
754773 self . async_payments_role ,
755774 seed_bytes,
756775 runtime,
@@ -910,6 +929,13 @@ impl ArcedNodeBuilder {
910929 self . inner . write ( ) . unwrap ( ) . set_gossip_source_rgs ( rgs_server_url) ;
911930 }
912931
932+ /// Configures the [`Node`] instance to source its external scores from the given URL.
933+ ///
934+ /// The external scores are merged into the local scoring system to improve routing.
935+ pub fn set_pathfinding_scores_source ( & self , url : String ) {
936+ self . inner . write ( ) . unwrap ( ) . set_pathfinding_scores_source ( url) ;
937+ }
938+
913939 /// Configures the [`Node`] instance to source inbound liquidity from the given
914940 /// [bLIP-51 / LSPS1] service.
915941 ///
@@ -1110,6 +1136,7 @@ fn build_with_store_internal(
11101136 config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
11111137 gossip_source_config : Option < & GossipSourceConfig > ,
11121138 liquidity_source_config : Option < & LiquiditySourceConfig > ,
1139+ pathfinding_scores_sync_config : Option < & PathfindingScoresSyncConfig > ,
11131140 async_payments_role : Option < AsyncPaymentsRole > , seed_bytes : [ u8 ; 64 ] , runtime : Arc < Runtime > ,
11141141 logger : Arc < Logger > , kv_store : Arc < DynStore > ,
11151142) -> Result < Node , BuildError > {
@@ -1365,26 +1392,24 @@ fn build_with_store_internal(
13651392 } ,
13661393 } ;
13671394
1368- let scorer = match io:: utils:: read_scorer (
1395+ let local_scorer = match io:: utils:: read_scorer (
13691396 Arc :: clone ( & kv_store) ,
13701397 Arc :: clone ( & network_graph) ,
13711398 Arc :: clone ( & logger) ,
13721399 ) {
1373- Ok ( scorer) => Arc :: new ( Mutex :: new ( scorer) ) ,
1400+ Ok ( scorer) => scorer,
13741401 Err ( e) => {
13751402 if e. kind ( ) == std:: io:: ErrorKind :: NotFound {
13761403 let params = ProbabilisticScoringDecayParameters :: default ( ) ;
1377- Arc :: new ( Mutex :: new ( ProbabilisticScorer :: new (
1378- params,
1379- Arc :: clone ( & network_graph) ,
1380- Arc :: clone ( & logger) ,
1381- ) ) )
1404+ ProbabilisticScorer :: new ( params, Arc :: clone ( & network_graph) , Arc :: clone ( & logger) )
13821405 } else {
13831406 return Err ( BuildError :: ReadFailed ) ;
13841407 }
13851408 } ,
13861409 } ;
13871410
1411+ let scorer = Arc :: new ( Mutex :: new ( CombinedScorer :: new ( local_scorer) ) ) ;
1412+
13881413 let scoring_fee_params = ProbabilisticScoringFeeParameters :: default ( ) ;
13891414 let router = Arc :: new ( DefaultRouter :: new (
13901415 Arc :: clone ( & network_graph) ,
@@ -1716,6 +1741,8 @@ fn build_with_store_internal(
17161741 let ( background_processor_stop_sender, _) = tokio:: sync:: watch:: channel ( ( ) ) ;
17171742 let is_running = Arc :: new ( RwLock :: new ( false ) ) ;
17181743
1744+ let pathfinding_scores_sync_url = pathfinding_scores_sync_config. map ( |c| c. url . clone ( ) ) ;
1745+
17191746 Ok ( Node {
17201747 runtime,
17211748 stop_sender,
@@ -1734,6 +1761,7 @@ fn build_with_store_internal(
17341761 keys_manager,
17351762 network_graph,
17361763 gossip_source,
1764+ pathfinding_scores_sync_url,
17371765 liquidity_source,
17381766 kv_store,
17391767 logger,
0 commit comments