@@ -21,6 +21,7 @@ use routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintH
2121use ln:: features:: { InitFeatures , InvoiceFeatures , NodeFeatures } ;
2222use ln:: msgs;
2323use ln:: msgs:: { ChannelMessageHandler , ChannelUpdate , OptionalField } ;
24+ use ln:: wire:: Encode ;
2425use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
2526use util:: ser:: { Writeable , Writer } ;
2627use util:: { byte_utils, test_utils} ;
@@ -438,13 +439,29 @@ fn test_onion_failure() {
438439 Some ( BADONION |PERM |6 ) , None , Some ( short_channel_id) ) ;
439440
440441 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 ( ) ;
441458 run_onion_failure_test_with_fail_intercept ( "temporary_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
442459 msg. amount_msat -= 1 ;
443460 } , |msg| {
444461 let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
445462 let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
446- 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 ( ) [ .. ] ) ;
447- } , ||{ } , 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) ) ;
448465
449466 let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
450467 run_onion_failure_test_with_fail_intercept ( "permanent_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
@@ -1097,11 +1114,15 @@ fn test_phantom_dust_exposure_failure() {
10971114 commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_1. commitment_signed, false ) ;
10981115
10991116 // Ensure the payment fails with the expected error.
1100- let mut error_data = channel. 1 . encode_with_len ( ) ;
1117+ let mut err_data = Vec :: new ( ) ;
1118+ err_data. extend_from_slice ( & ( channel. 1 . serialized_length ( ) as u16 + 2 ) . to_be_bytes ( ) ) ;
1119+ err_data. extend_from_slice ( & ChannelUpdate :: TYPE . to_be_bytes ( ) ) ;
1120+ err_data. extend_from_slice ( & channel. 1 . encode ( ) ) ;
1121+
11011122 let mut fail_conditions = PaymentFailedConditions :: new ( )
11021123 . blamed_scid ( channel. 0 . contents . short_channel_id )
11031124 . blamed_chan_closed ( false )
1104- . expected_htlc_error_data ( 0x1000 | 7 , & error_data ) ;
1125+ . expected_htlc_error_data ( 0x1000 | 7 , & err_data ) ;
11051126 expect_payment_failed_conditions ! ( nodes[ 0 ] , payment_hash, false , fail_conditions) ;
11061127}
11071128
0 commit comments