@@ -152,7 +152,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
152
152
}
153
153
154
154
pub ( super ) fn compute_payinfo (
155
- intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs
155
+ intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs , htlc_maximum_msat : u64
156
156
) -> Result < BlindedPayInfo , ( ) > {
157
157
let mut curr_base_fee: u128 = 0 ;
158
158
let mut curr_prop_mil: u128 = 0 ;
@@ -209,12 +209,13 @@ pub(super) fn compute_payinfo(
209
209
htlc_minimum_msat =
210
210
core:: cmp:: max ( payee_tlvs. payment_constraints . htlc_minimum_msat as u128 , htlc_minimum_msat) ;
211
211
212
+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
212
213
Ok ( BlindedPayInfo {
213
214
fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
214
215
fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
215
216
cltv_expiry_delta,
216
217
htlc_minimum_msat : u64:: try_from ( htlc_minimum_msat) . map_err ( |_| ( ) ) ?,
217
- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // TODO
218
+ htlc_maximum_msat,
218
219
features : BlindedHopFeatures :: empty ( ) ,
219
220
} )
220
221
}
@@ -274,11 +275,13 @@ mod tests {
274
275
htlc_minimum_msat : 1 ,
275
276
} ,
276
277
} ;
277
- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
278
+ let htlc_maximum_msat = 100_000 ;
279
+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
278
280
assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
279
281
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
280
282
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
281
283
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 900 ) ;
284
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
282
285
}
283
286
284
287
#[ test]
@@ -290,11 +293,12 @@ mod tests {
290
293
htlc_minimum_msat : 1 ,
291
294
} ,
292
295
} ;
293
- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
296
+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
294
297
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
295
298
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
296
299
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
297
300
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
301
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
298
302
}
299
303
300
304
#[ test]
@@ -334,7 +338,8 @@ mod tests {
334
338
htlc_minimum_msat : 3 ,
335
339
} ,
336
340
} ;
337
- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
341
+ let htlc_maximum_msat = 100_000 ;
342
+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
338
343
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
339
344
}
340
345
@@ -375,8 +380,12 @@ mod tests {
375
380
htlc_minimum_msat : 1 ,
376
381
} ,
377
382
} ;
383
+ let htlc_minimum_msat = 3797 ;
384
+ assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 ) . is_err( ) ) ;
378
385
379
- let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs) . unwrap ( ) ;
380
- assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 3797 ) ;
386
+ let htlc_maximum_msat = htlc_minimum_msat + 1 ;
387
+ let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat) . unwrap ( ) ;
388
+ assert_eq ! ( blinded_payinfo. htlc_minimum_msat, htlc_minimum_msat) ;
389
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
381
390
}
382
391
}
0 commit comments