@@ -2617,7 +2617,7 @@ where
26172617 }
26182618
26192619 fn construct_fwd_pending_htlc_info (
2620- & self , msg : & msgs:: UpdateAddHTLC , hop_data : msgs:: OnionHopData , hop_hmac : [ u8 ; 32 ] ,
2620+ & self , msg : & msgs:: UpdateAddHTLC , hop_data : msgs:: InboundOnionPayload , hop_hmac : [ u8 ; 32 ] ,
26212621 new_packet_bytes : [ u8 ; onion_utils:: ONION_DATA_LEN ] , shared_secret : [ u8 ; 32 ] ,
26222622 next_packet_pubkey_opt : Option < Result < PublicKey , secp256k1:: Error > >
26232623 ) -> Result < PendingHTLCInfo , InboundOnionErr > {
@@ -2626,42 +2626,44 @@ where
26262626 version : 0 ,
26272627 public_key : next_packet_pubkey_opt. unwrap_or ( Err ( secp256k1:: Error :: InvalidPublicKey ) ) ,
26282628 hop_data : new_packet_bytes,
2629- hmac : hop_hmac. clone ( ) ,
2629+ hmac : hop_hmac,
26302630 } ;
26312631
2632- let short_channel_id = match hop_data. format {
2633- msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } => short_channel_id,
2634- msgs:: OnionHopDataFormat :: FinalNode { .. } => {
2632+ let ( short_channel_id, amt_to_forward, outgoing_cltv_value) = match hop_data {
2633+ msgs:: InboundOnionPayload :: Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
2634+ ( short_channel_id, amt_to_forward, outgoing_cltv_value) ,
2635+ msgs:: InboundOnionPayload :: Receive { .. } =>
26352636 return Err ( InboundOnionErr {
26362637 msg : "Final Node OnionHopData provided for us as an intermediary node" ,
26372638 err_code : 0x4000 | 22 ,
26382639 err_data : Vec :: new ( ) ,
2639- } )
2640- } ,
2640+ } ) ,
26412641 } ;
26422642
26432643 Ok ( PendingHTLCInfo {
26442644 routing : PendingHTLCRouting :: Forward {
26452645 onion_packet : outgoing_packet,
26462646 short_channel_id,
26472647 } ,
2648- payment_hash : msg. payment_hash . clone ( ) ,
2648+ payment_hash : msg. payment_hash ,
26492649 incoming_shared_secret : shared_secret,
26502650 incoming_amt_msat : Some ( msg. amount_msat ) ,
2651- outgoing_amt_msat : hop_data . amt_to_forward ,
2652- outgoing_cltv_value : hop_data . outgoing_cltv_value ,
2651+ outgoing_amt_msat : amt_to_forward,
2652+ outgoing_cltv_value,
26532653 skimmed_fee_msat : None ,
26542654 } )
26552655 }
26562656
26572657 fn construct_recv_pending_htlc_info (
2658- & self , hop_data : msgs:: OnionHopData , shared_secret : [ u8 ; 32 ] , payment_hash : PaymentHash ,
2658+ & self , hop_data : msgs:: InboundOnionPayload , shared_secret : [ u8 ; 32 ] , payment_hash : PaymentHash ,
26592659 amt_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > , allow_underpay : bool ,
26602660 counterparty_skimmed_fee_msat : Option < u64 > ,
26612661 ) -> Result < PendingHTLCInfo , InboundOnionErr > {
2662- let ( payment_data, keysend_preimage, payment_metadata) = match hop_data. format {
2663- msgs:: OnionHopDataFormat :: FinalNode { payment_data, keysend_preimage, payment_metadata } =>
2664- ( payment_data, keysend_preimage, payment_metadata) ,
2662+ let ( payment_data, keysend_preimage, onion_amt_msat, outgoing_cltv_value, payment_metadata) = match hop_data {
2663+ msgs:: InboundOnionPayload :: Receive {
2664+ payment_data, keysend_preimage, amt_msat, outgoing_cltv_value, payment_metadata, ..
2665+ } =>
2666+ ( payment_data, keysend_preimage, amt_msat, outgoing_cltv_value, payment_metadata) ,
26652667 _ =>
26662668 return Err ( InboundOnionErr {
26672669 err_code : 0x4000 |22 ,
@@ -2670,7 +2672,7 @@ where
26702672 } ) ,
26712673 } ;
26722674 // final_incorrect_cltv_expiry
2673- if hop_data . outgoing_cltv_value > cltv_expiry {
2675+ if outgoing_cltv_value > cltv_expiry {
26742676 return Err ( InboundOnionErr {
26752677 msg : "Upstream node set CLTV to less than the CLTV set by the sender" ,
26762678 err_code : 18 ,
@@ -2685,7 +2687,7 @@ where
26852687 // payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
26862688 // channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
26872689 let current_height: u32 = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
2688- if ( hop_data . outgoing_cltv_value as u64 ) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
2690+ if ( outgoing_cltv_value as u64 ) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
26892691 let mut err_data = Vec :: with_capacity ( 12 ) ;
26902692 err_data. extend_from_slice ( & amt_msat. to_be_bytes ( ) ) ;
26912693 err_data. extend_from_slice ( & current_height. to_be_bytes ( ) ) ;
@@ -2694,8 +2696,8 @@ where
26942696 msg : "The final CLTV expiry is too soon to handle" ,
26952697 } ) ;
26962698 }
2697- if ( !allow_underpay && hop_data . amt_to_forward > amt_msat) ||
2698- ( allow_underpay && hop_data . amt_to_forward >
2699+ if ( !allow_underpay && onion_amt_msat > amt_msat) ||
2700+ ( allow_underpay && onion_amt_msat >
26992701 amt_msat. saturating_add ( counterparty_skimmed_fee_msat. unwrap_or ( 0 ) ) )
27002702 {
27012703 return Err ( InboundOnionErr {
@@ -2730,13 +2732,13 @@ where
27302732 payment_data,
27312733 payment_preimage,
27322734 payment_metadata,
2733- incoming_cltv_expiry : hop_data . outgoing_cltv_value ,
2735+ incoming_cltv_expiry : outgoing_cltv_value,
27342736 }
27352737 } else if let Some ( data) = payment_data {
27362738 PendingHTLCRouting :: Receive {
27372739 payment_data : data,
27382740 payment_metadata,
2739- incoming_cltv_expiry : hop_data . outgoing_cltv_value ,
2741+ incoming_cltv_expiry : outgoing_cltv_value,
27402742 phantom_shared_secret,
27412743 }
27422744 } else {
@@ -2751,8 +2753,8 @@ where
27512753 payment_hash,
27522754 incoming_shared_secret : shared_secret,
27532755 incoming_amt_msat : Some ( amt_msat) ,
2754- outgoing_amt_msat : hop_data . amt_to_forward ,
2755- outgoing_cltv_value : hop_data . outgoing_cltv_value ,
2756+ outgoing_amt_msat : onion_amt_msat ,
2757+ outgoing_cltv_value,
27562758 skimmed_fee_msat : counterparty_skimmed_fee_msat,
27572759 } )
27582760 }
@@ -2816,9 +2818,8 @@ where
28162818 } ;
28172819 let ( outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt) = match next_hop {
28182820 onion_utils:: Hop :: Forward {
2819- next_hop_data : msgs:: OnionHopData {
2820- format : msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } , amt_to_forward,
2821- outgoing_cltv_value,
2821+ next_hop_data : msgs:: InboundOnionPayload :: Forward {
2822+ short_channel_id, amt_to_forward, outgoing_cltv_value
28222823 } , ..
28232824 } => {
28242825 let next_pk = onion_utils:: next_hop_packet_pubkey ( & self . secp_ctx ,
@@ -2828,9 +2829,7 @@ where
28282829 // We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
28292830 // inbound channel's state.
28302831 onion_utils:: Hop :: Receive { .. } => return Ok ( ( next_hop, shared_secret, None ) ) ,
2831- onion_utils:: Hop :: Forward {
2832- next_hop_data : msgs:: OnionHopData { format : msgs:: OnionHopDataFormat :: FinalNode { .. } , .. } , ..
2833- } => {
2832+ onion_utils:: Hop :: Forward { next_hop_data : msgs:: InboundOnionPayload :: Receive { .. } , .. } => {
28342833 return_err ! ( "Final Node OnionHopData provided for us as an intermediary node" , 0x4000 | 22 , & [ 0 ; 0 ] ) ;
28352834 }
28362835 } ;
@@ -10020,16 +10019,14 @@ mod tests {
1002010019 let node = create_network ( 1 , & node_cfg, & node_chanmgr) ;
1002110020 let sender_intended_amt_msat = 100 ;
1002210021 let extra_fee_msat = 10 ;
10023- let hop_data = msgs:: OnionHopData {
10024- amt_to_forward : 100 ,
10022+ let hop_data = msgs:: InboundOnionPayload :: Receive {
10023+ amt_msat : 100 ,
1002510024 outgoing_cltv_value : 42 ,
10026- format : msgs:: OnionHopDataFormat :: FinalNode {
10027- keysend_preimage : None ,
10028- payment_metadata : None ,
10029- payment_data : Some ( msgs:: FinalOnionHopData {
10030- payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10031- } ) ,
10032- }
10025+ payment_metadata : None ,
10026+ keysend_preimage : None ,
10027+ payment_data : Some ( msgs:: FinalOnionHopData {
10028+ payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10029+ } ) ,
1003310030 } ;
1003410031 // Check that if the amount we received + the penultimate hop extra fee is less than the sender
1003510032 // intended amount, we fail the payment.
@@ -10041,16 +10038,14 @@ mod tests {
1004110038 } else { panic ! ( ) ; }
1004210039
1004310040 // If amt_received + extra_fee is equal to the sender intended amount, we're fine.
10044- let hop_data = msgs:: OnionHopData { // This is the same hop_data as above, OnionHopData doesn't implement Clone
10045- amt_to_forward : 100 ,
10041+ let hop_data = msgs:: InboundOnionPayload :: Receive { // This is the same payload as above, InboundOnionPayload doesn't implement Clone
10042+ amt_msat : 100 ,
1004610043 outgoing_cltv_value : 42 ,
10047- format : msgs:: OnionHopDataFormat :: FinalNode {
10048- keysend_preimage : None ,
10049- payment_metadata : None ,
10050- payment_data : Some ( msgs:: FinalOnionHopData {
10051- payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10052- } ) ,
10053- }
10044+ payment_metadata : None ,
10045+ keysend_preimage : None ,
10046+ payment_data : Some ( msgs:: FinalOnionHopData {
10047+ payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10048+ } ) ,
1005410049 } ;
1005510050 assert ! ( node[ 0 ] . node. construct_recv_pending_htlc_info( hop_data, [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) ,
1005610051 sender_intended_amt_msat - extra_fee_msat, 42 , None , true , Some ( extra_fee_msat) ) . is_ok( ) ) ;
0 commit comments