@@ -59,7 +59,7 @@ use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
59
59
use crate :: util:: logger:: Logger ;
60
60
use crate :: prelude:: * ;
61
61
use crate :: prelude:: hash_map:: Entry ;
62
- use core:: { cmp, fmt} ;
62
+ use core:: { cmp, fmt, mem } ;
63
63
use core:: ops:: { Deref , DerefMut } ;
64
64
use core:: time:: Duration ;
65
65
use crate :: io:: { self , Read } ;
@@ -1143,6 +1143,11 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ProbabilisticScorer<G, L> whe
1143
1143
}
1144
1144
None
1145
1145
}
1146
+
1147
+ /// Overwrite the scorer state with the given external scores.
1148
+ pub fn set ( & mut self , external_scores : ChannelLiquidities ) {
1149
+ _ = mem:: replace ( & mut self . channel_liquidities , external_scores) ;
1150
+ }
1146
1151
}
1147
1152
1148
1153
impl ChannelLiquidity {
@@ -1746,6 +1751,11 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref + Clone> CombinedScore
1746
1751
self . scorer . channel_liquidities . insert ( scid, liquidity) ;
1747
1752
}
1748
1753
}
1754
+
1755
+ /// Overwrite the scorer state with the given external scores.
1756
+ pub fn set ( & mut self , external_scores : ChannelLiquidities ) {
1757
+ self . scorer . set ( external_scores) ;
1758
+ }
1749
1759
}
1750
1760
1751
1761
impl < G : Deref < Target = NetworkGraph < L > > , L : Deref > ScoreLookUp for CombinedScorer < G , L > where L :: Target : Logger {
@@ -3962,6 +3972,19 @@ mod tests {
3962
3972
} ,
3963
3973
} ;
3964
3974
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
+
3965
3988
{
3966
3989
let network_graph = network_graph. read_only ( ) ;
3967
3990
let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
@@ -3971,16 +3994,7 @@ mod tests {
3971
3994
3972
3995
let penalty = combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
3973
3996
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 ) ;
3984
3998
3985
3999
let penalty_after_merge =
3986
4000
combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
@@ -3993,6 +4007,13 @@ mod tests {
3993
4007
let liquidity_range =
3994
4008
combined_scorer. scorer . estimated_channel_liquidity_range ( 42 , & target_node_id ( ) ) ;
3995
4009
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 ( 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 ) ) ;
3996
4017
}
3997
4018
}
3998
4019
0 commit comments