@@ -409,18 +409,10 @@ where L::Target: Logger {
409
409
410
410
// Handle packed channel/node updates for passing back for the route handler
411
411
construct_onion_keys_callback ( secp_ctx, & path, session_priv,
412
- |shared_secret, _, _ , route_hop_opt, route_hop_idx|
412
+ |shared_secret, _, pubkey , route_hop_opt, route_hop_idx|
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
@@ -445,27 +432,52 @@ where L::Target: Logger {
445
432
if !fixed_time_eq ( & Hmac :: from_engine ( hmac) . into_inner ( ) , & err_packet. hmac ) { return }
446
433
let error_code_slice = match err_packet. failuremsg . get ( 0 ..2 ) {
447
434
Some ( s) => s,
448
- None => {
435
+ None if route_hop_opt . is_some ( ) => {
449
436
// Useless packet that we can't use but it passed HMAC, so it definitely came from the peer
450
437
// in question
451
438
let network_update = Some ( NetworkUpdate :: NodeFailure {
452
- node_id : route_hop . pubkey ,
439
+ node_id : pubkey,
453
440
is_permanent : true ,
454
441
} ) ;
455
- let short_channel_id = Some ( route_hop . short_channel_id ) ;
442
+ let short_channel_id = Some ( route_hop_opt . as_ref ( ) . unwrap ( ) . short_channel_id ) ;
456
443
res = Some ( ( network_update, short_channel_id, !is_from_final_node) ) ;
457
444
return
445
+ } ,
446
+ None => return , // Useless packet from a blinded path hop
447
+ } ;
448
+
449
+ let error_code = u16:: from_be_bytes ( error_code_slice. try_into ( ) . expect ( "len is 2" ) ) ;
450
+ error_code_ret = Some ( error_code) ;
451
+ error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
452
+
453
+ let route_hop = match route_hop_opt {
454
+ Some ( hop) => hop,
455
+ None => {
456
+ res = Some ( ( None , None , true ) ) ;
457
+ return
458
+ }
459
+ } ;
460
+ let amt_to_forward = htlc_msat - route_hop. fee_msat ;
461
+ htlc_msat = amt_to_forward;
462
+
463
+ // The failing hop includes either the inbound channel to the recipient or the outbound channel
464
+ // from the current hop (i.e., the next hop's inbound channel).
465
+ is_from_final_node = route_hop_idx + 1 == path. hops . len ( ) && path. blinded_tail . is_none ( ) ;
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
+
460
476
const BADONION : u16 = 0x8000 ;
461
477
const PERM : u16 = 0x4000 ;
462
478
const NODE : u16 = 0x2000 ;
463
479
const UPDATE : u16 = 0x1000 ;
464
480
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
481
let ( debug_field, debug_field_size) = errors:: get_onion_debug_field ( error_code) ;
470
482
471
483
// indicate that payment parameter has failed and no need to update Route object
0 commit comments