@@ -2621,7 +2621,7 @@ where
2621
2621
2622
2622
fn decode_update_add_htlc_onion (
2623
2623
& 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 > {
2625
2625
macro_rules! return_malformed_err {
2626
2626
( $msg: expr, $err_code: expr) => {
2627
2627
{
@@ -2676,16 +2676,20 @@ where
2676
2676
return_err ! ( err_msg, err_code, & [ 0 ; 0 ] ) ;
2677
2677
} ,
2678
2678
} ;
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 {
2680
2680
onion_utils:: Hop :: Forward {
2681
2681
next_hop_data : msgs:: OnionHopData {
2682
2682
format : msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } , amt_to_forward,
2683
2683
outgoing_cltv_value,
2684
2684
} , ..
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
+ } ,
2686
2690
// We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
2687
2691
// 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 ) ) ,
2689
2693
onion_utils:: Hop :: Forward {
2690
2694
next_hop_data : msgs:: OnionHopData { format : msgs:: OnionHopDataFormat :: FinalNode { .. } , .. } , ..
2691
2695
} => {
@@ -2826,11 +2830,12 @@ where
2826
2830
}
2827
2831
return_err ! ( err, code, & res. 0 [ ..] ) ;
2828
2832
}
2829
- Ok ( ( next_hop, shared_secret) )
2833
+ Ok ( ( next_hop, shared_secret, next_packet_pk_opt ) )
2830
2834
}
2831
2835
2832
2836
fn construct_pending_htlc_status < ' a > (
2833
2837
& self , msg : & msgs:: UpdateAddHTLC , shared_secret : [ u8 ; 32 ] , decoded_hop : onion_utils:: Hop ,
2838
+ next_packet_pubkey_opt : Option < Result < PublicKey , secp256k1:: Error > >
2834
2839
) -> PendingHTLCStatus {
2835
2840
macro_rules! return_err {
2836
2841
( $msg: expr, $err_code: expr, $data: expr) => {
@@ -2860,10 +2865,10 @@ where
2860
2865
}
2861
2866
} ,
2862
2867
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 ( ) ) ;
2864
2869
let outgoing_packet = msgs:: OnionPacket {
2865
2870
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 ) ) ,
2867
2872
hop_data : new_packet_bytes,
2868
2873
hmac : next_hop_hmac. clone ( ) ,
2869
2874
} ;
@@ -5400,8 +5405,8 @@ where
5400
5405
hash_map:: Entry :: Occupied ( mut chan) => {
5401
5406
5402
5407
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 ) ,
5405
5410
Err ( e) => PendingHTLCStatus :: Fail ( e)
5406
5411
} ;
5407
5412
let create_pending_htlc_status = |chan : & Channel < <SP :: Target as SignerProvider >:: Signer > , pending_forward_info : PendingHTLCStatus , error_code : u16 | {
0 commit comments