@@ -16,7 +16,9 @@ use crate::ln::msgs;
16
16
use crate :: ln:: types:: { PaymentHash , PaymentPreimage } ;
17
17
use crate :: ln:: wire:: Encode ;
18
18
use crate :: routing:: gossip:: NetworkUpdate ;
19
- use crate :: routing:: router:: { Path , Payee , RouteHop , RouteParameters , MAX_PATH_LENGTH_ESTIMATE } ;
19
+ use crate :: routing:: router:: {
20
+ Path , RouteHop , RouteParameters , DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA , MAX_PATH_LENGTH_ESTIMATE ,
21
+ } ;
20
22
use crate :: sign:: NodeSigner ;
21
23
use crate :: util:: errors:: { self , APIError } ;
22
24
use crate :: util:: logger:: Logger ;
@@ -324,46 +326,44 @@ pub(crate) fn set_max_path_length(
324
326
. serialized_length ( )
325
327
. saturating_add ( PAYLOAD_HMAC_LEN ) ;
326
328
327
- let ( cltv_expiry_delta, num_reserved_hops, blinded_tail_opt) =
328
- match & route_params. payment_params . payee {
329
- Payee :: Blinded { route_hints, .. } => {
330
- let ( blinded_payinfo, largest_path) = route_hints
331
- . iter ( )
332
- . max_by ( |( _, path_a) , ( _, path_b) | {
333
- path_a. serialized_length ( ) . cmp ( & path_b. serialized_length ( ) )
334
- } )
335
- . ok_or ( ( ) ) ?;
336
- let blinded_tail = BlindedTailHopIter {
337
- hops : largest_path. blinded_hops . iter ( ) ,
338
- blinding_point : largest_path. blinding_point ,
339
- final_value_msat : route_params. final_value_msat ,
340
- excess_final_cltv_expiry_delta : 0 ,
341
- } ;
342
- (
343
- blinded_payinfo. cltv_expiry_delta as u32 ,
344
- largest_path. blinded_hops . len ( ) ,
345
- Some ( blinded_tail) ,
346
- )
347
- } ,
348
- Payee :: Clear { final_cltv_expiry_delta, .. } => {
349
- ( * final_cltv_expiry_delta, 1 as usize , None )
350
- } ,
351
- } ;
329
+ const MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY : u64 = 100_000_000 ;
330
+ let final_value_msat_with_overpay_buffer = core:: cmp:: max (
331
+ route_params. final_value_msat . saturating_mul ( 4 ) ,
332
+ MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY ,
333
+ ) ;
334
+
335
+ let ( num_reserved_hops, blinded_tail_opt) = route_params
336
+ . payment_params
337
+ . payee
338
+ . blinded_route_hints ( )
339
+ . iter ( )
340
+ . map ( |( _, path) | path)
341
+ . max_by ( |path_a, path_b| path_a. serialized_length ( ) . cmp ( & path_b. serialized_length ( ) ) )
342
+ . map ( |largest_path| {
343
+ let blinded_tail = BlindedTailHopIter {
344
+ hops : largest_path. blinded_hops . iter ( ) ,
345
+ blinding_point : largest_path. blinding_point ,
346
+ final_value_msat : final_value_msat_with_overpay_buffer,
347
+ excess_final_cltv_expiry_delta : 0 ,
348
+ } ;
349
+ ( largest_path. blinded_hops . len ( ) , Some ( blinded_tail) )
350
+ } )
351
+ . unwrap_or ( ( 1 , None ) ) ;
352
352
353
353
let unblinded_route_hop = RouteHop {
354
354
pubkey : PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ,
355
355
node_features : NodeFeatures :: empty ( ) ,
356
356
short_channel_id : 42 ,
357
357
channel_features : ChannelFeatures :: empty ( ) ,
358
- fee_msat : route_params . final_value_msat ,
359
- cltv_expiry_delta,
358
+ fee_msat : final_value_msat_with_overpay_buffer ,
359
+ cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
360
360
maybe_announced_channel : false ,
361
361
} ;
362
362
let mut num_reserved_bytes: usize = 0 ;
363
363
let build_payloads_res = build_onion_payloads_callback (
364
364
core:: iter:: once ( & unblinded_route_hop) ,
365
365
blinded_tail_opt,
366
- route_params . final_value_msat ,
366
+ final_value_msat_with_overpay_buffer ,
367
367
& recipient_onion,
368
368
best_block_height,
369
369
& keysend_preimage,
0 commit comments