Skip to content

Commit 4937f6e

Browse files
f adapt to having a RouteHop for the intro node
1 parent b927f56 commit 4937f6e

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

lightning/src/routing/router.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
21052105
let network_nodes = network_graph.nodes();
21062106

21072107
for path in route.paths.iter_mut() {
2108-
if path.blinded_tail.as_ref().map_or(false, |tail| tail.path.blinded_hops.len() > 1) { continue }
2108+
if path.blinded_tail.as_ref().map_or(false, |tail| tail.hops.len() > 1) { continue }
21092109

21102110
let mut shadow_ctlv_expiry_delta_offset: u32 = 0;
21112111

@@ -2176,9 +2176,10 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
21762176

21772177
// Add 'shadow' CLTV offset to the final hop
21782178
if let Some(tail) = path.blinded_tail.as_mut() {
2179-
tail.cltv_expiry_delta = tail.cltv_expiry_delta
2180-
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(tail.cltv_expiry_delta);
2181-
} else if let Some(last_hop) = path.hops.last_mut() {
2179+
tail.final_cltv_expiry_delta = tail.final_cltv_expiry_delta
2180+
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(tail.final_cltv_expiry_delta);
2181+
}
2182+
if let Some(last_hop) = path.hops.last_mut() {
21822183
last_hop.cltv_expiry_delta = last_hop.cltv_expiry_delta
21832184
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(last_hop.cltv_expiry_delta);
21842185
}
@@ -5810,6 +5811,14 @@ mod tests {
58105811
#[test]
58115812
fn blinded_path_cltv_shadow_offset() {
58125813
// Don't add a shadow offset to blinded paths with more than 1 hop.
5814+
let blinded_path = BlindedPath {
5815+
introduction_node_id: ln_test_utils::pubkey(43),
5816+
blinding_point: ln_test_utils::pubkey(44),
5817+
blinded_hops: vec![
5818+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() },
5819+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(46), encrypted_payload: Vec::new() }
5820+
],
5821+
};
58135822
let mut route = Route { paths: vec![Path {
58145823
hops: vec![RouteHop {
58155824
pubkey: ln_test_utils::pubkey(42),
@@ -5818,32 +5827,33 @@ mod tests {
58185827
channel_features: ChannelFeatures::empty(),
58195828
fee_msat: 100,
58205829
cltv_expiry_delta: 0,
5821-
}],
5822-
blinded_tail: Some(BlindedTail {
5823-
path: BlindedPath {
5824-
introduction_node_id: ln_test_utils::pubkey(43),
5825-
blinding_point: ln_test_utils::pubkey(44),
5826-
blinded_hops: vec![
5827-
BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() },
5828-
BlindedHop { blinded_node_id: ln_test_utils::pubkey(46), encrypted_payload: Vec::new() }
5829-
],
5830-
},
5831-
intro_node_scid: 43,
5830+
},
5831+
RouteHop {
5832+
pubkey: blinded_path.introduction_node_id,
5833+
node_features: NodeFeatures::empty(),
5834+
short_channel_id: 43,
5835+
channel_features: ChannelFeatures::empty(),
58325836
fee_msat: 1,
58335837
cltv_expiry_delta: 0,
5838+
}
5839+
],
5840+
blinded_tail: Some(BlindedTail {
5841+
hops: blinded_path.blinded_hops,
5842+
blinding_point: blinded_path.blinding_point,
5843+
final_cltv_expiry_delta: 0,
58345844
final_value_msat: 200,
58355845
}),
58365846
}], payment_params: None};
58375847

58385848
let payment_params = PaymentParameters::from_node_id(ln_test_utils::pubkey(47), 18);
58395849
let (_, network_graph, _, _, _) = build_line_graph();
58405850
add_random_cltv_offset(&mut route, &payment_params, &network_graph.read_only(), &[0; 32]);
5841-
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().cltv_expiry_delta, 0);
5851+
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().final_cltv_expiry_delta, 0);
58425852

58435853
// Add a shadow offset if we're sending to a 1-hop blinded path.
5844-
route.paths[0].blinded_tail.as_mut().unwrap().path.blinded_hops.pop();
5854+
route.paths[0].blinded_tail.as_mut().unwrap().hops.pop();
58455855
add_random_cltv_offset(&mut route, &payment_params, &network_graph.read_only(), &[0; 32]);
5846-
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().cltv_expiry_delta, 40);
5856+
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().final_cltv_expiry_delta, 40);
58475857
}
58485858
}
58495859

0 commit comments

Comments
 (0)