Skip to content

Commit 8f54dc3

Browse files
Account for Path::blinded_tail when adding a shadow cltv offset
1 parent 68980c0 commit 8f54dc3

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

lightning/src/routing/router.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,10 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
21792179
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset, max_path_offset);
21802180

21812181
// Add 'shadow' CLTV offset to the final hop
2182-
if let Some(last_hop) = path.hops.last_mut() {
2182+
if let Some(tail) = path.blinded_tail.as_mut() {
2183+
tail.final_cltv_expiry_delta = tail.final_cltv_expiry_delta
2184+
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(tail.final_cltv_expiry_delta);
2185+
} else if let Some(last_hop) = path.hops.last_mut() {
21832186
last_hop.cltv_expiry_delta = last_hop.cltv_expiry_delta
21842187
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(last_hop.cltv_expiry_delta);
21852188
}
@@ -5871,6 +5874,49 @@ mod tests {
58715874
assert_eq!(*inflight_htlcs.0.get(&(42, true)).unwrap(), 301);
58725875
assert_eq!(*inflight_htlcs.0.get(&(43, false)).unwrap(), 201);
58735876
}
5877+
5878+
#[test]
5879+
fn blinded_path_cltv_shadow_offset() {
5880+
// Make sure we add a shadow offset when sending to blinded paths.
5881+
let blinded_path = BlindedPath {
5882+
introduction_node_id: ln_test_utils::pubkey(43),
5883+
blinding_point: ln_test_utils::pubkey(44),
5884+
blinded_hops: vec![
5885+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() },
5886+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(46), encrypted_payload: Vec::new() }
5887+
],
5888+
};
5889+
let mut route = Route { paths: vec![Path {
5890+
hops: vec![RouteHop {
5891+
pubkey: ln_test_utils::pubkey(42),
5892+
node_features: NodeFeatures::empty(),
5893+
short_channel_id: 42,
5894+
channel_features: ChannelFeatures::empty(),
5895+
fee_msat: 100,
5896+
cltv_expiry_delta: 0,
5897+
},
5898+
RouteHop {
5899+
pubkey: blinded_path.introduction_node_id,
5900+
node_features: NodeFeatures::empty(),
5901+
short_channel_id: 43,
5902+
channel_features: ChannelFeatures::empty(),
5903+
fee_msat: 1,
5904+
cltv_expiry_delta: 0,
5905+
}
5906+
],
5907+
blinded_tail: Some(BlindedTail {
5908+
hops: blinded_path.blinded_hops,
5909+
blinding_point: blinded_path.blinding_point,
5910+
final_cltv_expiry_delta: 0,
5911+
final_value_msat: 200,
5912+
}),
5913+
}], payment_params: None};
5914+
5915+
let payment_params = PaymentParameters::from_node_id(ln_test_utils::pubkey(47), 18);
5916+
let (_, network_graph, _, _, _) = build_line_graph();
5917+
add_random_cltv_offset(&mut route, &payment_params, &network_graph.read_only(), &[0; 32]);
5918+
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().final_cltv_expiry_delta, 40);
5919+
}
58745920
}
58755921

58765922
#[cfg(all(test, not(feature = "no-std")))]

0 commit comments

Comments
 (0)