@@ -473,27 +473,23 @@ where
473
473
NS :: Target : NodeSigner ,
474
474
L :: Target : Logger ,
475
475
{
476
- macro_rules! return_malformed_err {
477
- ( $msg: expr, $err_code: expr) => {
478
- {
479
- log_info!( logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
480
- let ( sha256_of_onion, failure_code) = if msg. blinding_point. is_some( ) {
481
- ( [ 0 ; 32 ] , INVALID_ONION_BLINDING )
482
- } else {
483
- ( Sha256 :: hash( & msg. onion_routing_packet. hop_data) . to_byte_array( ) , $err_code)
484
- } ;
485
- return Err ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
486
- channel_id: msg. channel_id,
487
- htlc_id: msg. htlc_id,
488
- sha256_of_onion,
489
- failure_code,
490
- } ) ) ;
491
- }
492
- }
493
- }
476
+ let encode_malformed_error = |message : & str , err_code : u16 | {
477
+ log_info ! ( logger, "Failed to accept/forward incoming HTLC: {}" , message) ;
478
+ let ( sha256_of_onion, failure_code) = if msg. blinding_point . is_some ( ) || err_code == INVALID_ONION_BLINDING {
479
+ ( [ 0 ; 32 ] , INVALID_ONION_BLINDING )
480
+ } else {
481
+ ( Sha256 :: hash ( & msg. onion_routing_packet . hop_data ) . to_byte_array ( ) , err_code)
482
+ } ;
483
+ return Err ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
484
+ channel_id : msg. channel_id ,
485
+ htlc_id : msg. htlc_id ,
486
+ sha256_of_onion,
487
+ failure_code,
488
+ } ) ) ;
489
+ } ;
494
490
495
491
if let Err ( _) = msg. onion_routing_packet . public_key {
496
- return_malformed_err ! ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 ) ;
492
+ return encode_malformed_error ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 ) ;
497
493
}
498
494
499
495
if msg. onion_routing_packet . version != 0 {
@@ -503,12 +499,12 @@ where
503
499
//receiving node would have to brute force to figure out which version was put in the
504
500
//packet by the node that send us the message, in the case of hashing the hop_data, the
505
501
//node knows the HMAC matched, so they already know what is there...
506
- return_malformed_err ! ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
502
+ return encode_malformed_error ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
507
503
}
508
504
509
505
let encode_relay_error = |message : & str , err_code : u16 , shared_secret : [ u8 ; 32 ] , trampoline_shared_secret : Option < [ u8 ; 32 ] > , data : & [ u8 ] | {
510
506
if msg. blinding_point . is_some ( ) {
511
- return_malformed_err ! ( message, INVALID_ONION_BLINDING )
507
+ return encode_malformed_error ( message, INVALID_ONION_BLINDING )
512
508
}
513
509
514
510
log_info ! ( logger, "Failed to accept/forward incoming HTLC: {}" , message) ;
@@ -527,7 +523,7 @@ where
527
523
) {
528
524
Ok ( res) => res,
529
525
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
530
- return_malformed_err ! ( err_msg, err_code) ;
526
+ return encode_malformed_error ( err_msg, err_code) ;
531
527
} ,
532
528
Err ( onion_utils:: OnionDecodeErr :: Relay { err_msg, err_code, shared_secret, trampoline_shared_secret } ) => {
533
529
return encode_relay_error ( err_msg, err_code, shared_secret. secret_bytes ( ) , trampoline_shared_secret. map ( |tss| tss. secret_bytes ( ) ) , & [ 0 ; 0 ] ) ;
0 commit comments