@@ -178,7 +178,7 @@ fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &PaymentRelay) -> O
178178}
179179
180180pub ( super ) fn compute_payinfo (
181- intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs
181+ intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs , htlc_maximum_msat : u64
182182) -> Result < BlindedPayInfo , ( ) > {
183183 let mut curr_base_fee: u64 = 0 ;
184184 let mut curr_prop_mil: u64 = 0 ;
@@ -220,12 +220,13 @@ pub(super) fn compute_payinfo(
220220 payee_tlvs. payment_constraints . htlc_minimum_msat , htlc_minimum_msat
221221 ) ;
222222
223+ if htlc_maximum_msat < htlc_minimum_msat { return Err ( ( ) ) }
223224 Ok ( BlindedPayInfo {
224225 fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
225226 fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
226227 cltv_expiry_delta,
227228 htlc_minimum_msat,
228- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
229+ htlc_maximum_msat,
229230 features : BlindedHopFeatures :: empty ( ) ,
230231 } )
231232}
@@ -285,11 +286,13 @@ mod tests {
285286 htlc_minimum_msat : 1 ,
286287 } ,
287288 } ;
288- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
289+ let htlc_maximum_msat = 100_000 ;
290+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
289291 assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
290292 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
291293 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
292294 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 900 ) ;
295+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
293296 }
294297
295298 #[ test]
@@ -301,11 +304,12 @@ mod tests {
301304 htlc_minimum_msat : 1 ,
302305 } ,
303306 } ;
304- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
307+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
305308 assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
306309 assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
307310 assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
308311 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
312+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
309313 }
310314
311315 #[ test]
@@ -345,7 +349,8 @@ mod tests {
345349 htlc_minimum_msat : 3 ,
346350 } ,
347351 } ;
348- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
352+ let htlc_maximum_msat = 100_000 ;
353+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
349354 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
350355 }
351356
@@ -387,7 +392,11 @@ mod tests {
387392 } ,
388393 } ;
389394 let htlc_minimum_msat = 3798 ;
390- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
395+ assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 ) . is_err( ) ) ;
396+
397+ let htlc_maximum_msat = htlc_minimum_msat + 1 ;
398+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
391399 assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
400+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
392401 }
393402}
0 commit comments