Skip to content

Commit 0c93422

Browse files
author
Elias Rohrer
committed
Added test for CLTV delta limit.
1 parent 54a98ee commit 0c93422

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,6 +4821,31 @@ mod tests {
48214821
assert_eq!(route.get_total_amount(), 0);
48224822
}
48234823

4824+
#[test]
4825+
fn limits_total_cltv_delta() {
4826+
let (secp_ctx, network_graph, _, _, logger) = build_graph();
4827+
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
4828+
let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes));
4829+
4830+
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
4831+
4832+
// Make sure that generally there is at least one route available
4833+
let feasible_max_total_cltv_delta = 1000;
4834+
let route = get_route(&our_id, &payee, &network_graph, None, 100, 42, feasible_max_total_cltv_delta, Arc::clone(&logger), &scorer).unwrap();
4835+
let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::<Vec<_>>();
4836+
assert_ne!(path.len(), 0);
4837+
4838+
// But not if we exclude all paths on the basis of their accumulated CLTV delta
4839+
let fail_max_total_cltv_delta = 0;
4840+
match get_route(&our_id, &payee, &network_graph, None, 100, 42, fail_max_total_cltv_delta, Arc::clone(&logger), &scorer)
4841+
{
4842+
Err(LightningError { err, .. } ) => {
4843+
assert_eq!(err, "Failed to find a path to the given destination");
4844+
},
4845+
Ok(_) => panic!("Expected error"),
4846+
}
4847+
}
4848+
48244849
#[cfg(not(feature = "no-std"))]
48254850
pub(super) fn random_init_seed() -> u64 {
48264851
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.

0 commit comments

Comments
 (0)