@@ -341,7 +341,7 @@ impl HTLCSource {
341
341
}
342
342
}
343
343
344
- struct ReceiveError {
344
+ struct InboundOnionErr {
345
345
err_code : u16 ,
346
346
err_data : Vec < u8 > ,
347
347
msg : & ' static str ,
@@ -2616,14 +2616,52 @@ where
2616
2616
}
2617
2617
}
2618
2618
2619
+ fn construct_fwd_pending_htlc_info (
2620
+ & self , msg : & msgs:: UpdateAddHTLC , hop_data : msgs:: OnionHopData , hop_hmac : [ u8 ; 32 ] ,
2621
+ new_packet_bytes : [ u8 ; onion_utils:: ONION_DATA_LEN ] , shared_secret : [ u8 ; 32 ] ,
2622
+ next_packet_pubkey_opt : Option < Result < PublicKey , secp256k1:: Error > >
2623
+ ) -> Result < PendingHTLCInfo , InboundOnionErr > {
2624
+ debug_assert ! ( next_packet_pubkey_opt. is_some( ) ) ;
2625
+ let outgoing_packet = msgs:: OnionPacket {
2626
+ version : 0 ,
2627
+ public_key : next_packet_pubkey_opt. unwrap_or ( Err ( secp256k1:: Error :: InvalidPublicKey ) ) ,
2628
+ hop_data : new_packet_bytes,
2629
+ hmac : hop_hmac. clone ( ) ,
2630
+ } ;
2631
+
2632
+ let short_channel_id = match hop_data. format {
2633
+ msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } => short_channel_id,
2634
+ msgs:: OnionHopDataFormat :: FinalNode { .. } => {
2635
+ return Err ( InboundOnionErr {
2636
+ msg : "Final Node OnionHopData provided for us as an intermediary node" ,
2637
+ err_code : 0x4000 | 22 ,
2638
+ err_data : Vec :: new ( ) ,
2639
+ } )
2640
+ } ,
2641
+ } ;
2642
+
2643
+ Ok ( PendingHTLCInfo {
2644
+ routing : PendingHTLCRouting :: Forward {
2645
+ onion_packet : outgoing_packet,
2646
+ short_channel_id,
2647
+ } ,
2648
+ payment_hash : msg. payment_hash . clone ( ) ,
2649
+ incoming_shared_secret : shared_secret,
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 ,
2653
+ skimmed_fee_msat : None ,
2654
+ } )
2655
+ }
2656
+
2619
2657
fn construct_recv_pending_htlc_info (
2620
2658
& self , hop_data : msgs:: OnionHopData , shared_secret : [ u8 ; 32 ] , payment_hash : PaymentHash ,
2621
2659
amt_msat : u64 , cltv_expiry : u32 , phantom_shared_secret : Option < [ u8 ; 32 ] > , allow_underpay : bool ,
2622
2660
counterparty_skimmed_fee_msat : Option < u64 > ,
2623
- ) -> Result < PendingHTLCInfo , ReceiveError > {
2661
+ ) -> Result < PendingHTLCInfo , InboundOnionErr > {
2624
2662
// final_incorrect_cltv_expiry
2625
2663
if hop_data. outgoing_cltv_value > cltv_expiry {
2626
- return Err ( ReceiveError {
2664
+ return Err ( InboundOnionErr {
2627
2665
msg : "Upstream node set CLTV to less than the CLTV set by the sender" ,
2628
2666
err_code : 18 ,
2629
2667
err_data : cltv_expiry. to_be_bytes ( ) . to_vec ( )
@@ -2641,7 +2679,7 @@ where
2641
2679
let mut err_data = Vec :: with_capacity ( 12 ) ;
2642
2680
err_data. extend_from_slice ( & amt_msat. to_be_bytes ( ) ) ;
2643
2681
err_data. extend_from_slice ( & current_height. to_be_bytes ( ) ) ;
2644
- return Err ( ReceiveError {
2682
+ return Err ( InboundOnionErr {
2645
2683
err_code : 0x4000 | 15 , err_data,
2646
2684
msg : "The final CLTV expiry is too soon to handle" ,
2647
2685
} ) ;
@@ -2650,7 +2688,7 @@ where
2650
2688
( allow_underpay && hop_data. amt_to_forward >
2651
2689
amt_msat. saturating_add ( counterparty_skimmed_fee_msat. unwrap_or ( 0 ) ) )
2652
2690
{
2653
- return Err ( ReceiveError {
2691
+ return Err ( InboundOnionErr {
2654
2692
err_code : 19 ,
2655
2693
err_data : amt_msat. to_be_bytes ( ) . to_vec ( ) ,
2656
2694
msg : "Upstream node sent less than we were supposed to receive in payment" ,
@@ -2659,7 +2697,7 @@ where
2659
2697
2660
2698
let routing = match hop_data. format {
2661
2699
msgs:: OnionHopDataFormat :: NonFinalNode { .. } => {
2662
- return Err ( ReceiveError {
2700
+ return Err ( InboundOnionErr {
2663
2701
err_code : 0x4000 |22 ,
2664
2702
err_data : Vec :: new ( ) ,
2665
2703
msg : "Got non final data with an HMAC of 0" ,
@@ -2674,14 +2712,14 @@ where
2674
2712
// time discrepancies due to a hash collision with X.
2675
2713
let hashed_preimage = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
2676
2714
if hashed_preimage != payment_hash {
2677
- return Err ( ReceiveError {
2715
+ return Err ( InboundOnionErr {
2678
2716
err_code : 0x4000 |22 ,
2679
2717
err_data : Vec :: new ( ) ,
2680
2718
msg : "Payment preimage didn't match payment hash" ,
2681
2719
} ) ;
2682
2720
}
2683
2721
if !self . default_configuration . accept_mpp_keysend && payment_data. is_some ( ) {
2684
- return Err ( ReceiveError {
2722
+ return Err ( InboundOnionErr {
2685
2723
err_code : 0x4000 |22 ,
2686
2724
err_data : Vec :: new ( ) ,
2687
2725
msg : "We don't support MPP keysend payments" ,
@@ -2701,7 +2739,7 @@ where
2701
2739
phantom_shared_secret,
2702
2740
}
2703
2741
} else {
2704
- return Err ( ReceiveError {
2742
+ return Err ( InboundOnionErr {
2705
2743
err_code : 0x4000 |0x2000 |3 ,
2706
2744
err_data : Vec :: new ( ) ,
2707
2745
msg : "We require payment_secrets" ,
@@ -2964,37 +3002,15 @@ where
2964
3002
// delay) once they've send us a commitment_signed!
2965
3003
PendingHTLCStatus :: Forward ( info)
2966
3004
} ,
2967
- Err ( ReceiveError { err_code, err_data, msg } ) => return_err ! ( msg, err_code, & err_data)
3005
+ Err ( InboundOnionErr { err_code, err_data, msg } ) => return_err ! ( msg, err_code, & err_data)
2968
3006
}
2969
3007
} ,
2970
3008
onion_utils:: Hop :: Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
2971
- debug_assert ! ( next_packet_pubkey_opt. is_some( ) ) ;
2972
- let outgoing_packet = msgs:: OnionPacket {
2973
- version : 0 ,
2974
- public_key : next_packet_pubkey_opt. unwrap_or ( Err ( secp256k1:: Error :: InvalidPublicKey ) ) ,
2975
- hop_data : new_packet_bytes,
2976
- hmac : next_hop_hmac. clone ( ) ,
2977
- } ;
2978
-
2979
- let short_channel_id = match next_hop_data. format {
2980
- msgs:: OnionHopDataFormat :: NonFinalNode { short_channel_id } => short_channel_id,
2981
- msgs:: OnionHopDataFormat :: FinalNode { .. } => {
2982
- return_err ! ( "Final Node OnionHopData provided for us as an intermediary node" , 0x4000 | 22 , & [ 0 ; 0 ] ) ;
2983
- } ,
2984
- } ;
2985
-
2986
- PendingHTLCStatus :: Forward ( PendingHTLCInfo {
2987
- routing : PendingHTLCRouting :: Forward {
2988
- onion_packet : outgoing_packet,
2989
- short_channel_id,
2990
- } ,
2991
- payment_hash : msg. payment_hash . clone ( ) ,
2992
- incoming_shared_secret : shared_secret,
2993
- incoming_amt_msat : Some ( msg. amount_msat ) ,
2994
- outgoing_amt_msat : next_hop_data. amt_to_forward ,
2995
- outgoing_cltv_value : next_hop_data. outgoing_cltv_value ,
2996
- skimmed_fee_msat : None ,
2997
- } )
3009
+ match self . construct_fwd_pending_htlc_info ( msg, next_hop_data, next_hop_hmac,
3010
+ new_packet_bytes, shared_secret, next_packet_pubkey_opt) {
3011
+ Ok ( info) => PendingHTLCStatus :: Forward ( info) ,
3012
+ Err ( InboundOnionErr { err_code, err_data, msg } ) => return_err ! ( msg, err_code, & err_data)
3013
+ }
2998
3014
}
2999
3015
}
3000
3016
}
@@ -3777,7 +3793,7 @@ where
3777
3793
outgoing_cltv_value, Some ( phantom_shared_secret) , false , None )
3778
3794
{
3779
3795
Ok ( info) => phantom_receives. push( ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id, vec![ ( info, prev_htlc_id) ] ) ) ,
3780
- Err ( ReceiveError { err_code, err_data, msg } ) => failed_payment!( msg, err_code, err_data, Some ( phantom_shared_secret) )
3796
+ Err ( InboundOnionErr { err_code, err_data, msg } ) => failed_payment!( msg, err_code, err_data, Some ( phantom_shared_secret) )
3781
3797
}
3782
3798
} ,
3783
3799
_ => panic!( ) ,
@@ -10018,7 +10034,7 @@ mod tests {
10018
10034
} ;
10019
10035
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
10020
10036
// intended amount, we fail the payment.
10021
- if let Err ( crate :: ln:: channelmanager:: ReceiveError { err_code, .. } ) =
10037
+ if let Err ( crate :: ln:: channelmanager:: InboundOnionErr { err_code, .. } ) =
10022
10038
node[ 0 ] . node . construct_recv_pending_htlc_info ( hop_data, [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) ,
10023
10039
sender_intended_amt_msat - extra_fee_msat - 1 , 42 , None , true , Some ( extra_fee_msat) )
10024
10040
{
0 commit comments