@@ -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
@@ -799,21 +799,23 @@ where L::Target: Logger {
799
799
let network_channels = network_graph. channels ( ) ;
800
800
let network_nodes = network_graph. nodes ( ) ;
801
801
802
+ if payment_params. max_path_count == 0 {
803
+ return Err ( LightningError { err : "Can't find a route with no paths allowed." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
804
+ }
805
+
802
806
// Allow MPP only if we have a features set from somewhere that indicates the payee supports
803
807
// it. If the payee supports it they're supposed to include it in the invoice, so that should
804
808
// work reliably.
805
- let allow_mpp = if let Some ( features) = & payment_params. features {
809
+ let allow_mpp = if payment_params. max_path_count == 1 {
810
+ false
811
+ } else if let Some ( features) = & payment_params. features {
806
812
features. supports_basic_mpp ( )
807
813
} else if let Some ( node) = network_nodes. get ( & payee_node_id) {
808
814
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
809
815
node_info. features . supports_basic_mpp ( )
810
816
} else { false }
811
817
} else { false } ;
812
818
813
- if allow_mpp && payment_params. max_mpp_path_count == 0 {
814
- return Err ( LightningError { err : "Can't find an MPP route with no paths allowed." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
815
- }
816
-
817
819
log_trace ! ( logger, "Searching for a route from payer {} to payee {} {} MPP and {} first hops {}overriding the network graph" , our_node_pubkey,
818
820
payment_params. payee_pubkey, if allow_mpp { "with" } else { "without" } ,
819
821
first_hops. map( |hops| hops. len( ) ) . unwrap_or( 0 ) , if first_hops. is_some( ) { "" } else { "not " } ) ;
@@ -871,10 +873,10 @@ where L::Target: Logger {
871
873
// Taking too many smaller paths also increases the chance of payment failure.
872
874
// Thus to avoid this effect, we require from our collected links to provide
873
875
// 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
876
+ // This requirement is currently set to be 1/max_path_count of the payment
875
877
// value to ensure we only ever return routes that do not violate this limit.
876
878
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
879
+ ( final_value_msat + ( payment_params. max_path_count as u64 - 1 ) ) / payment_params. max_path_count as u64
878
880
} else {
879
881
final_value_msat
880
882
} ;
@@ -1693,7 +1695,7 @@ where L::Target: Logger {
1693
1695
selected_paths. push ( path) ;
1694
1696
}
1695
1697
// Make sure we would never create a route with more paths than we allow.
1696
- debug_assert ! ( selected_paths. len( ) <= payment_params. max_mpp_path_count . into( ) ) ;
1698
+ debug_assert ! ( selected_paths. len( ) <= payment_params. max_path_count . into( ) ) ;
1697
1699
1698
1700
if let Some ( features) = & payment_params. features {
1699
1701
for path in selected_paths. iter_mut ( ) {
@@ -4117,20 +4119,20 @@ mod tests {
4117
4119
}
4118
4120
4119
4121
{
4120
- // Attempt to route while setting max_mpp_path_count to 0 results in a failure.
4121
- let zero_payment_params = payment_params. clone ( ) . with_max_mpp_path_count ( 0 ) ;
4122
+ // Attempt to route while setting max_path_count to 0 results in a failure.
4123
+ let zero_payment_params = payment_params. clone ( ) . with_max_path_count ( 0 ) ;
4122
4124
if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route (
4123
4125
& our_id, & zero_payment_params, & network_graph. read_only ( ) , None , 100 , 42 ,
4124
4126
Arc :: clone ( & logger) , & scorer, & random_seed_bytes) {
4125
- assert_eq ! ( err, "Can't find an MPP route with no paths allowed." ) ;
4127
+ assert_eq ! ( err, "Can't find a route with no paths allowed." ) ;
4126
4128
} else { panic ! ( ) ; }
4127
4129
}
4128
4130
4129
4131
{
4130
- // Attempt to route while setting max_mpp_path_count to 3 results in a failure.
4132
+ // Attempt to route while setting max_path_count to 3 results in a failure.
4131
4133
// This is the case because the minimal_value_contribution_msat would require each path
4132
4134
// to account for 1/3 of the total value, which is violated by 2 out of 3 paths.
4133
- let fail_payment_params = payment_params. clone ( ) . with_max_mpp_path_count ( 3 ) ;
4135
+ let fail_payment_params = payment_params. clone ( ) . with_max_path_count ( 3 ) ;
4134
4136
if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = get_route (
4135
4137
& our_id, & fail_payment_params, & network_graph. read_only ( ) , None , 250_000 , 42 ,
4136
4138
Arc :: clone ( & logger) , & scorer, & random_seed_bytes) {
0 commit comments