Skip to content

Commit 7af02d0

Browse files
OMs: fix panic sending to a two-hop blinded route where we are the intro node
1 parent a4e242b commit 7af02d0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,20 @@ fn too_big_packet_error() {
174174
fn we_are_intro_node() {
175175
// If we are sending straight to a blinded route and we are the introduction node, we need to
176176
// advance the blinded route by 1 hop so the second hop is the new introduction node.
177-
let nodes = create_nodes(3);
177+
let mut nodes = create_nodes(3);
178178
let test_msg = TestCustomMessage {};
179179

180180
let secp_ctx = Secp256k1::new();
181181
let blinded_route = BlindedRoute::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
182182

183183
nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg.clone()), None).unwrap();
184184
pass_along_path(&nodes, None);
185+
186+
// Try with a two-hop blinded route where we are the introduction node.
187+
let blinded_route = BlindedRoute::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap();
188+
nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg), None).unwrap();
189+
nodes.remove(2);
190+
pass_along_path(&nodes, None);
185191
}
186192

187193
#[test]

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,8 @@ fn packet_payloads_and_keys<T: CustomOnionMessageContents, S: secp256k1::Signing
513513
next_blinding_override: Some(blinding_pt),
514514
})), control_tlvs_ss));
515515
}
516-
if let Some(encrypted_payload) = enc_payload_opt {
517-
payloads.push((Payload::Forward(ForwardControlTlvs::Blinded(encrypted_payload)),
518-
control_tlvs_ss));
519-
} else { debug_assert!(false); }
520-
blinded_path_idx += 1;
521-
} else if blinded_path_idx < num_blinded_hops - 1 && enc_payload_opt.is_some() {
516+
}
517+
if blinded_path_idx < num_blinded_hops.saturating_sub(1) && enc_payload_opt.is_some() {
522518
payloads.push((Payload::Forward(ForwardControlTlvs::Blinded(enc_payload_opt.unwrap())),
523519
control_tlvs_ss));
524520
blinded_path_idx += 1;

0 commit comments

Comments
 (0)