@@ -2126,4 +2126,49 @@ mod tests {
2126
2126
let usage = ChannelUsage { amount_msat : 1_001 , ..usage } ;
2127
2127
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value( ) ) ;
2128
2128
}
2129
+
2130
+ #[ test]
2131
+ fn adds_anti_probing_penalty ( ) {
2132
+ let logger = TestLogger :: new ( ) ;
2133
+ let network_graph = network_graph ( & logger) ;
2134
+ let source = source_node_id ( ) ;
2135
+ let target = target_node_id ( ) ;
2136
+ let params = ProbabilisticScoringParameters {
2137
+ anti_probing_penalty_msat : 10_000 ,
2138
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2139
+ } ;
2140
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2141
+
2142
+ // Check we receive no penalty for a low htlc_maximum_msat.
2143
+ let usage = ChannelUsage {
2144
+ amount_msat : 512_000 ,
2145
+ inflight_htlc_msat : 0 ,
2146
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024_000 , htlc_maximum_msat : Some ( 1_000 ) } ,
2147
+ } ;
2148
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
2149
+
2150
+ // Check we receive anti-probing penalty for htlc_maximum_msat == channel_capacity.
2151
+ let usage = ChannelUsage {
2152
+ amount_msat : 512_000 ,
2153
+ inflight_htlc_msat : 0 ,
2154
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024_000 , htlc_maximum_msat : Some ( 1_024_000 ) } ,
2155
+ } ;
2156
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 10_000 ) ;
2157
+
2158
+ // Check we receive anti-probing penalty for htlc_maximum_msat == channel_capacity/2.
2159
+ let usage = ChannelUsage {
2160
+ amount_msat : 512_000 ,
2161
+ inflight_htlc_msat : 0 ,
2162
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024_000 , htlc_maximum_msat : Some ( 512_000 ) } ,
2163
+ } ;
2164
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 10_000 ) ;
2165
+
2166
+ // Check we receive no anti-probing penalty for htlc_maximum_msat == channel_capacity/2 - 1.
2167
+ let usage = ChannelUsage {
2168
+ amount_msat : 512_000 ,
2169
+ inflight_htlc_msat : 0 ,
2170
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024_000 , htlc_maximum_msat : Some ( 511_999 ) } ,
2171
+ } ;
2172
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
2173
+ }
2129
2174
}
0 commit comments