Skip to content

Commit d4fc1b2

Browse files
committed
Introduce PaymentParameters::max_total_routing_fee_msat
Currently, users have no means to upper-bound the total fees accruing when finding a route. Here, we add a corresponding field to `PaymentParameters` which will be used to limit the candidate set during path finding in the following commits.
1 parent 36af946 commit d4fc1b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ pub struct PaymentParameters {
537537
/// Default value: 2
538538
pub max_channel_saturation_power_of_half: u8,
539539

540+
/// The maximum total fees, in millisatoshi, that may accrue during route finding.
541+
///
542+
/// This limit also applies to the total fees that may arise while retrying partially failed
543+
/// payments.
544+
///
545+
/// Default value: `None`
546+
pub max_total_routing_fee_msat: Option<u64>,
547+
540548
/// A list of SCIDs which this payment was previously attempted over and which caused the
541549
/// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
542550
/// these SCIDs.
@@ -562,6 +570,7 @@ impl Writeable for PaymentParameters {
562570
(7, self.previously_failed_channels, required_vec),
563571
(8, *blinded_hints, optional_vec),
564572
(9, self.payee.final_cltv_expiry_delta(), option),
573+
(11, self.max_total_routing_fee_msat, option),
565574
});
566575
Ok(())
567576
}
@@ -580,6 +589,7 @@ impl ReadableArgs<u32> for PaymentParameters {
580589
(7, previously_failed_channels, optional_vec),
581590
(8, blinded_route_hints, optional_vec),
582591
(9, final_cltv_expiry_delta, (default_value, default_final_cltv_expiry_delta)),
592+
(11, max_total_routing_fee_msat, option),
583593
});
584594
let blinded_route_hints = blinded_route_hints.unwrap_or(vec![]);
585595
let payee = if blinded_route_hints.len() != 0 {
@@ -603,6 +613,7 @@ impl ReadableArgs<u32> for PaymentParameters {
603613
max_channel_saturation_power_of_half: _init_tlv_based_struct_field!(max_channel_saturation_power_of_half, (default_value, unused)),
604614
expiry_time,
605615
previously_failed_channels: previously_failed_channels.unwrap_or(Vec::new()),
616+
max_total_routing_fee_msat,
606617
})
607618
}
608619
}
@@ -621,6 +632,7 @@ impl PaymentParameters {
621632
max_path_count: DEFAULT_MAX_PATH_COUNT,
622633
max_channel_saturation_power_of_half: DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF,
623634
previously_failed_channels: Vec::new(),
635+
max_total_routing_fee_msat: None,
624636
}
625637
}
626638

@@ -658,6 +670,7 @@ impl PaymentParameters {
658670
max_path_count: DEFAULT_MAX_PATH_COUNT,
659671
max_channel_saturation_power_of_half: DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF,
660672
previously_failed_channels: Vec::new(),
673+
max_total_routing_fee_msat: None,
661674
}
662675
}
663676

@@ -733,6 +746,13 @@ impl PaymentParameters {
733746
pub fn with_max_channel_saturation_power_of_half(self, max_channel_saturation_power_of_half: u8) -> Self {
734747
Self { max_channel_saturation_power_of_half, ..self }
735748
}
749+
750+
/// Includes a limit for the maximum total routing fees that may accrue during route finding.
751+
///
752+
/// This is not exported to bindings users since bindings don't support move semantics
753+
pub fn with_max_total_routing_fee_msat(self, max_total_routing_fee_msat: u64) -> Self {
754+
Self { max_total_routing_fee_msat: Some(max_total_routing_fee_msat), ..self }
755+
}
736756
}
737757

738758
/// The recipient of a payment, differing based on whether they've hidden their identity with route

0 commit comments

Comments
 (0)