@@ -439,13 +439,29 @@ fn test_onion_failure() {
439
439
Some ( BADONION |PERM |6 ) , None , Some ( short_channel_id) ) ;
440
440
441
441
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 ( ) ;
442
458
run_onion_failure_test_with_fail_intercept ( "temporary_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
443
459
msg. amount_msat -= 1 ;
444
460
} , |msg| {
445
461
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
446
462
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) ) ;
449
465
450
466
let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
451
467
run_onion_failure_test_with_fail_intercept ( "permanent_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
0 commit comments