@@ -176,10 +176,10 @@ impl_writeable_tlv_based!(RouteParameters, {
176
176
/// Maximum total CTLV difference we allow for a full payment path.
177
177
pub const DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA : u32 = 1008 ;
178
178
179
- /// Maximum number of paths we allow an MPP payment to have.
179
+ /// Maximum number of paths we allow an ( MPP) payment to have.
180
180
// The default limit is currently set rather arbitrary - there aren't any real fundamental path-count
181
181
// limits, but for now more than 10 paths likely carries too much one-path failure.
182
- pub const DEFAULT_MAX_MPP_PATH_COUNT : u8 = 10 ;
182
+ pub const DEFAULT_MAX_PATH_COUNT : u8 = 10 ;
183
183
184
184
// The median hop CLTV expiry delta currently seen in the network.
185
185
const MEDIAN_HOP_CLTV_EXPIRY_DELTA : u32 = 40 ;
@@ -222,16 +222,16 @@ pub struct PaymentParameters {
222
222
/// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
223
223
pub max_total_cltv_expiry_delta : u32 ,
224
224
225
- /// The maximum number of paths that may be used by MPP payments.
226
- /// Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT `].
227
- pub max_mpp_path_count : u8 ,
225
+ /// The maximum number of paths that may be used by ( MPP) payments.
226
+ /// Defaults to [`DEFAULT_MAX_PATH_COUNT `].
227
+ pub max_path_count : u8 ,
228
228
}
229
229
230
230
impl_writeable_tlv_based ! ( PaymentParameters , {
231
231
( 0 , payee_pubkey, required) ,
232
232
( 1 , max_total_cltv_expiry_delta, ( default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ) ) ,
233
233
( 2 , features, option) ,
234
- ( 3 , max_mpp_path_count , ( default_value, DEFAULT_MAX_MPP_PATH_COUNT ) ) ,
234
+ ( 3 , max_path_count , ( default_value, DEFAULT_MAX_PATH_COUNT ) ) ,
235
235
( 4 , route_hints, vec_type) ,
236
236
( 6 , expiry_time, option) ,
237
237
} ) ;
@@ -245,7 +245,7 @@ impl PaymentParameters {
245
245
route_hints : vec ! [ ] ,
246
246
expiry_time : None ,
247
247
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
248
- max_mpp_path_count : DEFAULT_MAX_MPP_PATH_COUNT ,
248
+ max_path_count : DEFAULT_MAX_PATH_COUNT ,
249
249
}
250
250
}
251
251
@@ -282,11 +282,11 @@ impl PaymentParameters {
282
282
Self { max_total_cltv_expiry_delta, ..self }
283
283
}
284
284
285
- /// Includes a limit for the maximum number of payment paths that may be used by MPP .
285
+ /// Includes a limit for the maximum number of payment paths that may be used.
286
286
///
287
287
/// (C-not exported) since bindings don't support move semantics
288
- pub fn with_max_mpp_path_count ( self , max_mpp_path_count : u8 ) -> Self {
289
- Self { max_mpp_path_count , ..self }
288
+ pub fn with_max_path_count ( self , max_path_count : u8 ) -> Self {
289
+ Self { max_path_count , ..self }
290
290
}
291
291
}
292
292
@@ -800,21 +800,23 @@ where L::Target: Logger {
800
800
let network_channels = network_graph. channels ( ) ;
801
801
let network_nodes = network_graph. nodes ( ) ;
802
802
803
+ if payment_params. max_path_count == 0 {
804
+ return Err ( LightningError { err : "Can't find a route with no paths allowed." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
805
+ }
806
+
803
807
// Allow MPP only if we have a features set from somewhere that indicates the payee supports
804
808
// it. If the payee supports it they're supposed to include it in the invoice, so that should
805
809
// work reliably.
806
- let allow_mpp = if let Some ( features) = & payment_params. features {
810
+ let allow_mpp = if payment_params. max_path_count == 1 {
811
+ false
812
+ } else if let Some ( features) = & payment_params. features {
807
813
features. supports_basic_mpp ( )
808
814
} else if let Some ( node) = network_nodes. get ( & payee_node_id) {
809
815
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
810
816
node_info. features . supports_basic_mpp ( )
811
817
} else { false }
812
818
} else { false } ;
813
819
814
- if allow_mpp && payment_params. max_mpp_path_count == 0 {
815
- return Err ( LightningError { err : "Can't find an MPP route with no paths allowed." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
816
- }
817
-
818
820
log_trace ! ( logger, "Searching for a route from payer {} to payee {} {} MPP and {} first hops {}overriding the network graph" , our_node_pubkey,
819
821
payment_params. payee_pubkey, if allow_mpp { "with" } else { "without" } ,
820
822
first_hops. map( |hops| hops. len( ) ) . unwrap_or( 0 ) , if first_hops. is_some( ) { "" } else { "not " } ) ;
@@ -872,10 +874,10 @@ where L::Target: Logger {
872
874
// Taking too many smaller paths also increases the chance of payment failure.
873
875
// Thus to avoid this effect, we require from our collected links to provide
874
876
// at least a minimal contribution to the recommended value yet-to-be-fulfilled.
875
- // This requirement is currently set to be 1/max_mpp_path_count of the payment
877
+ // This requirement is currently set to be 1/max_path_count of the payment
876
878
// value to ensure we only ever return routes that do not violate this limit.
877
879
let minimal_value_contribution_msat: u64 = if allow_mpp {
878
- ( final_value_msat + ( payment_params. max_mpp_path_count as u64 - 1 ) ) / payment_params. max_mpp_path_count as u64
880
+ ( final_value_msat + ( payment_params. max_path_count as u64 - 1 ) ) / payment_params. max_path_count as u64
879
881
} else {
880
882
final_value_msat
881
883
} ;
@@ -1694,7 +1696,7 @@ where L::Target: Logger {
1694
1696
selected_paths. push ( path) ;
1695
1697
}
1696
1698
// Make sure we would never create a route with more paths than we allow.
1697
- debug_assert ! ( selected_paths. len( ) <= payment_params. max_mpp_path_count . into( ) ) ;
1699
+ debug_assert ! ( selected_paths. len( ) <= payment_params. max_path_count . into( ) ) ;
1698
1700
1699
1701
if let Some ( features) = & payment_params. features {
1700
1702
for path in selected_paths. iter_mut ( ) {
@@ -4119,20 +4121,20 @@ mod tests {
4119
4121
}
4120
4122
4121
4123
{
4122
- // Attempt to route while setting max_mpp_path_count to 0 results in a failure.
4123
- let zero_payment_params = payment_params. clone ( ) . with_max_mpp_path_count ( 0 ) ;
4124
+ // Attempt to route while setting max_path_count to 0 results in a failure.
4125
+ let zero_payment_params = payment_params. clone ( ) . with_max_path_count ( 0 ) ;
4124
4126
if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route (
4125
4127
& our_id, & zero_payment_params, & network_graph. read_only ( ) , None , 100 , 42 ,
4126
4128
Arc :: clone ( & logger) , & scorer, & random_seed_bytes) {
4127
- assert_eq ! ( err, "Can't find an MPP route with no paths allowed." ) ;
4129
+ assert_eq ! ( err, "Can't find a route with no paths allowed." ) ;
4128
4130
} else { panic ! ( ) ; }
4129
4131
}
4130
4132
4131
4133
{
4132
- // Attempt to route while setting max_mpp_path_count to 3 results in a failure.
4134
+ // Attempt to route while setting max_path_count to 3 results in a failure.
4133
4135
// This is the case because the minimal_value_contribution_msat would require each path
4134
4136
// to account for 1/3 of the total value, which is violated by 2 out of 3 paths.
4135
- let fail_payment_params = payment_params. clone ( ) . with_max_mpp_path_count ( 3 ) ;
4137
+ let fail_payment_params = payment_params. clone ( ) . with_max_path_count ( 3 ) ;
4136
4138
if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route (
4137
4139
& our_id, & fail_payment_params, & network_graph. read_only ( ) , None , 250_000 , 42 ,
4138
4140
Arc :: clone ( & logger) , & scorer, & random_seed_bytes) {
0 commit comments