@@ -2621,7 +2621,7 @@ where
26212621
26222622 fn decode_update_add_htlc_onion (
26232623 & self , msg : & msgs:: UpdateAddHTLC
2624- ) -> Result < ( onion_utils:: Hop , [ u8 ; 32 ] ) , HTLCFailureMsg > {
2624+ ) -> Result < ( onion_utils:: Hop , [ u8 ; 32 ] , Option < Result < PublicKey , secp256k1 :: Error > > ) , HTLCFailureMsg > {
26252625 macro_rules! return_malformed_err {
26262626 ( $msg: expr, $err_code: expr) => {
26272627 {
@@ -2676,16 +2676,20 @@ where
26762676 return_err ! ( err_msg, err_code, & [ 0 ; 0 ] ) ;
26772677 } ,
26782678 } ;
2679- let ( outgoing_scid, outgoing_amt_msat, outgoing_cltv_value) = match next_hop {
2679+ let ( outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt ) = match next_hop {
26802680 onion_utils:: Hop :: Forward {
26812681 next_hop_data : msgs:: OnionHopData {
26822682 format : msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } , amt_to_forward,
26832683 outgoing_cltv_value,
26842684 } , ..
2685- } => ( short_channel_id, amt_to_forward, outgoing_cltv_value) ,
2685+ } => {
2686+ let next_pk = onion_utils:: next_hop_packet_pubkey ( & self . secp_ctx ,
2687+ msg. onion_routing_packet . public_key . unwrap ( ) , & shared_secret) ;
2688+ ( short_channel_id, amt_to_forward, outgoing_cltv_value, Some ( next_pk) )
2689+ } ,
26862690 // We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
26872691 // inbound channel's state.
2688- onion_utils:: Hop :: Receive { .. } => return Ok ( ( next_hop, shared_secret) ) ,
2692+ onion_utils:: Hop :: Receive { .. } => return Ok ( ( next_hop, shared_secret, None ) ) ,
26892693 onion_utils:: Hop :: Forward {
26902694 next_hop_data : msgs:: OnionHopData { format : msgs:: OnionHopDataFormat :: FinalNode { .. } , .. } , ..
26912695 } => {
@@ -2826,11 +2830,12 @@ where
28262830 }
28272831 return_err ! ( err, code, & res. 0 [ ..] ) ;
28282832 }
2829- Ok ( ( next_hop, shared_secret) )
2833+ Ok ( ( next_hop, shared_secret, next_packet_pk_opt ) )
28302834 }
28312835
28322836 fn construct_pending_htlc_status < ' a > (
28332837 & self , msg : & msgs:: UpdateAddHTLC , shared_secret : [ u8 ; 32 ] , decoded_hop : onion_utils:: Hop ,
2838+ next_packet_pubkey_opt : Option < Result < PublicKey , secp256k1:: Error > >
28342839 ) -> PendingHTLCStatus {
28352840 macro_rules! return_err {
28362841 ( $msg: expr, $err_code: expr, $data: expr) => {
@@ -2860,10 +2865,10 @@ where
28602865 }
28612866 } ,
28622867 onion_utils:: Hop :: Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
2863- let new_pubkey = msg . onion_routing_packet . public_key . unwrap ( ) ;
2868+ debug_assert ! ( next_packet_pubkey_opt . is_some ( ) ) ;
28642869 let outgoing_packet = msgs:: OnionPacket {
28652870 version : 0 ,
2866- public_key : onion_utils :: next_hop_packet_pubkey ( & self . secp_ctx , new_pubkey , & shared_secret ) ,
2871+ public_key : next_packet_pubkey_opt . unwrap_or ( Err ( secp256k1 :: Error :: InvalidPublicKey ) ) ,
28672872 hop_data : new_packet_bytes,
28682873 hmac : next_hop_hmac. clone ( ) ,
28692874 } ;
@@ -5400,8 +5405,8 @@ where
54005405 hash_map:: Entry :: Occupied ( mut chan) => {
54015406
54025407 let pending_forward_info = match decoded_hop_res {
5403- Ok ( ( next_hop, shared_secret) ) =>
5404- self . construct_pending_htlc_status ( msg, shared_secret, next_hop) ,
5408+ Ok ( ( next_hop, shared_secret, next_packet_pk_opt ) ) =>
5409+ self . construct_pending_htlc_status ( msg, shared_secret, next_hop, next_packet_pk_opt ) ,
54055410 Err ( e) => PendingHTLCStatus :: Fail ( e)
54065411 } ;
54075412 let create_pending_htlc_status = |chan : & Channel < <SP :: Target as SignerProvider >:: Signer > , pending_forward_info : PendingHTLCStatus , error_code : u16 | {
0 commit comments