@@ -152,7 +152,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
152152} 
153153
154154pub ( super )  fn  compute_payinfo ( 
155- 	intermediate_nodes :  & [ ( PublicKey ,  ForwardTlvs ) ] ,  payee_tlvs :  & ReceiveTlvs 
155+ 	intermediate_nodes :  & [ ( PublicKey ,  ForwardTlvs ) ] ,  payee_tlvs :  & ReceiveTlvs ,   htlc_maximum_msat :   u64 
156156)  -> Result < BlindedPayInfo ,  ( ) >  { 
157157	let  mut  curr_base_fee:  u128  = 0 ; 
158158	let  mut  curr_prop_mil:  u128  = 0 ; 
@@ -209,12 +209,13 @@ pub(super) fn compute_payinfo(
209209	htlc_minimum_msat =
210210		core:: cmp:: max ( payee_tlvs. payment_constraints . htlc_minimum_msat  as  u128 ,  htlc_minimum_msat) ; 
211211
212+ 	if  ( htlc_maximum_msat as  u128 )  < htlc_minimum_msat {  return  Err ( ( ) )  } 
212213	Ok ( BlindedPayInfo  { 
213214		fee_base_msat :  u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?, 
214215		fee_proportional_millionths :  u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?, 
215216		cltv_expiry_delta, 
216217		htlc_minimum_msat :  u64:: try_from ( htlc_minimum_msat) . map_err ( |_| ( ) ) ?, 
217- 		htlc_maximum_msat :   21_000_000   *   100_000_000   *   1_000 ,   // TODO 
218+ 		htlc_maximum_msat, 
218219		features :  BlindedHopFeatures :: empty ( ) , 
219220	} ) 
220221} 
@@ -274,11 +275,13 @@ mod tests {
274275				htlc_minimum_msat :  1 , 
275276			} , 
276277		} ; 
277- 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs) . unwrap ( ) ; 
278+ 		let  htlc_maximum_msat = 100_000 ; 
279+ 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs,  htlc_maximum_msat) . unwrap ( ) ; 
278280		assert_eq ! ( blinded_payinfo. fee_base_msat,  201 ) ; 
279281		assert_eq ! ( blinded_payinfo. fee_proportional_millionths,  1001 ) ; 
280282		assert_eq ! ( blinded_payinfo. cltv_expiry_delta,  288 ) ; 
281283		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  900 ) ; 
284+ 		assert_eq ! ( blinded_payinfo. htlc_maximum_msat,  htlc_maximum_msat) ; 
282285	} 
283286
284287	#[ test]  
@@ -290,11 +293,12 @@ mod tests {
290293				htlc_minimum_msat :  1 , 
291294			} , 
292295		} ; 
293- 		let  blinded_payinfo = super :: compute_payinfo ( & [ ] ,  & recv_tlvs) . unwrap ( ) ; 
296+ 		let  blinded_payinfo = super :: compute_payinfo ( & [ ] ,  & recv_tlvs,   4242 ) . unwrap ( ) ; 
294297		assert_eq ! ( blinded_payinfo. fee_base_msat,  0 ) ; 
295298		assert_eq ! ( blinded_payinfo. fee_proportional_millionths,  0 ) ; 
296299		assert_eq ! ( blinded_payinfo. cltv_expiry_delta,  0 ) ; 
297300		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  1 ) ; 
301+ 		assert_eq ! ( blinded_payinfo. htlc_maximum_msat,  4242 ) ; 
298302	} 
299303
300304	#[ test]  
@@ -334,7 +338,8 @@ mod tests {
334338				htlc_minimum_msat :  3 , 
335339			} , 
336340		} ; 
337- 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs) . unwrap ( ) ; 
341+ 		let  htlc_maximum_msat = 100_000 ; 
342+ 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs,  htlc_maximum_msat) . unwrap ( ) ; 
338343		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  2_000 ) ; 
339344	} 
340345
@@ -375,8 +380,12 @@ mod tests {
375380				htlc_minimum_msat :  1 , 
376381			} , 
377382		} ; 
383+ 		let  htlc_minimum_msat = 3797 ; 
384+ 		assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] ,  & recv_tlvs,  htlc_minimum_msat - 1 ) . is_err( ) ) ; 
378385
379- 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs) . unwrap ( ) ; 
380- 		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  3797 ) ; 
386+ 		let  htlc_maximum_msat = htlc_minimum_msat + 1 ; 
387+ 		let  blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] ,  & recv_tlvs,  htlc_maximum_msat) . unwrap ( ) ; 
388+ 		assert_eq ! ( blinded_payinfo. htlc_minimum_msat,  htlc_minimum_msat) ; 
389+ 		assert_eq ! ( blinded_payinfo. htlc_maximum_msat,  htlc_maximum_msat) ; 
381390	} 
382391} 
0 commit comments