@@ -2659,6 +2659,16 @@ where
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) ,
2665
+ _ =>
2666
+ return Err ( InboundOnionErr {
2667
+ err_code : 0x4000 |22 ,
2668
+ err_data : Vec :: new ( ) ,
2669
+ msg : "Got non final data with an HMAC of 0" ,
2670
+ } ) ,
2671
+ } ;
2662
2672
// final_incorrect_cltv_expiry
2663
2673
if hop_data. outgoing_cltv_value > cltv_expiry {
2664
2674
return Err ( InboundOnionErr {
@@ -2695,57 +2705,46 @@ where
2695
2705
} ) ;
2696
2706
}
2697
2707
2698
- let routing = match hop_data. format {
2699
- msgs:: OnionHopDataFormat :: NonFinalNode { .. } => {
2708
+ let routing = if let Some ( payment_preimage) = keysend_preimage {
2709
+ // We need to check that the sender knows the keysend preimage before processing this
2710
+ // payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
2711
+ // could discover the final destination of X, by probing the adjacent nodes on the route
2712
+ // with a keysend payment of identical payment hash to X and observing the processing
2713
+ // time discrepancies due to a hash collision with X.
2714
+ let hashed_preimage = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
2715
+ if hashed_preimage != payment_hash {
2700
2716
return Err ( InboundOnionErr {
2701
2717
err_code : 0x4000 |22 ,
2702
2718
err_data : Vec :: new ( ) ,
2703
- msg : "Got non final data with an HMAC of 0 " ,
2719
+ msg : "Payment preimage didn't match payment hash " ,
2704
2720
} ) ;
2705
- } ,
2706
- msgs:: OnionHopDataFormat :: FinalNode { payment_data, keysend_preimage, payment_metadata } => {
2707
- if let Some ( payment_preimage) = keysend_preimage {
2708
- // We need to check that the sender knows the keysend preimage before processing this
2709
- // payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
2710
- // could discover the final destination of X, by probing the adjacent nodes on the route
2711
- // with a keysend payment of identical payment hash to X and observing the processing
2712
- // time discrepancies due to a hash collision with X.
2713
- let hashed_preimage = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
2714
- if hashed_preimage != payment_hash {
2715
- return Err ( InboundOnionErr {
2716
- err_code : 0x4000 |22 ,
2717
- err_data : Vec :: new ( ) ,
2718
- msg : "Payment preimage didn't match payment hash" ,
2719
- } ) ;
2720
- }
2721
- if !self . default_configuration . accept_mpp_keysend && payment_data. is_some ( ) {
2722
- return Err ( InboundOnionErr {
2723
- err_code : 0x4000 |22 ,
2724
- err_data : Vec :: new ( ) ,
2725
- msg : "We don't support MPP keysend payments" ,
2726
- } ) ;
2727
- }
2728
- PendingHTLCRouting :: ReceiveKeysend {
2729
- payment_data,
2730
- payment_preimage,
2731
- payment_metadata,
2732
- incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2733
- }
2734
- } else if let Some ( data) = payment_data {
2735
- PendingHTLCRouting :: Receive {
2736
- payment_data : data,
2737
- payment_metadata,
2738
- incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2739
- phantom_shared_secret,
2740
- }
2741
- } else {
2742
- return Err ( InboundOnionErr {
2743
- err_code : 0x4000 |0x2000 |3 ,
2744
- err_data : Vec :: new ( ) ,
2745
- msg : "We require payment_secrets" ,
2746
- } ) ;
2747
- }
2748
- } ,
2721
+ }
2722
+ if !self . default_configuration . accept_mpp_keysend && payment_data. is_some ( ) {
2723
+ return Err ( InboundOnionErr {
2724
+ err_code : 0x4000 |22 ,
2725
+ err_data : Vec :: new ( ) ,
2726
+ msg : "We don't support MPP keysend payments" ,
2727
+ } ) ;
2728
+ }
2729
+ PendingHTLCRouting :: ReceiveKeysend {
2730
+ payment_data,
2731
+ payment_preimage,
2732
+ payment_metadata,
2733
+ incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2734
+ }
2735
+ } else if let Some ( data) = payment_data {
2736
+ PendingHTLCRouting :: Receive {
2737
+ payment_data : data,
2738
+ payment_metadata,
2739
+ incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2740
+ phantom_shared_secret,
2741
+ }
2742
+ } else {
2743
+ return Err ( InboundOnionErr {
2744
+ err_code : 0x4000 |0x2000 |3 ,
2745
+ err_data : Vec :: new ( ) ,
2746
+ msg : "We require payment_secrets" ,
2747
+ } ) ;
2749
2748
} ;
2750
2749
Ok ( PendingHTLCInfo {
2751
2750
routing,
0 commit comments