@@ -1746,6 +1746,14 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref + Clone> CombinedScore
17461746 self . scorer . channel_liquidities . insert ( scid, liquidity) ;
17471747 }
17481748 }
1749+
1750+ /// Set scorer state to match the provided external channel liquidity information. The state for channels that are
1751+ /// not present in the external data set will remain unchanged.
1752+ pub fn set ( & mut self , external_scores : ChannelLiquidities ) {
1753+ for ( scid, liquidity) in external_scores. 0 {
1754+ self . scorer . channel_liquidities . insert ( scid, liquidity) ;
1755+ }
1756+ }
17491757}
17501758
17511759impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ScoreLookUp for CombinedScorer < G , L > where L :: Target : Logger {
@@ -3962,6 +3970,19 @@ mod tests {
39623970 } ,
39633971 } ;
39643972
3973+ let logger_rc = Rc :: new ( & logger) ;
3974+
3975+ let mut external_liquidity = ChannelLiquidity :: new ( Duration :: ZERO ) ;
3976+ external_liquidity. as_directed_mut ( & source_node_id ( ) , & target_node_id ( ) , 1_000 ) . successful (
3977+ 1000 ,
3978+ Duration :: ZERO ,
3979+ format_args ! ( "test channel" ) ,
3980+ logger_rc. as_ref ( ) ,
3981+ ) ;
3982+
3983+ let mut external_scores = ChannelLiquidities :: new ( ) ;
3984+ external_scores. insert ( 42 , external_liquidity) ;
3985+
39653986 {
39663987 let network_graph = network_graph. read_only ( ) ;
39673988 let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
@@ -3971,16 +3992,7 @@ mod tests {
39713992
39723993 let penalty = combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
39733994
3974- let mut external_liquidity = ChannelLiquidity :: new ( Duration :: ZERO ) ;
3975- let logger_rc = Rc :: new ( & logger) ; // Why necessary and not above for the network graph?
3976- external_liquidity
3977- . as_directed_mut ( & source_node_id ( ) , & target_node_id ( ) , 1_000 )
3978- . successful ( 1000 , Duration :: ZERO , format_args ! ( "test channel" ) , logger_rc. as_ref ( ) ) ;
3979-
3980- let mut external_scores = ChannelLiquidities :: new ( ) ;
3981-
3982- external_scores. insert ( 42 , external_liquidity) ;
3983- combined_scorer. merge ( external_scores, Duration :: ZERO ) ;
3995+ combined_scorer. merge ( external_scores. clone ( ) , Duration :: ZERO ) ;
39843996
39853997 let penalty_after_merge =
39863998 combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
@@ -3993,6 +4005,13 @@ mod tests {
39934005 let liquidity_range =
39944006 combined_scorer. scorer . estimated_channel_liquidity_range ( 42 , & target_node_id ( ) ) ;
39954007 assert_eq ! ( liquidity_range. unwrap( ) , ( 0 , 300 ) ) ;
4008+
4009+ // Now set (overwrite) the scorer state with the external data which should lead to an even greater liquidity
4010+ // range. Just the success from the external source is now considered.
4011+ combined_scorer. set ( external_scores) ;
4012+ let liquidity_range =
4013+ combined_scorer. scorer . estimated_channel_liquidity_range ( 42 , & target_node_id ( ) ) ;
4014+ assert_eq ! ( liquidity_range. unwrap( ) , ( 0 , 0 ) ) ;
39964015 }
39974016}
39984017
0 commit comments