@@ -2617,7 +2617,7 @@ where
2617
2617
}
2618
2618
2619
2619
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:: InboundPayload , hop_hmac : [ u8 ; 32 ] ,
2621
2621
new_packet_bytes : [ u8 ; onion_utils:: ONION_DATA_LEN ] , shared_secret : [ u8 ; 32 ] ,
2622
2622
next_packet_pubkey_opt : Option < Result < PublicKey , secp256k1:: Error > >
2623
2623
) -> Result < PendingHTLCInfo , InboundOnionErr > {
@@ -2626,42 +2626,44 @@ where
2626
2626
version : 0 ,
2627
2627
public_key : next_packet_pubkey_opt. unwrap_or ( Err ( secp256k1:: Error :: InvalidPublicKey ) ) ,
2628
2628
hop_data : new_packet_bytes,
2629
- hmac : hop_hmac. clone ( ) ,
2629
+ hmac : hop_hmac,
2630
2630
} ;
2631
2631
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:: InboundPayload :: Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
2634
+ ( short_channel_id, amt_to_forward, outgoing_cltv_value) ,
2635
+ msgs:: InboundPayload :: Receive { .. } =>
2635
2636
return Err ( InboundOnionErr {
2636
2637
msg : "Final Node OnionHopData provided for us as an intermediary node" ,
2637
2638
err_code : 0x4000 | 22 ,
2638
2639
err_data : Vec :: new ( ) ,
2639
- } )
2640
- } ,
2640
+ } ) ,
2641
2641
} ;
2642
2642
2643
2643
Ok ( PendingHTLCInfo {
2644
2644
routing : PendingHTLCRouting :: Forward {
2645
2645
onion_packet : outgoing_packet,
2646
2646
short_channel_id,
2647
2647
} ,
2648
- payment_hash : msg. payment_hash . clone ( ) ,
2648
+ payment_hash : msg. payment_hash ,
2649
2649
incoming_shared_secret : shared_secret,
2650
2650
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,
2653
2653
skimmed_fee_msat : None ,
2654
2654
} )
2655
2655
}
2656
2656
2657
2657
fn construct_recv_pending_htlc_info (
2658
- & self , hop_data : msgs:: OnionHopData , shared_secret : [ u8 ; 32 ] , payment_hash : PaymentHash ,
2658
+ & self , hop_data : msgs:: InboundPayload , shared_secret : [ u8 ; 32 ] , payment_hash : PaymentHash ,
2659
2659
amt_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > , allow_underpay : bool ,
2660
2660
counterparty_skimmed_fee_msat : Option < u64 > ,
2661
2661
) -> 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:: InboundPayload :: 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) ,
2665
2667
_ =>
2666
2668
return Err ( InboundOnionErr {
2667
2669
err_code : 0x4000 |22 ,
@@ -2670,7 +2672,7 @@ where
2670
2672
} ) ,
2671
2673
} ;
2672
2674
// final_incorrect_cltv_expiry
2673
- if hop_data . outgoing_cltv_value > cltv_expiry {
2675
+ if outgoing_cltv_value > cltv_expiry {
2674
2676
return Err ( InboundOnionErr {
2675
2677
msg : "Upstream node set CLTV to less than the CLTV set by the sender" ,
2676
2678
err_code : 18 ,
@@ -2685,7 +2687,7 @@ where
2685
2687
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
2686
2688
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
2687
2689
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 {
2689
2691
let mut err_data = Vec :: with_capacity ( 12 ) ;
2690
2692
err_data. extend_from_slice ( & amt_msat. to_be_bytes ( ) ) ;
2691
2693
err_data. extend_from_slice ( & current_height. to_be_bytes ( ) ) ;
@@ -2694,8 +2696,8 @@ where
2694
2696
msg : "The final CLTV expiry is too soon to handle" ,
2695
2697
} ) ;
2696
2698
}
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 >
2699
2701
amt_msat. saturating_add ( counterparty_skimmed_fee_msat. unwrap_or ( 0 ) ) )
2700
2702
{
2701
2703
return Err ( InboundOnionErr {
@@ -2731,13 +2733,13 @@ where
2731
2733
payment_data,
2732
2734
payment_preimage,
2733
2735
payment_metadata,
2734
- incoming_cltv_expiry : hop_data . outgoing_cltv_value ,
2736
+ incoming_cltv_expiry : outgoing_cltv_value,
2735
2737
}
2736
2738
} else if let Some ( data) = payment_data {
2737
2739
routing = PendingHTLCRouting :: Receive {
2738
2740
payment_data : data,
2739
2741
payment_metadata,
2740
- incoming_cltv_expiry : hop_data . outgoing_cltv_value ,
2742
+ incoming_cltv_expiry : outgoing_cltv_value,
2741
2743
phantom_shared_secret,
2742
2744
}
2743
2745
} else {
@@ -2752,8 +2754,8 @@ where
2752
2754
payment_hash,
2753
2755
incoming_shared_secret : shared_secret,
2754
2756
incoming_amt_msat : Some ( amt_msat) ,
2755
- outgoing_amt_msat : hop_data . amt_to_forward ,
2756
- outgoing_cltv_value : hop_data . outgoing_cltv_value ,
2757
+ outgoing_amt_msat : onion_amt_msat ,
2758
+ outgoing_cltv_value,
2757
2759
skimmed_fee_msat : counterparty_skimmed_fee_msat,
2758
2760
} )
2759
2761
}
@@ -2817,9 +2819,8 @@ where
2817
2819
} ;
2818
2820
let ( outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt) = match next_hop {
2819
2821
onion_utils:: Hop :: Forward {
2820
- next_hop_data : msgs:: OnionHopData {
2821
- format : msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } , amt_to_forward,
2822
- outgoing_cltv_value,
2822
+ next_hop_data : msgs:: InboundPayload :: Forward {
2823
+ short_channel_id, amt_to_forward, outgoing_cltv_value
2823
2824
} , ..
2824
2825
} => {
2825
2826
let next_pk = onion_utils:: next_hop_packet_pubkey ( & self . secp_ctx ,
@@ -2829,9 +2830,7 @@ where
2829
2830
// We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
2830
2831
// inbound channel's state.
2831
2832
onion_utils:: Hop :: Receive { .. } => return Ok ( ( next_hop, shared_secret, None ) ) ,
2832
- onion_utils:: Hop :: Forward {
2833
- next_hop_data : msgs:: OnionHopData { format : msgs:: OnionHopDataFormat :: FinalNode { .. } , .. } , ..
2834
- } => {
2833
+ onion_utils:: Hop :: Forward { next_hop_data : msgs:: InboundPayload :: Receive { .. } , .. } => {
2835
2834
return_err ! ( "Final Node OnionHopData provided for us as an intermediary node" , 0x4000 | 22 , & [ 0 ; 0 ] ) ;
2836
2835
}
2837
2836
} ;
@@ -10021,16 +10020,14 @@ mod tests {
10021
10020
let node = create_network ( 1 , & node_cfg, & node_chanmgr) ;
10022
10021
let sender_intended_amt_msat = 100 ;
10023
10022
let extra_fee_msat = 10 ;
10024
- let hop_data = msgs:: OnionHopData {
10025
- amt_to_forward : 100 ,
10023
+ let hop_data = msgs:: InboundPayload :: Receive {
10024
+ amt_msat : 100 ,
10026
10025
outgoing_cltv_value : 42 ,
10027
- format : msgs:: OnionHopDataFormat :: FinalNode {
10028
- keysend_preimage : None ,
10029
- payment_metadata : None ,
10030
- payment_data : Some ( msgs:: FinalOnionHopData {
10031
- payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10032
- } ) ,
10033
- }
10026
+ payment_metadata : None ,
10027
+ keysend_preimage : None ,
10028
+ payment_data : Some ( msgs:: FinalOnionHopData {
10029
+ payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10030
+ } ) ,
10034
10031
} ;
10035
10032
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
10036
10033
// intended amount, we fail the payment.
@@ -10042,16 +10039,14 @@ mod tests {
10042
10039
} else { panic ! ( ) ; }
10043
10040
10044
10041
// If amt_received + extra_fee is equal to the sender intended amount, we're fine.
10045
- let hop_data = msgs:: OnionHopData { // This is the same hop_data as above, OnionHopData doesn't implement Clone
10046
- amt_to_forward : 100 ,
10042
+ let hop_data = msgs:: InboundPayload :: Receive { // This is the same payload as above, InboundPayload doesn't implement Clone
10043
+ amt_msat : 100 ,
10047
10044
outgoing_cltv_value : 42 ,
10048
- format : msgs:: OnionHopDataFormat :: FinalNode {
10049
- keysend_preimage : None ,
10050
- payment_metadata : None ,
10051
- payment_data : Some ( msgs:: FinalOnionHopData {
10052
- payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10053
- } ) ,
10054
- }
10045
+ payment_metadata : None ,
10046
+ keysend_preimage : None ,
10047
+ payment_data : Some ( msgs:: FinalOnionHopData {
10048
+ payment_secret : PaymentSecret ( [ 0 ; 32 ] ) , total_msat : sender_intended_amt_msat,
10049
+ } ) ,
10055
10050
} ;
10056
10051
assert ! ( node[ 0 ] . node. construct_recv_pending_htlc_info( hop_data, [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) ,
10057
10052
sender_intended_amt_msat - extra_fee_msat, 42 , None , true , Some ( extra_fee_msat) ) . is_ok( ) ) ;
0 commit comments