@@ -540,17 +540,6 @@ async fn on_htlc_accepted(
540540 "htlc is a forward, continue"
541541 ) ;
542542
543- let extra_fee_msat = req
544- . htlc
545- . extra_tlvs
546- . as_ref ( )
547- . map ( |tlvs| tlvs. get_u64 ( 65537 ) )
548- . transpose ( ) ?
549- . flatten ( ) ;
550- if let Some ( amt) = extra_fee_msat {
551- debug ! ( "lsp htlc is deducted by an extra_fee={amt}" ) ;
552- }
553-
554543 // Check that the htlc belongs to a jit-channel request.
555544 let dir = p. configuration ( ) . lightning_dir ;
556545 let rpc_path = Path :: new ( & dir) . join ( & p. configuration ( ) . rpc_file ) ;
@@ -572,12 +561,31 @@ async fn on_htlc_accepted(
572561 // If we don't know about this payment it's not an LSP payment, continue.
573562 some_or_continue ! ( lsp_data. datastore. first( ) ) ;
574563
564+ let extra_fee_msat = req
565+ . htlc
566+ . extra_tlvs
567+ . as_ref ( )
568+ . map ( |tlvs| tlvs. get_u64 ( 65537 ) )
569+ . transpose ( ) ?
570+ . flatten ( )
571+ . unwrap_or_default ( ) ;
572+
575573 debug ! (
576- "incoming jit-channel htlc with htlc_amt={} and onion_amt ={}" ,
574+ "incoming jit-channel htlc with htlc_amt={}, onion_amt={} and extra_fee ={}" ,
577575 htlc_amt. msat( ) ,
578- onion_amt. msat( )
576+ onion_amt. msat( ) ,
577+ extra_fee_msat
579578 ) ;
580579
580+ if htlc_amt. msat ( ) + extra_fee_msat != onion_amt. msat ( ) {
581+ warn ! (
582+ "amounts don't match (htlc_amt + extra_fee) = {} != onion_amt = {}" ,
583+ ( htlc_amt. msat( ) + extra_fee_msat) ,
584+ onion_amt. msat( )
585+ ) ;
586+ // FIXME: If we are strict, we should reject the htlc here.
587+ }
588+
581589 let inv_res = ok_or_continue ! ( cln_client
582590 . call_typed( & ListinvoicesRequest {
583591 index: None ,
@@ -597,22 +605,7 @@ async fn on_htlc_accepted(
597605 hex:: encode( & req. htlc. payment_hash)
598606 ) ;
599607
600- let total_amt = match invoice. amount_msat {
601- Some ( a) => {
602- debug ! ( "invoice has total_amt={}msat" , & a. msat( ) ) ;
603- a. msat ( )
604- }
605- None => {
606- debug ! ( "invoice has no total amount, only accept single htlc" ) ;
607- htlc_amt. msat ( )
608- }
609- } ;
610-
611- // Fixme: Check that we did not already pay for this channel.
612- // - via datastore or invoice label.
613-
614- // Fixme: Check the if MPP or No-MPP, assuming No-MPP for now.
615- // - check that extra_fee + htlc is the total_amount_msat of the onion.
608+ let total_amt = invoice. amount_msat . unwrap_or ( htlc_amt) . msat ( ) ;
616609
617610 let mut payload = req. onion . payload . clone ( ) ;
618611 payload. set_tu64 ( TLV_FORWARD_AMT , htlc_amt. msat ( ) ) ;
0 commit comments