@@ -2659,6 +2659,16 @@ where
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) ,
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+ } ;
26622672 // final_incorrect_cltv_expiry
26632673 if hop_data. outgoing_cltv_value > cltv_expiry {
26642674 return Err ( InboundOnionErr {
@@ -2695,57 +2705,46 @@ where
26952705 } ) ;
26962706 }
26972707
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 {
27002716 return Err ( InboundOnionErr {
27012717 err_code : 0x4000 |22 ,
27022718 err_data : Vec :: new ( ) ,
2703- msg : "Got non final data with an HMAC of 0 " ,
2719+ msg : "Payment preimage didn't match payment hash " ,
27042720 } ) ;
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+ } ) ;
27492748 } ;
27502749 Ok ( PendingHTLCInfo {
27512750 routing,
0 commit comments