@@ -178,7 +178,7 @@ fn amt_to_forward_msat(inbound_amt_msat: u64, payment_relay: &PaymentRelay) -> O
178
178
}
179
179
180
180
pub ( super ) fn compute_payinfo (
181
- intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs
181
+ intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs , htlc_maximum_msat : u64
182
182
) -> Result < BlindedPayInfo , ( ) > {
183
183
let mut curr_base_fee: u64 = 0 ;
184
184
let mut curr_prop_mil: u64 = 0 ;
@@ -220,12 +220,13 @@ pub(super) fn compute_payinfo(
220
220
payee_tlvs. payment_constraints . htlc_minimum_msat , htlc_minimum_msat
221
221
) ;
222
222
223
+ if htlc_maximum_msat < htlc_minimum_msat { return Err ( ( ) ) }
223
224
Ok ( BlindedPayInfo {
224
225
fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
225
226
fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
226
227
cltv_expiry_delta,
227
228
htlc_minimum_msat,
228
- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
229
+ htlc_maximum_msat,
229
230
features : BlindedHopFeatures :: empty ( ) ,
230
231
} )
231
232
}
@@ -285,11 +286,13 @@ mod tests {
285
286
htlc_minimum_msat : 1 ,
286
287
} ,
287
288
} ;
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 ( ) ;
289
291
assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
290
292
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
291
293
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
292
294
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 900 ) ;
295
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
293
296
}
294
297
295
298
#[ test]
@@ -301,11 +304,12 @@ mod tests {
301
304
htlc_minimum_msat : 1 ,
302
305
} ,
303
306
} ;
304
- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
307
+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
305
308
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
306
309
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
307
310
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
308
311
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
312
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
309
313
}
310
314
311
315
#[ test]
@@ -345,7 +349,8 @@ mod tests {
345
349
htlc_minimum_msat : 3 ,
346
350
} ,
347
351
} ;
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 ( ) ;
349
354
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
350
355
}
351
356
@@ -387,7 +392,11 @@ mod tests {
387
392
} ,
388
393
} ;
389
394
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 ( ) ;
391
399
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
400
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
392
401
}
393
402
}
0 commit comments