@@ -59,7 +59,7 @@ use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
5959use crate :: util:: logger:: Logger ;
6060use crate :: prelude:: * ;
6161use crate :: prelude:: hash_map:: Entry ;
62- use core:: { cmp, fmt} ;
62+ use core:: { cmp, fmt, mem } ;
6363use core:: ops:: { Deref , DerefMut } ;
6464use core:: time:: Duration ;
6565use crate :: io:: { self , Read } ;
@@ -1143,6 +1143,11 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
11431143 }
11441144 None
11451145 }
1146+
1147+ /// Overwrite the scorer state with the given external scores.
1148+ pub fn set_scores ( & mut self , external_scores : ChannelLiquidities ) {
1149+ _ = mem:: replace ( & mut self . channel_liquidities , external_scores) ;
1150+ }
11461151}
11471152
11481153impl ChannelLiquidity {
@@ -1746,6 +1751,11 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref + Clone> CombinedScore
17461751 self . scorer . channel_liquidities . insert ( scid, liquidity) ;
17471752 }
17481753 }
1754+
1755+ /// Overwrite the scorer state with the given external scores.
1756+ pub fn set_scores ( & mut self , external_scores : ChannelLiquidities ) {
1757+ self . scorer . set_scores ( external_scores) ;
1758+ }
17491759}
17501760
17511761impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ScoreLookUp for CombinedScorer < G , L > where L :: Target : Logger {
@@ -3962,6 +3972,19 @@ mod tests {
39623972 } ,
39633973 } ;
39643974
3975+ let logger_rc = Rc :: new ( & logger) ;
3976+
3977+ let mut external_liquidity = ChannelLiquidity :: new ( Duration :: ZERO ) ;
3978+ external_liquidity. as_directed_mut ( & source_node_id ( ) , & target_node_id ( ) , 1_000 ) . successful (
3979+ 1000 ,
3980+ Duration :: ZERO ,
3981+ format_args ! ( "test channel" ) ,
3982+ logger_rc. as_ref ( ) ,
3983+ ) ;
3984+
3985+ let mut external_scores = ChannelLiquidities :: new ( ) ;
3986+ external_scores. insert ( 42 , external_liquidity) ;
3987+
39653988 {
39663989 let network_graph = network_graph. read_only ( ) ;
39673990 let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
@@ -3971,16 +3994,7 @@ mod tests {
39713994
39723995 let penalty = combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
39733996
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 ) ;
3997+ combined_scorer. merge ( external_scores. clone ( ) , Duration :: ZERO ) ;
39843998
39853999 let penalty_after_merge =
39864000 combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
@@ -3993,6 +4007,13 @@ mod tests {
39934007 let liquidity_range =
39944008 combined_scorer. scorer . estimated_channel_liquidity_range ( 42 , & target_node_id ( ) ) ;
39954009 assert_eq ! ( liquidity_range. unwrap( ) , ( 0 , 300 ) ) ;
4010+
4011+ // Now set (overwrite) the scorer state with the external data which should lead to an even greater liquidity
4012+ // range. Just the success from the external source is now considered.
4013+ combined_scorer. set_scores ( external_scores) ;
4014+ let liquidity_range =
4015+ combined_scorer. scorer . estimated_channel_liquidity_range ( 42 , & target_node_id ( ) ) ;
4016+ assert_eq ! ( liquidity_range. unwrap( ) , ( 0 , 0 ) ) ;
39964017 }
39974018}
39984019
0 commit comments