@@ -21,6 +21,7 @@ use routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintH
21
21
use ln:: features:: { InitFeatures , InvoiceFeatures , NodeFeatures } ;
22
22
use ln:: msgs;
23
23
use ln:: msgs:: { ChannelMessageHandler , ChannelUpdate , OptionalField } ;
24
+ use ln:: wire:: Encode ;
24
25
use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
25
26
use util:: ser:: { Writeable , Writer } ;
26
27
use util:: { byte_utils, test_utils} ;
@@ -438,13 +439,29 @@ fn test_onion_failure() {
438
439
Some ( BADONION |PERM |6 ) , None , Some ( short_channel_id) ) ;
439
440
440
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 ( ) ;
441
458
run_onion_failure_test_with_fail_intercept ( "temporary_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
442
459
msg. amount_msat -= 1 ;
443
460
} , |msg| {
444
461
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
445
462
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) ) ;
448
465
449
466
let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
450
467
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() {
1097
1114
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_1. commitment_signed, false ) ;
1098
1115
1099
1116
// 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
+
1101
1122
let mut fail_conditions = PaymentFailedConditions :: new ( )
1102
1123
. blamed_scid ( channel. 0 . contents . short_channel_id )
1103
1124
. blamed_chan_closed ( false )
1104
- . expected_htlc_error_data ( 0x1000 | 7 , & error_data ) ;
1125
+ . expected_htlc_error_data ( 0x1000 | 7 , & err_data ) ;
1105
1126
expect_payment_failed_conditions ! ( nodes[ 0 ] , payment_hash, false , fail_conditions) ;
1106
1127
}
1107
1128
0 commit comments