@@ -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 ;
@@ -202,12 +202,13 @@ pub(super) fn compute_payinfo(
202
202
htlc_minimum_msat = core:: cmp:: max ( htlc_min_candidate, htlc_minimum_msat) ;
203
203
}
204
204
205
+ if ( htlc_maximum_msat as u128 ) < htlc_minimum_msat { return Err ( ( ) ) }
205
206
Ok ( BlindedPayInfo {
206
207
fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
207
208
fee_proportional_millionths : u32:: try_from ( curr_prop_mil) . map_err ( |_| ( ) ) ?,
208
209
cltv_expiry_delta,
209
210
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,
211
212
features : BlindedHopFeatures :: empty ( ) ,
212
213
} )
213
214
}
@@ -267,11 +268,13 @@ mod tests {
267
268
htlc_minimum_msat : 1 ,
268
269
} ,
269
270
} ;
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 ( ) ;
271
273
assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
272
274
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
273
275
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
274
276
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1000 ) ;
277
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, htlc_maximum_msat) ;
275
278
}
276
279
277
280
#[ test]
@@ -283,11 +286,12 @@ mod tests {
283
286
htlc_minimum_msat : 1 ,
284
287
} ,
285
288
} ;
286
- let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs) . unwrap ( ) ;
289
+ let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 ) . unwrap ( ) ;
287
290
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
288
291
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
289
292
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
290
293
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1 ) ;
294
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
291
295
}
292
296
293
297
#[ test]
@@ -327,7 +331,8 @@ mod tests {
327
331
htlc_minimum_msat : 3 ,
328
332
} ,
329
333
} ;
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 ( ) ;
331
336
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 2_000 ) ;
332
337
}
333
338
@@ -368,7 +373,12 @@ mod tests {
368
373
htlc_minimum_msat : 1 ,
369
374
} ,
370
375
} ;
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) ;
373
383
}
374
384
}
0 commit comments