@@ -16,7 +16,7 @@ use crate::ln::channelmanager::{BlindedFailure, BlindedForward, CLTV_FAR_FAR_AWA
1616use crate :: types:: features:: BlindedHopFeatures ;
1717use crate :: ln:: msgs;
1818use crate :: ln:: onion_utils;
19- use crate :: ln:: onion_utils:: { HTLCFailReason , INVALID_ONION_BLINDING } ;
19+ use crate :: ln:: onion_utils:: { Hop , HTLCFailReason , INVALID_ONION_BLINDING } ;
2020use crate :: sign:: { NodeSigner , Recipient } ;
2121use crate :: util:: logger:: Logger ;
2222
@@ -323,13 +323,50 @@ where
323323 // onion here and check it.
324324
325325 create_fwd_pending_htlc_info (
326- msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret,
326+ msg, msgs:: InboundOnionPayload :: Forward ( next_hop_data) , next_hop_hmac, new_packet_bytes, shared_secret,
327+ Some ( next_packet_pubkey)
328+ ) ?
329+ } ,
330+ onion_utils:: Hop :: BlindedForward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
331+ let NextPacketDetails {
332+ next_packet_pubkey, outgoing_amt_msat : _, outgoing_scid : _, outgoing_cltv_value
333+ } = match next_packet_details_opt {
334+ Some ( next_packet_details) => next_packet_details,
335+ // Forward should always include the next hop details
336+ None => return Err ( InboundHTLCErr {
337+ msg : "Failed to decode update add htlc onion" ,
338+ err_code : 0x4000 | 22 ,
339+ err_data : Vec :: new ( ) ,
340+ } ) ,
341+ } ;
342+
343+ if let Err ( ( err_msg, code) ) = check_incoming_htlc_cltv (
344+ cur_height, outgoing_cltv_value, msg. cltv_expiry
345+ ) {
346+ return Err ( InboundHTLCErr {
347+ msg : err_msg,
348+ err_code : code,
349+ err_data : Vec :: new ( ) ,
350+ } ) ;
351+ }
352+
353+ // TODO: If this is potentially a phantom payment we should decode the phantom payment
354+ // onion here and check it.
355+
356+ create_fwd_pending_htlc_info (
357+ msg, msgs:: InboundOnionPayload :: BlindedForward ( next_hop_data) , next_hop_hmac, new_packet_bytes, shared_secret,
327358 Some ( next_packet_pubkey)
328359 ) ?
329360 } ,
330361 onion_utils:: Hop :: Receive ( received_data) => {
331362 create_recv_pending_htlc_info (
332- received_data, shared_secret, msg. payment_hash , msg. amount_msat , msg. cltv_expiry ,
363+ msgs:: InboundOnionPayload :: Receive ( received_data) , shared_secret, msg. payment_hash , msg. amount_msat , msg. cltv_expiry ,
364+ None , allow_skimmed_fees, msg. skimmed_fee_msat , cur_height
365+ ) ?
366+ } ,
367+ onion_utils:: Hop :: BlindedReceive ( received_data) => {
368+ create_recv_pending_htlc_info (
369+ msgs:: InboundOnionPayload :: BlindedReceive ( received_data) , shared_secret, msg. payment_hash , msg. amount_msat , msg. cltv_expiry ,
333370 None , allow_skimmed_fees, msg. skimmed_fee_msat , cur_height
334371 ) ?
335372 }
@@ -424,23 +461,15 @@ where
424461 } ;
425462
426463 let next_packet_details = match next_hop {
427- onion_utils:: Hop :: Forward {
428- next_hop_data : msgs:: InboundOnionPayload :: Forward ( msgs:: InboundOnionForwardPayload {
429- short_channel_id, amt_to_forward, outgoing_cltv_value
430- } ) , ..
431- } => {
464+ Hop :: Forward { next_hop_data : msgs:: InboundOnionForwardPayload { short_channel_id, amt_to_forward, outgoing_cltv_value } , .. } => {
432465 let next_packet_pubkey = onion_utils:: next_hop_pubkey ( secp_ctx,
433466 msg. onion_routing_packet . public_key . unwrap ( ) , & shared_secret) ;
434- NextPacketDetails {
467+ Some ( NextPacketDetails {
435468 next_packet_pubkey, outgoing_scid : short_channel_id,
436469 outgoing_amt_msat : amt_to_forward, outgoing_cltv_value
437- }
438- } ,
439- onion_utils:: Hop :: Forward {
440- next_hop_data : msgs:: InboundOnionPayload :: BlindedForward ( msgs:: InboundOnionBlindedForwardPayload {
441- short_channel_id, ref payment_relay, ref payment_constraints, ref features, ..
442- } ) , ..
443- } => {
470+ } )
471+ }
472+ Hop :: BlindedForward { next_hop_data : msgs:: InboundOnionBlindedForwardPayload { short_channel_id, ref payment_relay, ref payment_constraints, ref features, .. } , .. } => {
444473 let ( amt_to_forward, outgoing_cltv_value) = match check_blinded_forward (
445474 msg. amount_msat , msg. cltv_expiry , & payment_relay, & payment_constraints, & features
446475 ) {
@@ -452,20 +481,15 @@ where
452481 } ;
453482 let next_packet_pubkey = onion_utils:: next_hop_pubkey ( & secp_ctx,
454483 msg. onion_routing_packet . public_key . unwrap ( ) , & shared_secret) ;
455- NextPacketDetails {
484+ Some ( NextPacketDetails {
456485 next_packet_pubkey, outgoing_scid : short_channel_id, outgoing_amt_msat : amt_to_forward,
457486 outgoing_cltv_value
458- }
459- } ,
460- onion_utils:: Hop :: Receive { .. } => return Ok ( ( next_hop, shared_secret, None ) ) ,
461- onion_utils:: Hop :: Forward { next_hop_data : msgs:: InboundOnionPayload :: Receive { .. } , .. } |
462- onion_utils:: Hop :: Forward { next_hop_data : msgs:: InboundOnionPayload :: BlindedReceive { .. } , .. } =>
463- {
464- return_err ! ( "Final Node OnionHopData provided for us as an intermediary node" , 0x4000 | 22 , & [ 0 ; 0 ] ) ;
487+ } )
465488 }
489+ _ => None
466490 } ;
467491
468- Ok ( ( next_hop, shared_secret, Some ( next_packet_details) ) )
492+ Ok ( ( next_hop, shared_secret, next_packet_details) )
469493}
470494
471495pub ( super ) fn check_incoming_htlc_cltv (
0 commit comments