@@ -154,7 +154,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
154
154
}
155
155
156
156
pub ( super ) fn compute_payinfo (
157
- intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs
157
+ intermediate_nodes : & [ ( PublicKey , ForwardTlvs ) ] , payee_tlvs : & ReceiveTlvs , htlc_maximum_msat : u64
158
158
) -> Result < BlindedPayInfo , ( ) > {
159
159
let mut curr_base_fee: u64 = 0 ;
160
160
let mut curr_prop_mil: u64 = 0 ;
@@ -212,12 +212,13 @@ pub(super) fn compute_payinfo(
212
212
htlc_minimum_msat =
213
213
core:: cmp:: max ( payee_tlvs. payment_constraints . htlc_minimum_msat as u128 , htlc_minimum_msat) ;
214
214
215
+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
215
216
Ok ( BlindedPayInfo {
216
217
fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
217
218
fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
218
219
cltv_expiry_delta,
219
220
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,
221
222
features : BlindedHopFeatures :: empty ( ) ,
222
223
} )
223
224
}
@@ -277,11 +278,13 @@ mod tests {
277
278
htlc_minimum_msat : 1 ,
278
279
} ,
279
280
} ;
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 ( ) ;
281
283
assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
282
284
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
283
285
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
284
286
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1000 ) ;
287
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
285
288
}
286
289
287
290
#[ test]
@@ -293,11 +296,12 @@ mod tests {
293
296
htlc_minimum_msat : 1 ,
294
297
} ,
295
298
} ;
296
- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
299
+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
297
300
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
298
301
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
299
302
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
300
303
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
304
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
301
305
}
302
306
303
307
#[ test]
@@ -337,7 +341,8 @@ mod tests {
337
341
htlc_minimum_msat : 3 ,
338
342
} ,
339
343
} ;
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 ( ) ;
341
346
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
342
347
}
343
348
@@ -378,7 +383,12 @@ mod tests {
378
383
htlc_minimum_msat : 1 ,
379
384
} ,
380
385
} ;
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) ;
383
393
}
384
394
}
0 commit comments