Skip to content

Commit edab3d6

Browse files
committed
Allow overshooting final cltv_expiry
Final nodes previously had stricter requirements on HTLC contents matching onion value compared to intermediate nodes. This allowed for probing, i.e. the last intermediate node could overshoot the value by a small amount and conclude from the acceptance or rejection of the HTLC whether the next node was the destination. This also applies to the msat amount, however this change was already present.
1 parent ef6e9b6 commit edab3d6

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,9 +2022,9 @@ where
20222022
payment_hash: PaymentHash, amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>) -> Result<PendingHTLCInfo, ReceiveError>
20232023
{
20242024
// final_incorrect_cltv_expiry
2025-
if hop_data.outgoing_cltv_value != cltv_expiry {
2025+
if hop_data.outgoing_cltv_value > cltv_expiry {
20262026
return Err(ReceiveError {
2027-
msg: "Upstream node set CLTV to the wrong value",
2027+
msg: "Upstream node set CLTV to less than outgoing CLTV",
20282028
err_code: 18,
20292029
err_data: cltv_expiry.to_be_bytes().to_vec()
20302030
})

lightning/src/ln/onion_route_tests.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn test_onion_failure() {
552552
for f in pending_forwards.iter_mut() {
553553
match f {
554554
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) =>
555-
forward_info.outgoing_cltv_value += 1,
555+
forward_info.outgoing_cltv_value -= 1,
556556
_ => {},
557557
}
558558
}
@@ -602,6 +602,31 @@ fn test_onion_failure() {
602602
}, true, Some(23), None, None);
603603
}
604604

605+
#[test]
606+
#[should_panic]
607+
fn test_overshoot_final_cltv() {
608+
// Test that we can overshoot the final cltv_expiry set by the sender
609+
// by making sure expecting it to fail panics
610+
let chanmon_cfgs = create_chanmon_cfgs(3);
611+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
612+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None; 3]);
613+
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
614+
let channels = [create_announced_chan_between_nodes(&nodes, 0, 1), create_announced_chan_between_nodes(&nodes, 1, 2)];
615+
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 40000);
616+
send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 40000);
617+
run_onion_failure_test("final_incorrect_cltv_expiry", 1, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || {
618+
for (_, pending_forwards) in nodes[1].node.forward_htlcs.lock().unwrap().iter_mut() {
619+
for f in pending_forwards.iter_mut() {
620+
match f {
621+
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) =>
622+
forward_info.outgoing_cltv_value += 1,
623+
_ => {},
624+
}
625+
}
626+
}
627+
}, true, Some(18), None, Some(channels[1].0.contents.short_channel_id));
628+
}
629+
605630
fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
606631
// Create a network of three nodes and two channels connecting them. We'll be updating the
607632
// HTLC relay policy of the second channel, causing forwarding failures at the first hop.
@@ -1096,7 +1121,7 @@ fn test_phantom_final_incorrect_cltv_expiry() {
10961121
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
10971122
forward_info: PendingHTLCInfo { ref mut outgoing_cltv_value, .. }, ..
10981123
}) => {
1099-
*outgoing_cltv_value += 1;
1124+
*outgoing_cltv_value -= 1;
11001125
},
11011126
_ => panic!("Unexpected forward"),
11021127
}
@@ -1114,7 +1139,7 @@ fn test_phantom_final_incorrect_cltv_expiry() {
11141139
commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false);
11151140

11161141
// Ensure the payment fails with the expected error.
1117-
let expected_cltv: u32 = 82;
1142+
let expected_cltv: u32 = 80;
11181143
let error_data = expected_cltv.to_be_bytes().to_vec();
11191144
let mut fail_conditions = PaymentFailedConditions::new()
11201145
.blamed_scid(phantom_scid)

0 commit comments

Comments
 (0)