@@ -464,27 +464,23 @@ where
464
464
NS :: Target : NodeSigner ,
465
465
L :: Target : Logger ,
466
466
{
467
- macro_rules! return_malformed_err {
468
- ( $msg: expr, $err_code: expr) => {
469
- {
470
- log_info!( logger, "Failed to accept/forward incoming HTLC: {}" , $msg) ;
471
- let ( sha256_of_onion, failure_code) = if msg. blinding_point. is_some( ) {
472
- ( [ 0 ; 32 ] , INVALID_ONION_BLINDING )
473
- } else {
474
- ( Sha256 :: hash( & msg. onion_routing_packet. hop_data) . to_byte_array( ) , $err_code)
475
- } ;
476
- return Err ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
477
- channel_id: msg. channel_id,
478
- htlc_id: msg. htlc_id,
479
- sha256_of_onion,
480
- failure_code,
481
- } ) ) ;
482
- }
483
- }
484
- }
467
+ let encode_malformed_error = |message : & str , err_code : u16 | {
468
+ log_info ! ( logger, "Failed to accept/forward incoming HTLC: {}" , message) ;
469
+ let ( sha256_of_onion, failure_code) = if msg. blinding_point . is_some ( ) {
470
+ ( [ 0 ; 32 ] , INVALID_ONION_BLINDING )
471
+ } else {
472
+ ( Sha256 :: hash ( & msg. onion_routing_packet . hop_data ) . to_byte_array ( ) , err_code)
473
+ } ;
474
+ return Err ( HTLCFailureMsg :: Malformed ( msgs:: UpdateFailMalformedHTLC {
475
+ channel_id : msg. channel_id ,
476
+ htlc_id : msg. htlc_id ,
477
+ sha256_of_onion,
478
+ failure_code,
479
+ } ) ) ;
480
+ } ;
485
481
486
482
if let Err ( _) = msg. onion_routing_packet . public_key {
487
- return_malformed_err ! ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 ) ;
483
+ return encode_malformed_error ( "invalid ephemeral pubkey" , 0x8000 | 0x4000 | 6 ) ;
488
484
}
489
485
490
486
if msg. onion_routing_packet . version != 0 {
@@ -494,12 +490,12 @@ where
494
490
//receiving node would have to brute force to figure out which version was put in the
495
491
//packet by the node that send us the message, in the case of hashing the hop_data, the
496
492
//node knows the HMAC matched, so they already know what is there...
497
- return_malformed_err ! ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
493
+ return encode_malformed_error ( "Unknown onion packet version" , 0x8000 | 0x4000 | 4 ) ;
498
494
}
499
495
500
496
let encode_relay_error = |message : & str , err_code : u16 , shared_secret : [ u8 ; 32 ] , trampoline_shared_secret : Option < [ u8 ; 32 ] > , data : & [ u8 ] | {
501
497
if msg. blinding_point . is_some ( ) {
502
- return_malformed_err ! ( message, INVALID_ONION_BLINDING )
498
+ return encode_malformed_error ( message, INVALID_ONION_BLINDING )
503
499
}
504
500
505
501
log_info ! ( logger, "Failed to accept/forward incoming HTLC: {}" , message) ;
@@ -518,7 +514,7 @@ where
518
514
) {
519
515
Ok ( res) => res,
520
516
Err ( onion_utils:: OnionDecodeErr :: Malformed { err_msg, err_code } ) => {
521
- return_malformed_err ! ( err_msg, err_code) ;
517
+ return encode_malformed_error ( err_msg, err_code) ;
522
518
} ,
523
519
Err ( onion_utils:: OnionDecodeErr :: Relay { err_msg, err_code, shared_secret, trampoline_shared_secret } ) => {
524
520
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