Skip to content

Commit 85d0698

Browse files
committed
Test we still parse failures w/ non-prefixed updates
1 parent 62817b4 commit 85d0698

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lightning/src/ln/onion_route_tests.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,29 @@ fn test_onion_failure() {
439439
Some(BADONION|PERM|6), None, Some(short_channel_id));
440440

441441
let short_channel_id = channels[1].0.contents.short_channel_id;
442+
let chan_update = ChannelUpdate::dummy(short_channel_id);
443+
444+
let mut err_data = Vec::new();
445+
err_data.extend_from_slice(&(chan_update.serialized_length() as u16 + 2).to_be_bytes());
446+
err_data.extend_from_slice(&ChannelUpdate::TYPE.to_be_bytes());
447+
err_data.extend_from_slice(&chan_update.encode());
448+
run_onion_failure_test_with_fail_intercept("temporary_channel_failure", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| {
449+
msg.amount_msat -= 1;
450+
}, |msg| {
451+
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
452+
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
453+
msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), UPDATE|7, &err_data);
454+
}, ||{}, true, Some(UPDATE|7), Some(NetworkUpdate::ChannelUpdateMessage{msg: chan_update.clone()}), Some(short_channel_id));
455+
456+
// Check we can still handle onion failures that include channel updates without a type prefix
457+
let err_data_without_type = chan_update.encode_with_len();
442458
run_onion_failure_test_with_fail_intercept("temporary_channel_failure", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| {
443459
msg.amount_msat -= 1;
444460
}, |msg| {
445461
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
446462
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
447-
msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), UPDATE|7, &ChannelUpdate::dummy(short_channel_id).encode_with_len()[..]);
448-
}, ||{}, true, Some(UPDATE|7), Some(NetworkUpdate::ChannelUpdateMessage{msg: ChannelUpdate::dummy(short_channel_id)}), Some(short_channel_id));
463+
msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), UPDATE|7, &err_data_without_type);
464+
}, ||{}, true, Some(UPDATE|7), Some(NetworkUpdate::ChannelUpdateMessage{msg: chan_update}), Some(short_channel_id));
449465

450466
let short_channel_id = channels[1].0.contents.short_channel_id;
451467
run_onion_failure_test_with_fail_intercept("permanent_channel_failure", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| {

0 commit comments

Comments
 (0)