Skip to content

Commit 8d4e072

Browse files
f adapt to having a RouteHop for the intro node
1 parent c6595f3 commit 8d4e072

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
@@ -2106,7 +2106,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
21062106
let network_nodes = network_graph.nodes();
21072107

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

21112111
let mut shadow_ctlv_expiry_delta_offset: u32 = 0;
21122112

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

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

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

58445854
// Add a shadow offset if we're sending to a 1-hop blinded path.
5845-
route.paths[0].blinded_tail.as_mut().unwrap().path.blinded_hops.pop();
5855+
route.paths[0].blinded_tail.as_mut().unwrap().hops.pop();
58465856
add_random_cltv_offset(&mut route, &payment_params, &network_graph.read_only(), &[0; 32]);
5847-
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().cltv_expiry_delta, 40);
5857+
assert_eq!(route.paths[0].blinded_tail.as_ref().unwrap().final_cltv_expiry_delta, 40);
58485858
}
58495859
}
58505860

0 commit comments

Comments
 (0)