@@ -168,7 +168,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
168
168
}
169
169
170
170
pub ( super ) fn compute_payinfo (
171
- path : & [ ( PublicKey , BlindedPaymentTlvs ) ]
171
+ path : & [ ( PublicKey , BlindedPaymentTlvs ) ] , htlc_maximum_msat : u64 ,
172
172
) -> Result < BlindedPayInfo , ( ) > {
173
173
let mut curr_base_fee: u32 = 0 ;
174
174
let mut curr_prop_mil: u32 = 0 ;
@@ -195,14 +195,15 @@ pub(super) fn compute_payinfo(
195
195
. map ( |f| f / 1_000_000 )
196
196
. ok_or ( ( ) ) ?;
197
197
}
198
+ let htlc_minimum_msat = path. iter ( ) . map ( |( _, tlvs) | tlvs. htlc_minimum_msat ( ) ) . max ( ) . unwrap_or ( 0 ) ;
199
+ if htlc_maximum_msat < htlc_minimum_msat { return Err ( ( ) ) }
198
200
Ok ( BlindedPayInfo {
199
201
fee_base_msat : curr_base_fee,
200
202
fee_proportional_millionths : curr_prop_mil,
201
203
cltv_expiry_delta : path. iter ( ) . map ( |( _, tlvs) | tlvs. cltv_expiry_delta ( ) )
202
204
. try_fold ( 0u16 , |acc, delta| acc. checked_add ( delta) ) . ok_or ( ( ) ) ?,
203
- htlc_minimum_msat : path. iter ( ) . map ( |( _, tlvs) | tlvs. htlc_minimum_msat ( ) ) . max ( ) . unwrap_or ( 0 ) ,
204
- // TODO: this field isn't present in route blinding encrypted data
205
- htlc_maximum_msat : 21_000_000 * 100_000_000 * 1_000 , // Total bitcoin supply
205
+ htlc_minimum_msat,
206
+ htlc_maximum_msat,
206
207
features : BlindedHopFeatures :: empty ( ) ,
207
208
} )
208
209
}
@@ -264,11 +265,12 @@ mod tests {
264
265
htlc_minimum_msat: 1 ,
265
266
} ,
266
267
} ) ] ;
267
- let blinded_payinfo = super :: compute_payinfo ( & path[ ..] ) . unwrap ( ) ;
268
+ let blinded_payinfo = super :: compute_payinfo ( & path[ ..] , 4242 ) . unwrap ( ) ;
268
269
assert_eq ! ( blinded_payinfo. fee_base_msat, 201 ) ;
269
270
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 1001 ) ;
270
271
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 288 ) ;
271
272
assert_eq ! ( blinded_payinfo. htlc_minimum_msat, 1_000 ) ;
273
+ assert_eq ! ( blinded_payinfo. htlc_maximum_msat, 4242 ) ;
272
274
}
273
275
274
276
#[ test]
@@ -281,7 +283,7 @@ mod tests {
281
283
htlc_minimum_msat: 1 ,
282
284
} ,
283
285
} ) ] ;
284
- let blinded_payinfo = super :: compute_payinfo ( & path[ ..] ) . unwrap ( ) ;
286
+ let blinded_payinfo = super :: compute_payinfo ( & path[ ..] , 42 ) . unwrap ( ) ;
285
287
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
286
288
assert_eq ! ( blinded_payinfo. fee_proportional_millionths, 0 ) ;
287
289
assert_eq ! ( blinded_payinfo. cltv_expiry_delta, 0 ) ;
@@ -313,7 +315,7 @@ mod tests {
313
315
} ,
314
316
features: BlindedHopFeatures :: empty( ) ,
315
317
} ) ] ;
316
- assert ! ( BlindedPath :: new_for_payment( & out_of_order_payloads_path[ ..] , & keys_manager, & secp_ctx) . is_err( ) ) ;
318
+ assert ! ( BlindedPath :: new_for_payment( & out_of_order_payloads_path[ ..] , 1_000_000 , & keys_manager, & secp_ctx) . is_err( ) ) ;
317
319
318
320
let multiple_recv_payloads_path = vec ! [ ( dummy_pk, BlindedPaymentTlvs :: Receive {
319
321
payment_secret: PaymentSecret ( [ 0 ; 32 ] ) ,
@@ -328,7 +330,7 @@ mod tests {
328
330
htlc_minimum_msat: 1 ,
329
331
} ,
330
332
} ) ] ;
331
- assert ! ( BlindedPath :: new_for_payment( & multiple_recv_payloads_path[ ..] , & keys_manager, & secp_ctx) . is_err( ) ) ;
333
+ assert ! ( BlindedPath :: new_for_payment( & multiple_recv_payloads_path[ ..] , 1_000_000 , & keys_manager, & secp_ctx) . is_err( ) ) ;
332
334
333
335
let missing_recv_payload_path = vec ! [ ( dummy_pk, BlindedPaymentTlvs :: Forward {
334
336
short_channel_id: 0 ,
@@ -343,6 +345,6 @@ mod tests {
343
345
} ,
344
346
features: BlindedHopFeatures :: empty( ) ,
345
347
} ) ] ;
346
- assert ! ( BlindedPath :: new_for_payment( & missing_recv_payload_path[ ..] , & keys_manager, & secp_ctx) . is_err( ) ) ;
348
+ assert ! ( BlindedPath :: new_for_payment( & missing_recv_payload_path[ ..] , 1_000_000 , & keys_manager, & secp_ctx) . is_err( ) ) ;
347
349
}
348
350
}
0 commit comments