@@ -1702,17 +1702,18 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
17021702#[ cfg( test) ]
17031703mod tests {
17041704 use super :: { ChannelLiquidity , HistoricalBucketRangeTracker , ProbabilisticScoringParameters , ProbabilisticScorerUsingTime } ;
1705+ use crate :: blinded_path:: { BlindedHop , BlindedPath } ;
17051706 use crate :: util:: config:: UserConfig ;
17061707 use crate :: util:: time:: Time ;
17071708 use crate :: util:: time:: tests:: SinceEpoch ;
17081709
17091710 use crate :: ln:: channelmanager;
17101711 use crate :: ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , UnsignedChannelAnnouncement , UnsignedChannelUpdate } ;
17111712 use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId } ;
1712- use crate :: routing:: router:: { Path , RouteHop } ;
1713+ use crate :: routing:: router:: { BlindedTail , Path , RouteHop } ;
17131714 use crate :: routing:: scoring:: { ChannelUsage , Score } ;
17141715 use crate :: util:: ser:: { ReadableArgs , Writeable } ;
1715- use crate :: util:: test_utils:: TestLogger ;
1716+ use crate :: util:: test_utils:: { self , TestLogger } ;
17161717
17171718 use bitcoin:: blockdata:: constants:: genesis_block;
17181719 use bitcoin:: hashes:: Hash ;
@@ -2870,4 +2871,54 @@ mod tests {
28702871 } ;
28712872 assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
28722873 }
2874+
2875+ #[ test]
2876+ fn scores_with_blinded_path ( ) {
2877+ // Make sure we'll account for a blinded path's final_value_msat in scoring
2878+ let logger = TestLogger :: new ( ) ;
2879+ let network_graph = network_graph ( & logger) ;
2880+ let params = ProbabilisticScoringParameters {
2881+ liquidity_penalty_multiplier_msat : 1_000 ,
2882+ liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2883+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2884+ } ;
2885+ let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2886+ let source = source_node_id ( ) ;
2887+ let target = target_node_id ( ) ;
2888+ let usage = ChannelUsage {
2889+ amount_msat : 512 ,
2890+ inflight_htlc_msat : 0 ,
2891+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : 1_000 } ,
2892+ } ;
2893+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 300 ) ;
2894+
2895+ let mut path = payment_path_for_amount ( 768 ) ;
2896+ let recipient_hop = path. hops . pop ( ) . unwrap ( ) ;
2897+ let blinded_path = BlindedPath {
2898+ introduction_node_id : path. hops . last ( ) . as_ref ( ) . unwrap ( ) . pubkey ,
2899+ blinding_point : test_utils:: pubkey ( 42 ) ,
2900+ blinded_hops : vec ! [
2901+ BlindedHop { blinded_node_id: test_utils:: pubkey( 44 ) , encrypted_payload: Vec :: new( ) }
2902+ ] ,
2903+ } ;
2904+ path. blinded_tail = Some ( BlindedTail {
2905+ hops : blinded_path. blinded_hops ,
2906+ blinding_point : blinded_path. blinding_point ,
2907+ excess_final_cltv_expiry_delta : recipient_hop. cltv_expiry_delta ,
2908+ final_value_msat : recipient_hop. fee_msat ,
2909+ } ) ;
2910+
2911+ // Check the liquidity before and after scoring payment failures to ensure the blinded path's
2912+ // final value is taken into account.
2913+ assert ! ( scorer. channel_liquidities. get( & 42 ) . is_none( ) ) ;
2914+
2915+ scorer. payment_path_failed ( & path, 42 ) ;
2916+ path. blinded_tail . as_mut ( ) . unwrap ( ) . final_value_msat = 256 ;
2917+ scorer. payment_path_failed ( & path, 43 ) ;
2918+
2919+ let liquidity = scorer. channel_liquidities . get ( & 42 ) . unwrap ( )
2920+ . as_directed ( & source, & target, 0 , 1_000 , & scorer. params ) ;
2921+ assert_eq ! ( liquidity. min_liquidity_msat( ) , 256 ) ;
2922+ assert_eq ! ( liquidity. max_liquidity_msat( ) , 768 ) ;
2923+ }
28732924}
0 commit comments