Skip to content

Commit adba982

Browse files
committed
Introduce RouteParametersOverride
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, `RouteParametersOverride`, 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 adba982

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lightning/src/routing/router.rs

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

965+
/// A struct for overriding specific [`RouteParameters`] values created
966+
/// from a given [`Bolt12Invoice`].
967+
///
968+
/// If any field is set to `None`, the corresponding parameter will not be overridden.
969+
#[derive(Clone, Copy)]
970+
pub struct RouteParametersOverride {
971+
/// Overrides [`RouteParameters::max_total_routing_fee_msat`] if specified.
972+
pub max_total_routing_fee_msat: Option<u64>,
973+
/// Overrides [`PaymentParameters::max_total_cltv_expiry_delta`] if specified.
974+
pub max_total_cltv_expiry_delta: Option<u32>,
975+
/// Overrides [`PaymentParameters::max_path_count`] if specified.
976+
pub max_path_count: Option<u8>,
977+
/// Overrides [`PaymentParameters::max_channel_saturation_power_of_half`] if specified.
978+
pub max_channel_saturation_power_of_half: Option<u8>,
979+
}
980+
981+
impl_writeable_tlv_based!(RouteParametersOverride, {
982+
(1, max_total_routing_fee_msat, option),
983+
(3, max_total_cltv_expiry_delta, option),
984+
(5, max_path_count, option),
985+
(7, max_channel_saturation_power_of_half, option),
986+
});
987+
988+
impl RouteParametersOverride {
989+
/// Initates an empty set of [`RouteParametersOverride`]
990+
pub fn new() -> Self {
991+
Self {
992+
max_total_routing_fee_msat: None,
993+
max_total_cltv_expiry_delta: None,
994+
max_path_count: None,
995+
max_channel_saturation_power_of_half: None,
996+
}
997+
}
998+
999+
/// Creates a new set of [`RouteParametersOverride`] with the updated `max_total_routing_fee_msat`.
1000+
pub fn with_max_total_routing_fee_msat(self, fee_msat: u64) -> Self {
1001+
Self { max_total_routing_fee_msat: Some(fee_msat), ..self }
1002+
}
1003+
}
1004+
9651005
/// The recipient of a payment, differing based on whether they've hidden their identity with route
9661006
/// blinding.
9671007
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

0 commit comments

Comments
 (0)