Skip to content

Commit 2caccc5

Browse files
committed
Fix and re-enable the remembers_historical_failures test
f0ecc3e introduced a regression in the `remembers_historical_failures` test, and disabled it by simply removing the `#[test]` annotation. This fixes the test and marks it as a test again.
1 parent 98ed285 commit 2caccc5

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

lightning/src/routing/scoring.rs

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,7 @@ mod tests {
33883388
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), u64::max_value());
33893389
}
33903390

3391+
#[test]
33913392
fn remembers_historical_failures() {
33923393
let logger = TestLogger::new();
33933394
let network_graph = network_graph(&logger);
@@ -3402,6 +3403,7 @@ mod tests {
34023403
};
34033404
let mut scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger);
34043405
let source = source_node_id();
3406+
let target = target_node_id();
34053407

34063408
let usage = ChannelUsage {
34073409
amount_msat: 100,
@@ -3413,24 +3415,37 @@ mod tests {
34133415
inflight_htlc_msat: 0,
34143416
effective_capacity: EffectiveCapacity::Total { capacity_msat: 1_024, htlc_maximum_msat: 1_024 },
34153417
};
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-
};
34233418

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+
}
34263431
assert_eq!(scorer.historical_estimated_channel_liquidity_probabilities(42, &target),
34273432
None);
34283433
assert_eq!(scorer.historical_estimated_payment_success_probability(42, &target, 42, &params),
34293434
None);
34303435

34313436
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+
}
34343449
// The "it failed" increment is 32, where the probability should lie several buckets into
34353450
// the first octile.
34363451
assert_eq!(scorer.historical_estimated_channel_liquidity_probabilities(42, &target),
@@ -3444,7 +3459,17 @@ mod tests {
34443459
// Even after we tell the scorer we definitely have enough available liquidity, it will
34453460
// still remember that there was some failure in the past, and assign a non-0 penalty.
34463461
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+
}
34483473
// The first points should be decayed just slightly and the last bucket has a new point.
34493474
assert_eq!(scorer.historical_estimated_channel_liquidity_probabilities(42, &target),
34503475
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 {
34643489
// Advance the time forward 16 half-lives (which the docs claim will ensure all data is
34653490
// gone), and check that we're back to where we started.
34663491
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+
}
34683503
// Once fully decayed we still have data, but its all-0s. In the future we may remove the
34693504
// data entirely instead.
34703505
assert_eq!(scorer.historical_estimated_channel_liquidity_probabilities(42, &target),
@@ -3477,16 +3512,26 @@ mod tests {
34773512
effective_capacity: EffectiveCapacity::Total { capacity_msat: 1_024, htlc_maximum_msat: 1_024 },
34783513
};
34793514
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+
};
34833523

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+
}
34903535

34913536
// Advance to decay all liquidity offsets to zero.
34923537
SinceEpoch::advance(Duration::from_secs(60 * 60 * 10));

0 commit comments

Comments
 (0)