@@ -168,7 +168,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
168168} 
169169
170170pub ( super )  fn  compute_payinfo ( 
171- 	path :  & [ ( PublicKey ,  BlindedPaymentTlvs ) ] 
171+ 	path :  & [ ( PublicKey ,  BlindedPaymentTlvs ) ] ,   htlc_maximum_msat :   u64 , 
172172)  -> Result < BlindedPayInfo ,  ( ) >  { 
173173	let  mut  curr_base_fee:  u32  = 0 ; 
174174	let  mut  curr_prop_mil:  u32  = 0 ; 
@@ -195,14 +195,15 @@ pub(super) fn compute_payinfo(
195195			. map ( |f| f / 1_000_000 ) 
196196			. ok_or ( ( ) ) ?; 
197197	} 
198+ 	let  htlc_minimum_msat = path. iter ( ) . map ( |( _,  tlvs) | tlvs. htlc_minimum_msat ( ) ) . max ( ) . unwrap_or ( 0 ) ; 
199+ 	if  htlc_maximum_msat < htlc_minimum_msat {  return  Err ( ( ) )  } 
198200	Ok ( BlindedPayInfo  { 
199201		fee_base_msat :  curr_base_fee, 
200202		fee_proportional_millionths :  curr_prop_mil, 
201203		cltv_expiry_delta :  path. iter ( ) . map ( |( _,  tlvs) | tlvs. cltv_expiry_delta ( ) ) 
202204			. try_fold ( 0u16 ,  |acc,  delta| acc. checked_add ( delta) ) . ok_or ( ( ) ) ?, 
203- 		htlc_minimum_msat :  path. iter ( ) . map ( |( _,  tlvs) | tlvs. htlc_minimum_msat ( ) ) . max ( ) . unwrap_or ( 0 ) , 
204- 		// TODO: this field isn't present in route blinding encrypted data 
205- 		htlc_maximum_msat :  21_000_000  *  100_000_000  *  1_000 ,  // Total bitcoin supply 
205+ 		htlc_minimum_msat, 
206+ 		htlc_maximum_msat, 
206207		features :  BlindedHopFeatures :: empty ( ) , 
207208	} ) 
208209} 
@@ -264,11 +265,12 @@ mod tests {
264265				htlc_minimum_msat:  1 , 
265266			} , 
266267		} ) ] ; 
267- 		let  blinded_payinfo = super :: compute_payinfo ( & path[ ..] ) . unwrap ( ) ; 
268+ 		let  blinded_payinfo = super :: compute_payinfo ( & path[ ..] ,   4242 ) . unwrap ( ) ; 
268269		assert_eq ! ( blinded_payinfo. fee_base_msat,  201 ) ; 
269270		assert_eq ! ( blinded_payinfo. fee_proportional_millionths,  1001 ) ; 
270271		assert_eq ! ( blinded_payinfo. cltv_expiry_delta,  288 ) ; 
271272		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  1_000 ) ; 
273+ 		assert_eq ! ( blinded_payinfo. htlc_maximum_msat,  4242 ) ; 
272274	} 
273275
274276	#[ test]  
@@ -281,7 +283,7 @@ mod tests {
281283				htlc_minimum_msat:  1 , 
282284			} , 
283285		} ) ] ; 
284- 		let  blinded_payinfo = super :: compute_payinfo ( & path[ ..] ) . unwrap ( ) ; 
286+ 		let  blinded_payinfo = super :: compute_payinfo ( & path[ ..] ,   42 ) . unwrap ( ) ; 
285287		assert_eq ! ( blinded_payinfo. fee_base_msat,  0 ) ; 
286288		assert_eq ! ( blinded_payinfo. fee_proportional_millionths,  0 ) ; 
287289		assert_eq ! ( blinded_payinfo. cltv_expiry_delta,  0 ) ; 
@@ -313,7 +315,7 @@ mod tests {
313315			} , 
314316			features:  BlindedHopFeatures :: empty( ) , 
315317		} ) ] ; 
316- 		assert ! ( BlindedPath :: new_for_payment( & out_of_order_payloads_path[ ..] ,  & keys_manager,  & secp_ctx) . is_err( ) ) ; 
318+ 		assert ! ( BlindedPath :: new_for_payment( & out_of_order_payloads_path[ ..] ,  1_000_000 ,   & keys_manager,  & secp_ctx) . is_err( ) ) ; 
317319
318320		let  multiple_recv_payloads_path = vec ! [ ( dummy_pk,  BlindedPaymentTlvs :: Receive  { 
319321			payment_secret:  PaymentSecret ( [ 0 ;  32 ] ) , 
@@ -328,7 +330,7 @@ mod tests {
328330				htlc_minimum_msat:  1 , 
329331			} , 
330332		} ) ] ; 
331- 		assert ! ( BlindedPath :: new_for_payment( & multiple_recv_payloads_path[ ..] ,  & keys_manager,  & secp_ctx) . is_err( ) ) ; 
333+ 		assert ! ( BlindedPath :: new_for_payment( & multiple_recv_payloads_path[ ..] ,  1_000_000 ,   & keys_manager,  & secp_ctx) . is_err( ) ) ; 
332334
333335		let  missing_recv_payload_path = vec ! [ ( dummy_pk,  BlindedPaymentTlvs :: Forward  { 
334336			short_channel_id:  0 , 
@@ -343,6 +345,6 @@ mod tests {
343345			} , 
344346			features:  BlindedHopFeatures :: empty( ) , 
345347		} ) ] ; 
346- 		assert ! ( BlindedPath :: new_for_payment( & missing_recv_payload_path[ ..] ,  & keys_manager,  & secp_ctx) . is_err( ) ) ; 
348+ 		assert ! ( BlindedPath :: new_for_payment( & missing_recv_payload_path[ ..] ,  1_000_000 ,   & keys_manager,  & secp_ctx) . is_err( ) ) ; 
347349	} 
348350} 
0 commit comments