Skip to content

Commit bd9a29e

Browse files
committed
Introduce RouteParametersConfig
With the current architecture, `pay_for_offer` only allows setting `max_total_routing_fee_msat` as a route parameter. However, it doesn't provide users the flexibility to set other important parameters. This commit introduces a new struct, `RouteParametersConfig`, that optionally allows users to set additional routing parameters. In later commits, this struct will be utilized when paying BOLT12 invoices.
1 parent ad19d93 commit bd9a29e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,89 @@ impl PaymentParameters {
962962
}
963963
}
964964

965+
/// A struct for configuring parameters for routing the payment.
966+
#[derive(Clone, Copy)]
967+
pub struct RouteParametersConfig {
968+
/// The maximum total fees, in millisatoshi, that may accrue during route finding.
969+
///
970+
/// This limit also applies to the total fees that may arise while retrying failed payment
971+
/// paths.
972+
///
973+
/// Note that values below a few sats may result in some paths being spuriously ignored.
974+
pub max_total_routing_fee_msat: Option<u64>,
975+
976+
/// The maximum total CLTV delta we accept for the route.
977+
/// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
978+
pub max_total_cltv_expiry_delta: u32,
979+
980+
/// The maximum number of paths that may be used by (MPP) payments.
981+
/// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
982+
pub max_path_count: u8,
983+
984+
/// Selects the maximum share of a channel's total capacity which will be sent over a channel,
985+
/// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
986+
/// a lower value prefers to send larger MPP parts, potentially saturating channels and
987+
/// increasing failure probability for those paths.
988+
///
989+
/// Note that this restriction will be relaxed during pathfinding after paths which meet this
990+
/// restriction have been found. While paths which meet this criteria will be searched for, it
991+
/// is ultimately up to the scorer to select them over other paths.
992+
///
993+
/// A value of 0 will allow payments up to and including a channel's total announced usable
994+
/// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
995+
///
996+
/// Default value: 2
997+
pub max_channel_saturation_power_of_half: u8,
998+
}
999+
1000+
impl_writeable_tlv_based!(RouteParametersConfig, {
1001+
(1, max_total_routing_fee_msat, option),
1002+
(3, max_total_cltv_expiry_delta, required),
1003+
(5, max_path_count, required),
1004+
(7, max_channel_saturation_power_of_half, required),
1005+
});
1006+
1007+
impl RouteParametersConfig {
1008+
/// Initates an new set of route parameter configs with default parameters.
1009+
pub fn new() -> Self {
1010+
Self {
1011+
max_total_routing_fee_msat: None,
1012+
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
1013+
max_path_count: DEFAULT_MAX_PATH_COUNT,
1014+
max_channel_saturation_power_of_half: DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF,
1015+
}
1016+
}
1017+
1018+
/// Set the maximum total fees, in millisatoshi, that may accrue during route finding.
1019+
///
1020+
/// This is not exported to bindings users since bindings don't support move semantics
1021+
pub fn with_max_total_routing_fee_msat(self, fee_msat: u64) -> Self {
1022+
Self { max_total_routing_fee_msat: Some(fee_msat), ..self }
1023+
}
1024+
1025+
/// Includes a limit for the total CLTV expiry delta which is considered during routing
1026+
///
1027+
/// This is not exported to bindings users since bindings don't support move semantics
1028+
pub fn with_max_total_cltv_expiry_delta(self, max_total_cltv_expiry_delta: u32) -> Self {
1029+
Self { max_total_cltv_expiry_delta, ..self }
1030+
}
1031+
1032+
/// Includes a limit for the maximum number of payment paths that may be used.
1033+
///
1034+
/// This is not exported to bindings users since bindings don't support move semantics
1035+
pub fn with_max_path_count(self, max_path_count: u8) -> Self {
1036+
Self { max_path_count, ..self }
1037+
}
1038+
1039+
/// Includes a limit for the maximum share of a channel's total capacity that can be sent over, as
1040+
/// a power of 1/2. See [`PaymentParameters::max_channel_saturation_power_of_half`].
1041+
///
1042+
/// This is not exported to bindings users since bindings don't support move semantics
1043+
pub fn with_max_channel_saturation_power_of_half(self, max_channel_saturation_power_of_half: u8) -> Self {
1044+
Self { max_channel_saturation_power_of_half, ..self }
1045+
}
1046+
}
1047+
9651048
/// The recipient of a payment, differing based on whether they've hidden their identity with route
9661049
/// blinding.
9671050
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

0 commit comments

Comments
 (0)