Skip to content

Commit 6fcd3a1

Browse files
f add buffer to amount and cltv delta estimates
1 parent f7159c2 commit 6fcd3a1

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::ln::msgs;
1616
use crate::ln::types::{PaymentHash, PaymentPreimage};
1717
use crate::ln::wire::Encode;
1818
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+
};
2022
use crate::sign::NodeSigner;
2123
use crate::util::errors::{self, APIError};
2224
use crate::util::logger::Logger;
@@ -324,46 +326,44 @@ pub(crate) fn set_max_path_length(
324326
.serialized_length()
325327
.saturating_add(PAYLOAD_HMAC_LEN);
326328

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));
352352

353353
let unblinded_route_hop = RouteHop {
354354
pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
355355
node_features: NodeFeatures::empty(),
356356
short_channel_id: 42,
357357
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,
360360
maybe_announced_channel: false,
361361
};
362362
let mut num_reserved_bytes: usize = 0;
363363
let build_payloads_res = build_onion_payloads_callback(
364364
core::iter::once(&unblinded_route_hop),
365365
blinded_tail_opt,
366-
route_params.final_value_msat,
366+
final_value_msat_with_overpay_buffer,
367367
&recipient_onion,
368368
best_block_height,
369369
&keysend_preimage,

0 commit comments

Comments
 (0)