Skip to content

Commit 3380687

Browse files
committed
Move value contrib. calculation and improve docs.
We move the calculation of the value contribution out of the `add_entry!` macro and improve/update documentation in a few places.
1 parent 4617555 commit 3380687

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

lightning/src/routing/router.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ pub const DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = 1008;
178178

179179
/// Maximum number of paths we allow an MPP payment to have.
180180
// The default limit is currently set rather arbitrary - there aren't any real fundamental path-count
181-
// limits. After we support retrying individual paths we should likely bump this, but
182-
// for now more than 10 paths likely carries too much one-path failure.
181+
// limits, but for now more than 10 paths likely carries too much one-path failure.
183182
pub const DEFAULT_MAX_MPP_PATH_COUNT: u8 = 10;
184183

185184
// The median hop CLTV expiry delta currently seen in the network.
@@ -220,9 +219,11 @@ pub struct PaymentParameters {
220219
pub expiry_time: Option<u64>,
221220

222221
/// The maximum total CLTV delta we accept for the route.
222+
/// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
223223
pub max_total_cltv_expiry_delta: u32,
224224

225225
/// The maximum number of paths that may be used by MPP payments.
226+
/// Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT`].
226227
pub max_mpp_path_count: u8,
227228
}
228229

@@ -863,6 +864,21 @@ where L::Target: Logger {
863864
let recommended_value_msat = final_value_msat * ROUTE_CAPACITY_PROVISION_FACTOR as u64;
864865
let mut path_value_msat = final_value_msat;
865866

867+
// Routing Fragmentation Mitigation heuristic:
868+
//
869+
// Routing fragmentation across many payment paths increases the overall routing
870+
// fees as you have irreducible routing fees per-link used (`fee_base_msat`).
871+
// Taking too many smaller paths also increases the chance of payment failure.
872+
// Thus to avoid this effect, we require from our collected links to provide
873+
// at least a minimal contribution to the recommended value yet-to-be-fulfilled.
874+
// This requirement is currently set to be 1/max_mpp_path_count of the payment
875+
// value to ensure we only ever return routes that do not violate this limit.
876+
let minimal_value_contribution_msat: u64 = if allow_mpp {
877+
(final_value_msat + (payment_params.max_mpp_path_count as u64 - 1)) / payment_params.max_mpp_path_count as u64
878+
} else {
879+
final_value_msat
880+
};
881+
866882
// Keep track of how much liquidity has been used in selected channels. Used to determine
867883
// if the channel can be used by additional MPP paths or to inform path finding decisions. It is
868884
// aware of direction *only* to ensure that the correct htlc_maximum_msat value is used. Hence,
@@ -933,20 +949,6 @@ where L::Target: Logger {
933949
*used_liquidity_msat
934950
});
935951

936-
// Routing Fragmentation Mitigation heuristic:
937-
//
938-
// Routing fragmentation across many payment paths increases the overall routing
939-
// fees as you have irreducible routing fees per-link used (`fee_base_msat`).
940-
// Taking too many smaller paths also increases the chance of payment failure.
941-
// Thus to avoid this effect, we require from our collected links to provide
942-
// at least a minimal contribution to the recommended value yet-to-be-fulfilled.
943-
// This requirement is currently set to be 1/max_mpp_path_count of the payment
944-
// value to ensure we only ever return routes that do not violate this limit.
945-
let minimal_value_contribution_msat: u64 = if allow_mpp {
946-
(final_value_msat + (payment_params.max_mpp_path_count as u64 - 1)) / payment_params.max_mpp_path_count as u64
947-
} else {
948-
final_value_msat
949-
};
950952
// Verify the liquidity offered by this channel complies to the minimal contribution.
951953
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
952954
// Do not consider candidate hops that would exceed the maximum path length.
@@ -1691,7 +1693,7 @@ where L::Target: Logger {
16911693
selected_paths.push(path);
16921694
}
16931695
// Make sure we would never create a route with more paths than we allow.
1694-
assert!(selected_paths.len() <= payment_params.max_mpp_path_count.into());
1696+
debug_assert!(selected_paths.len() <= payment_params.max_mpp_path_count.into());
16951697

16961698
if let Some(features) = &payment_params.features {
16971699
for path in selected_paths.iter_mut() {

0 commit comments

Comments
 (0)