@@ -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: u64 = 0 ;
160160 let mut curr_prop_mil: u64 = 0 ;
@@ -212,12 +212,13 @@ pub(super) fn compute_payinfo(
212212 htlc_minimum_msat =
213213 core:: cmp:: max ( payee_tlvs. payment_constraints . htlc_minimum_msat as u128 , htlc_minimum_msat) ;
214214
215+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
215216 Ok ( BlindedPayInfo {
216217 fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
217218 fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
218219 cltv_expiry_delta,
219220 htlc_minimum_msat : u64:: try_from ( htlc_minimum_msat) . map_err ( |_| ( ) ) ?,
220- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
221+ htlc_maximum_msat,
221222 features : BlindedHopFeatures :: empty ( ) ,
222223 } )
223224}
@@ -277,11 +278,13 @@ mod tests {
277278 htlc_minimum_msat : 1 ,
278279 } ,
279280 } ;
280- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
281+ let htlc_maximum_msat = 100_000 ;
282+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
281283 assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
282284 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
283285 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
284286 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1000 ) ;
287+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
285288 }
286289
287290 #[ test]
@@ -293,11 +296,12 @@ mod tests {
293296 htlc_minimum_msat : 1 ,
294297 } ,
295298 } ;
296- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
299+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
297300 assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
298301 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
299302 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
300303 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
304+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
301305 }
302306
303307 #[ test]
@@ -337,7 +341,8 @@ mod tests {
337341 htlc_minimum_msat : 3 ,
338342 } ,
339343 } ;
340- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
344+ let htlc_maximum_msat = 100_000 ;
345+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
341346 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
342347 }
343348
@@ -378,7 +383,12 @@ mod tests {
378383 htlc_minimum_msat : 1 ,
379384 } ,
380385 } ;
381- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
382- assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 4798 ) ;
386+ let htlc_minimum_msat = 4798 ;
387+ assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 ) . is_err( ) ) ;
388+
389+ let htlc_maximum_msat = htlc_minimum_msat + 1 ;
390+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
391+ assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
392+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
383393 }
384394}
0 commit comments