@@ -413,14 +413,6 @@ where L::Target: Logger {
413
413
{
414
414
if res. is_some ( ) { return ; }
415
415
416
- let route_hop = match route_hop_opt {
417
- Some ( hop) => hop,
418
- None => return ,
419
- } ;
420
-
421
- let amt_to_forward = htlc_msat - route_hop. fee_msat ;
422
- htlc_msat = amt_to_forward;
423
-
424
416
let ammag = gen_ammag_from_shared_secret ( shared_secret. as_ref ( ) ) ;
425
417
426
418
let mut decryption_tmp = Vec :: with_capacity ( packet_decrypted. len ( ) ) ;
@@ -429,11 +421,6 @@ where L::Target: Logger {
429
421
chacha. process ( & packet_decrypted, & mut decryption_tmp[ ..] ) ;
430
422
packet_decrypted = decryption_tmp;
431
423
432
- // The failing hop includes either the inbound channel to the recipient or the outbound channel
433
- // from the current hop (i.e., the next hop's inbound channel).
434
- is_from_final_node = route_hop_idx + 1 == path. hops . len ( ) ;
435
- let failing_route_hop = if is_from_final_node { route_hop } else { & path. hops [ route_hop_idx + 1 ] } ;
436
-
437
424
let err_packet = match msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new ( & packet_decrypted) ) {
438
425
Ok ( p) => p,
439
426
Err ( _) => return
@@ -442,30 +429,58 @@ where L::Target: Logger {
442
429
let mut hmac = HmacEngine :: < Sha256 > :: new ( & um) ;
443
430
hmac. input ( & err_packet. encode ( ) [ 32 ..] ) ;
444
431
432
+ // The failing hop includes either the inbound channel to the recipient or the outbound channel
433
+ // from the current hop (i.e., the next hop's inbound channel).
434
+ let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |t| t. hops . len ( ) ) ;
435
+ is_from_final_node = route_hop_idx + 1 == path. hops . len ( ) &&
436
+ ( path. blinded_tail . is_none ( ) || num_blinded_hops == 1 ) ;
437
+
445
438
if !fixed_time_eq ( & Hmac :: from_engine ( hmac) . into_inner ( ) , & err_packet. hmac ) { return }
446
439
let error_code_slice = match err_packet. failuremsg . get ( 0 ..2 ) {
447
440
Some ( s) => s,
448
- None => {
441
+ None if route_hop_opt . is_some ( ) => {
449
442
// Useless packet that we can't use but it passed HMAC, so it definitely came from the peer
450
443
// in question
451
444
let network_update = Some ( NetworkUpdate :: NodeFailure {
452
- node_id : route_hop . pubkey ,
445
+ node_id : route_hop_opt . as_ref ( ) . unwrap ( ) . pubkey ,
453
446
is_permanent : true ,
454
447
} ) ;
455
- let short_channel_id = Some ( route_hop . short_channel_id ) ;
448
+ let short_channel_id = Some ( route_hop_opt . as_ref ( ) . unwrap ( ) . short_channel_id ) ;
456
449
res = Some ( ( network_update, short_channel_id, !is_from_final_node) ) ;
457
450
return
451
+ } ,
452
+ None => return , // Useless packet from a blinded path hop
453
+ } ;
454
+
455
+ let error_code = u16:: from_be_bytes ( error_code_slice. try_into ( ) . expect ( "len is 2" ) ) ;
456
+ error_code_ret = Some ( error_code) ;
457
+ error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
458
+
459
+ let route_hop = match route_hop_opt {
460
+ Some ( hop) => hop,
461
+ None => {
462
+ res = Some ( ( None , None , true ) ) ;
463
+ return
464
+ }
465
+ } ;
466
+ let failing_route_hop = if is_from_final_node { route_hop } else {
467
+ match path. hops . get ( route_hop_idx + 1 ) {
468
+ Some ( hop) => hop,
469
+ None => {
470
+ res = Some ( ( None , None , true ) ) ;
471
+ return
472
+ }
458
473
}
459
474
} ;
475
+
476
+ let amt_to_forward = htlc_msat - route_hop. fee_msat ;
477
+ htlc_msat = amt_to_forward;
478
+
460
479
const BADONION : u16 = 0x8000 ;
461
480
const PERM : u16 = 0x4000 ;
462
481
const NODE : u16 = 0x2000 ;
463
482
const UPDATE : u16 = 0x1000 ;
464
483
465
- let error_code = u16:: from_be_bytes ( error_code_slice. try_into ( ) . expect ( "len is 2" ) ) ;
466
- error_code_ret = Some ( error_code) ;
467
- error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
468
-
469
484
let ( debug_field, debug_field_size) = errors:: get_onion_debug_field ( error_code) ;
470
485
471
486
// indicate that payment parameter has failed and no need to update Route object
0 commit comments