@@ -3388,6 +3388,7 @@ mod tests {
3388
3388
assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , u64 :: max_value( ) ) ;
3389
3389
}
3390
3390
3391
+ #[ test]
3391
3392
fn remembers_historical_failures ( ) {
3392
3393
let logger = TestLogger :: new ( ) ;
3393
3394
let network_graph = network_graph ( & logger) ;
@@ -3402,6 +3403,7 @@ mod tests {
3402
3403
} ;
3403
3404
let mut scorer = ProbabilisticScorer :: new ( decay_params, & network_graph, & logger) ;
3404
3405
let source = source_node_id ( ) ;
3406
+ let target = target_node_id ( ) ;
3405
3407
3406
3408
let usage = ChannelUsage {
3407
3409
amount_msat : 100 ,
@@ -3413,24 +3415,37 @@ mod tests {
3413
3415
inflight_htlc_msat : 0 ,
3414
3416
effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : 1_024 } ,
3415
3417
} ;
3416
- let network_graph = network_graph. read_only ( ) ;
3417
- let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3418
- let ( info, target) = channel. as_directed_from ( & source) . unwrap ( ) ;
3419
- let candidate = CandidateRouteHop :: PublicHop {
3420
- info,
3421
- short_channel_id : 42 ,
3422
- } ;
3423
3418
3424
- // With no historical data the normal liquidity penalty calculation is used.
3425
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 168 ) ;
3419
+ {
3420
+ let network_graph = network_graph. read_only ( ) ;
3421
+ let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3422
+ let ( info, _) = channel. as_directed_from ( & source) . unwrap ( ) ;
3423
+ let candidate = CandidateRouteHop :: PublicHop {
3424
+ info,
3425
+ short_channel_id : 42 ,
3426
+ } ;
3427
+
3428
+ // With no historical data the normal liquidity penalty calculation is used.
3429
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 168 ) ;
3430
+ }
3426
3431
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3427
3432
None ) ;
3428
3433
assert_eq ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, 42 , & params) ,
3429
3434
None ) ;
3430
3435
3431
3436
scorer. payment_path_failed ( & payment_path_for_amount ( 1 ) , 42 ) ;
3432
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2048 ) ;
3433
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage_1, & params) , 249 ) ;
3437
+ {
3438
+ let network_graph = network_graph. read_only ( ) ;
3439
+ let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3440
+ let ( info, _) = channel. as_directed_from ( & source) . unwrap ( ) ;
3441
+ let candidate = CandidateRouteHop :: PublicHop {
3442
+ info,
3443
+ short_channel_id : 42 ,
3444
+ } ;
3445
+
3446
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2048 ) ;
3447
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage_1, & params) , 249 ) ;
3448
+ }
3434
3449
// The "it failed" increment is 32, where the probability should lie several buckets into
3435
3450
// the first octile.
3436
3451
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
@@ -3444,7 +3459,17 @@ mod tests {
3444
3459
// Even after we tell the scorer we definitely have enough available liquidity, it will
3445
3460
// still remember that there was some failure in the past, and assign a non-0 penalty.
3446
3461
scorer. payment_path_failed ( & payment_path_for_amount ( 1000 ) , 43 ) ;
3447
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 105 ) ;
3462
+ {
3463
+ let network_graph = network_graph. read_only ( ) ;
3464
+ let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3465
+ let ( info, _) = channel. as_directed_from ( & source) . unwrap ( ) ;
3466
+ let candidate = CandidateRouteHop :: PublicHop {
3467
+ info,
3468
+ short_channel_id : 42 ,
3469
+ } ;
3470
+
3471
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 105 ) ;
3472
+ }
3448
3473
// The first points should be decayed just slightly and the last bucket has a new point.
3449
3474
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3450
3475
Some ( ( [ 31 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32 , 0 , 0 , 0 , 0 , 0 ] ,
@@ -3464,7 +3489,17 @@ mod tests {
3464
3489
// Advance the time forward 16 half-lives (which the docs claim will ensure all data is
3465
3490
// gone), and check that we're back to where we started.
3466
3491
SinceEpoch :: advance ( Duration :: from_secs ( 10 * 16 ) ) ;
3467
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 168 ) ;
3492
+ {
3493
+ let network_graph = network_graph. read_only ( ) ;
3494
+ let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3495
+ let ( info, _) = channel. as_directed_from ( & source) . unwrap ( ) ;
3496
+ let candidate = CandidateRouteHop :: PublicHop {
3497
+ info,
3498
+ short_channel_id : 42 ,
3499
+ } ;
3500
+
3501
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 168 ) ;
3502
+ }
3468
3503
// Once fully decayed we still have data, but its all-0s. In the future we may remove the
3469
3504
// data entirely instead.
3470
3505
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
@@ -3477,16 +3512,26 @@ mod tests {
3477
3512
effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : 1_024 } ,
3478
3513
} ;
3479
3514
scorer. payment_path_failed ( & payment_path_for_amount ( 1 ) , 42 ) ;
3480
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2050 ) ;
3481
- usage. inflight_htlc_msat = 0 ;
3482
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 866 ) ;
3515
+ {
3516
+ let network_graph = network_graph. read_only ( ) ;
3517
+ let channel = network_graph. channel ( 42 ) . unwrap ( ) ;
3518
+ let ( info, _) = channel. as_directed_from ( & source) . unwrap ( ) ;
3519
+ let candidate = CandidateRouteHop :: PublicHop {
3520
+ info,
3521
+ short_channel_id : 42 ,
3522
+ } ;
3483
3523
3484
- let usage = ChannelUsage {
3485
- amount_msat : 1 ,
3486
- inflight_htlc_msat : 0 ,
3487
- effective_capacity : EffectiveCapacity :: AdvertisedMaxHTLC { amount_msat : 0 } ,
3488
- } ;
3489
- assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2048 ) ;
3524
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2050 ) ;
3525
+ usage. inflight_htlc_msat = 0 ;
3526
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 866 ) ;
3527
+
3528
+ let usage = ChannelUsage {
3529
+ amount_msat : 1 ,
3530
+ inflight_htlc_msat : 0 ,
3531
+ effective_capacity : EffectiveCapacity :: AdvertisedMaxHTLC { amount_msat : 0 } ,
3532
+ } ;
3533
+ assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 2048 ) ;
3534
+ }
3490
3535
3491
3536
// Advance to decay all liquidity offsets to zero.
3492
3537
SinceEpoch :: advance ( Duration :: from_secs ( 60 * 60 * 10 ) ) ;
0 commit comments