@@ -1702,17 +1702,18 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
1702
1702
#[ cfg( test) ]
1703
1703
mod tests {
1704
1704
use super :: { ChannelLiquidity , HistoricalBucketRangeTracker , ProbabilisticScoringParameters , ProbabilisticScorerUsingTime } ;
1705
+ use crate :: blinded_path:: { BlindedHop , BlindedPath } ;
1705
1706
use crate :: util:: config:: UserConfig ;
1706
1707
use crate :: util:: time:: Time ;
1707
1708
use crate :: util:: time:: tests:: SinceEpoch ;
1708
1709
1709
1710
use crate :: ln:: channelmanager;
1710
1711
use crate :: ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , UnsignedChannelAnnouncement , UnsignedChannelUpdate } ;
1711
1712
use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId } ;
1712
- use crate :: routing:: router:: { Path , RouteHop } ;
1713
+ use crate :: routing:: router:: { BlindedTail , Path , RouteHop } ;
1713
1714
use crate :: routing:: scoring:: { ChannelUsage , Score } ;
1714
1715
use crate :: util:: ser:: { ReadableArgs , Writeable } ;
1715
- use crate :: util:: test_utils:: TestLogger ;
1716
+ use crate :: util:: test_utils:: { self , TestLogger } ;
1716
1717
1717
1718
use bitcoin:: blockdata:: constants:: genesis_block;
1718
1719
use bitcoin:: hashes:: Hash ;
@@ -2870,4 +2871,48 @@ mod tests {
2870
2871
} ;
2871
2872
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
2872
2873
}
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
+ final_cltv_expiry_delta : recipient_hop. cltv_expiry_delta ,
2908
+ final_value_msat : recipient_hop. fee_msat ,
2909
+ } ) ;
2910
+
2911
+ // More knowledge gives higher confidence (256, 768), meaning a lower penalty.
2912
+ scorer. payment_path_failed ( & path, 42 ) ;
2913
+ path. blinded_tail . as_mut ( ) . unwrap ( ) . final_value_msat = 256 ;
2914
+ scorer. payment_path_failed ( & path, 43 ) ;
2915
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 281 ) ;
2916
+ assert_eq ! ( scorer. channel_penalty_msat( 43 , & source, & target, usage) , 300 ) ;
2917
+ }
2873
2918
}
0 commit comments