@@ -1135,6 +1135,8 @@ impl ChannelLiquidity {
11351135 }
11361136
11371137 fn merge ( & mut self , other : & Self ) {
1138+ // Todo: check updated times for equality.
1139+
11381140 // Take average for min/max liquidity offsets.
11391141 self . min_liquidity_offset_msat = ( self . min_liquidity_offset_msat + other. min_liquidity_offset_msat ) / 2 ;
11401142 self . max_liquidity_offset_msat = ( self . max_liquidity_offset_msat + other. max_liquidity_offset_msat ) / 2 ;
@@ -2306,7 +2308,7 @@ mod tests {
23062308 use crate :: ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , UnsignedChannelAnnouncement , UnsignedChannelUpdate } ;
23072309 use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId } ;
23082310 use crate :: routing:: router:: { BlindedTail , Path , RouteHop , CandidateRouteHop , PublicHopCandidate } ;
2309- use crate :: routing:: scoring:: { ChannelUsage , ScoreLookUp , ScoreUpdate } ;
2311+ use crate :: routing:: scoring:: { ChannelLiquidities , ChannelUsage , CombinedScorer , ScoreLookUp , ScoreUpdate } ;
23102312 use crate :: util:: ser:: { ReadableArgs , Writeable } ;
23112313 use crate :: util:: test_utils:: { self , TestLogger } ;
23122314
@@ -2316,6 +2318,7 @@ mod tests {
23162318 use bitcoin:: network:: Network ;
23172319 use bitcoin:: secp256k1:: { PublicKey , Secp256k1 , SecretKey } ;
23182320 use core:: time:: Duration ;
2321+ use std:: rc:: Rc ;
23192322 use crate :: io;
23202323
23212324 fn source_privkey ( ) -> SecretKey {
@@ -3814,12 +3817,11 @@ mod tests {
38143817 let network_graph = network_graph ( & logger) ;
38153818 let params = ProbabilisticScoringFeeParameters :: default ( ) ;
38163819 let mut scorer = ProbabilisticScorer :: new ( ProbabilisticScoringDecayParameters :: default ( ) , & network_graph, & logger) ;
3820+ scorer. payment_path_failed ( & payment_path_for_amount ( 600 ) , 42 , Duration :: ZERO ) ;
38173821
3818- scorer . payment_path_failed ( & payment_path_for_amount ( 500 ) , 42 , Duration :: ZERO ) ;
3822+ let mut combined_scorer = CombinedScorer :: new ( scorer ) ;
38193823
38203824 let source = source_node_id ( ) ;
3821-
3822- let base_penalty_msat = params. base_penalty_msat ;
38233825 let usage = ChannelUsage {
38243826 amount_msat : 750 ,
38253827 inflight_htlc_msat : 0 ,
@@ -3832,11 +3834,22 @@ mod tests {
38323834 info,
38333835 short_channel_id : 42 ,
38343836 } ) ;
3835- let penalty = scorer . channel_penalty_msat ( & candidate, usage, & params) ;
3837+ let penalty = combined_scorer . channel_penalty_msat ( & candidate, usage, & params) ;
38363838 assert_eq ! ( penalty, 100000021275 ) ;
38373839
3838- }
3840+ let mut external_liquidity = ChannelLiquidity :: new ( Duration :: ZERO ) ;
3841+ let logger_rc = Rc :: new ( & logger) ; // Why necessary and not above for the network graph?
3842+ external_liquidity. as_directed_mut ( & source_node_id ( ) , & target_node_id ( ) , 1_000 ) .
3843+ successful ( 1000 , Duration :: ZERO , format_args ! ( "test channel" ) , logger_rc. as_ref ( ) ) ;
38393844
3845+ let mut external_scores = ChannelLiquidities :: new ( ) ;
3846+
3847+ external_scores. insert ( 42 , external_liquidity) ;
3848+ combined_scorer. merge ( external_scores) ;
3849+
3850+ let penalty = combined_scorer. channel_penalty_msat ( & candidate, usage, & params) ;
3851+ assert_eq ! ( penalty, 100000021275 ) ;
3852+ }
38403853}
38413854
38423855#[ cfg( ldk_bench) ]
0 commit comments