@@ -473,27 +473,23 @@ where
473473 NS :: Target : NodeSigner ,
474474 L :: Target : Logger ,
475475{
476- macro_rules! return_malformed_err {
477- ( $msg: expr, $err_code: expr, $force_blinding_error: expr) => {
478- {
479- log_info!( logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
480- let ( sha256_of_onion, failure_code) = if $force_blinding_error || 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+ } ;
494490
495491 if let Err ( _) = msg. onion_routing_packet . public_key {
496- return_malformed_err ! ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 , false ) ;
492+ return encode_malformed_error ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 ) ;
497493 }
498494
499495 if msg. onion_routing_packet . version != 0 {
@@ -503,12 +499,12 @@ where
503499 //receiving node would have to brute force to figure out which version was put in the
504500 //packet by the node that send us the message, in the case of hashing the hop_data, the
505501 //node knows the HMAC matched, so they already know what is there...
506- return_malformed_err ! ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 , false ) ;
502+ return encode_malformed_error ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
507503 }
508504
509505 let encode_relay_error = |message : & str , err_code : u16 , shared_secret : [ u8 ; 32 ] , trampoline_shared_secret : Option < [ u8 ; 32 ] > , data : & [ u8 ] | {
510506 if msg. blinding_point . is_some ( ) {
511- return_malformed_err ! ( message, INVALID_ONION_BLINDING , false )
507+ return encode_malformed_error ( message, INVALID_ONION_BLINDING )
512508 }
513509
514510 log_info ! ( logger, "Failed to accept/forward incoming HTLC: {}" , message) ;
@@ -526,8 +522,8 @@ where
526522 msg. payment_hash , msg. blinding_point , node_signer
527523 ) {
528524 Ok ( res) => res,
529- Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code, trampoline_onion_blinding } ) => {
530- return_malformed_err ! ( err_msg, err_code, trampoline_onion_blinding ) ;
525+ Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
526+ return encode_malformed_error ( err_msg, err_code) ;
531527 } ,
532528 Err ( onion_utils:: OnionDecodeErr :: Relay { err_msg, err_code, shared_secret, trampoline_shared_secret } ) => {
533529 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