@@ -154,7 +154,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
154154}
155155
156156pub ( super ) fn compute_payinfo (
157- intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs
157+ intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs , htlc_maximum_msat : u64
158158) -> Result < BlindedPayInfo , ( ) > {
159159 let mut curr_base_fee: u128 = 0 ;
160160 let mut curr_prop_mil: u128 = 0 ;
@@ -211,12 +211,13 @@ pub(super) fn compute_payinfo(
211211 htlc_minimum_msat =
212212 core:: cmp:: max ( payee_tlvs. payment_constraints . htlc_minimum_msat as u128 , htlc_minimum_msat) ;
213213
214+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
214215 Ok ( BlindedPayInfo {
215216 fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
216217 fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
217218 cltv_expiry_delta,
218219 htlc_minimum_msat : u64:: try_from ( htlc_minimum_msat) . map_err ( |_| ( ) ) ?,
219- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
220+ htlc_maximum_msat,
220221 features : BlindedHopFeatures :: empty ( ) ,
221222 } )
222223}
@@ -276,11 +277,13 @@ mod tests {
276277 htlc_minimum_msat : 1 ,
277278 } ,
278279 } ;
279- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
280+ let htlc_maximum_msat = 100_000 ;
281+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
280282 assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
281283 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
282284 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
283285 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 900 ) ;
286+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
284287 }
285288
286289 #[ test]
@@ -292,11 +295,12 @@ mod tests {
292295 htlc_minimum_msat : 1 ,
293296 } ,
294297 } ;
295- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
298+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
296299 assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
297300 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
298301 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
299302 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
303+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
300304 }
301305
302306 #[ test]
@@ -336,7 +340,8 @@ mod tests {
336340 htlc_minimum_msat : 3 ,
337341 } ,
338342 } ;
339- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
343+ let htlc_maximum_msat = 100_000 ;
344+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
340345 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
341346 }
342347
@@ -377,8 +382,12 @@ mod tests {
377382 htlc_minimum_msat : 1 ,
378383 } ,
379384 } ;
385+ let htlc_minimum_msat = 3797 ;
386+ assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 ) . is_err( ) ) ;
380387
381- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
382- assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 3797 ) ;
388+ let htlc_maximum_msat = htlc_minimum_msat + 1 ;
389+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
390+ assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
391+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
383392 }
384393}
0 commit comments