@@ -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 ;
@@ -202,12 +202,13 @@ pub(super) fn compute_payinfo(
202202 htlc_minimum_msat = core:: cmp:: max ( htlc_min_candidate, htlc_minimum_msat) ;
203203 }
204204
205+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
205206 Ok ( BlindedPayInfo {
206207 fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
207208 fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
208209 cltv_expiry_delta,
209210 htlc_minimum_msat : u64:: try_from ( htlc_minimum_msat) . map_err ( |_| ( ) ) ?,
210- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
211+ htlc_maximum_msat,
211212 features : BlindedHopFeatures :: empty ( ) ,
212213 } )
213214}
@@ -267,11 +268,13 @@ mod tests {
267268 htlc_minimum_msat : 1 ,
268269 } ,
269270 } ;
270- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
271+ let htlc_maximum_msat = 100_000 ;
272+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
271273 assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
272274 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
273275 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
274276 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1000 ) ;
277+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
275278 }
276279
277280 #[ test]
@@ -283,11 +286,12 @@ mod tests {
283286 htlc_minimum_msat : 1 ,
284287 } ,
285288 } ;
286- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
289+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
287290 assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
288291 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
289292 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
290293 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
294+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
291295 }
292296
293297 #[ test]
@@ -327,7 +331,8 @@ mod tests {
327331 htlc_minimum_msat : 3 ,
328332 } ,
329333 } ;
330- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
334+ let htlc_maximum_msat = 100_000 ;
335+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
331336 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
332337 }
333338
@@ -368,7 +373,12 @@ mod tests {
368373 htlc_minimum_msat : 1 ,
369374 } ,
370375 } ;
371- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
372- assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 4798 ) ;
376+ let htlc_minimum_msat = 4798 ;
377+ assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 ) . is_err( ) ) ;
378+
379+ let htlc_maximum_msat = htlc_minimum_msat + 1 ;
380+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
381+ assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
382+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
373383 }
374384}
0 commit comments