@@ -602,6 +602,17 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> {
602
602
}
603
603
}
604
604
605
+ /// The default `features` we assume for a node in a route, when no `features` are known about that
606
+ /// specific node.
607
+ ///
608
+ /// Default features are:
609
+ /// * variable_length_onion_optional
610
+ fn default_node_features ( ) -> NodeFeatures {
611
+ let mut features = NodeFeatures :: empty ( ) ;
612
+ features. set_variable_length_onion_optional ( ) ;
613
+ features
614
+ }
615
+
605
616
/// Finds a route from us (payer) to the given target node (payee).
606
617
///
607
618
/// If the payee provided features in their invoice, they should be provided via `params.payee`.
@@ -1101,8 +1112,7 @@ where L::Target: Logger {
1101
1112
} }
1102
1113
}
1103
1114
1104
- let mut onion_format_optional_features = NodeFeatures :: empty ( ) ;
1105
- onion_format_optional_features. set_variable_length_onion_optional ( ) ;
1115
+ let default_node_features = default_node_features ( ) ;
1106
1116
1107
1117
// Find ways (channels with destination) to reach a given node and store them
1108
1118
// in the corresponding data structures (routing graph etc).
@@ -1134,7 +1144,7 @@ where L::Target: Logger {
1134
1144
let features = if let Some ( node_info) = $node. announcement_info. as_ref( ) {
1135
1145
& node_info. features
1136
1146
} else {
1137
- & onion_format_optional_features
1147
+ & default_node_features
1138
1148
} ;
1139
1149
1140
1150
if !features. requires_unknown_bits( ) {
@@ -1314,7 +1324,7 @@ where L::Target: Logger {
1314
1324
// traversing the graph and arrange the path out of what we found.
1315
1325
if node_id == our_node_id {
1316
1326
let mut new_entry = dist. remove ( & our_node_id) . unwrap ( ) ;
1317
- let mut ordered_hops = vec ! ( ( new_entry. clone( ) , onion_format_optional_features . clone( ) ) ) ;
1327
+ let mut ordered_hops = vec ! ( ( new_entry. clone( ) , default_node_features . clone( ) ) ) ;
1318
1328
1319
1329
' path_walk: loop {
1320
1330
let mut features_set = false ;
@@ -1332,7 +1342,7 @@ where L::Target: Logger {
1332
1342
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
1333
1343
ordered_hops. last_mut ( ) . unwrap ( ) . 1 = node_info. features . clone ( ) ;
1334
1344
} else {
1335
- ordered_hops. last_mut ( ) . unwrap ( ) . 1 = onion_format_optional_features . clone ( ) ;
1345
+ ordered_hops. last_mut ( ) . unwrap ( ) . 1 = default_node_features . clone ( ) ;
1336
1346
}
1337
1347
} else {
1338
1348
// We can fill in features for everything except hops which were
@@ -1359,7 +1369,7 @@ where L::Target: Logger {
1359
1369
// so that fees paid for a HTLC forwarding on the current channel are
1360
1370
// associated with the previous channel (where they will be subtracted).
1361
1371
ordered_hops. last_mut ( ) . unwrap ( ) . 0 . fee_msat = new_entry. hop_use_fee_msat ;
1362
- ordered_hops. push ( ( new_entry. clone ( ) , onion_format_optional_features . clone ( ) ) ) ;
1372
+ ordered_hops. push ( ( new_entry. clone ( ) , default_node_features . clone ( ) ) ) ;
1363
1373
}
1364
1374
ordered_hops. last_mut ( ) . unwrap ( ) . 0 . fee_msat = value_contribution_msat;
1365
1375
ordered_hops. last_mut ( ) . unwrap ( ) . 0 . hop_use_fee_msat = 0 ;
@@ -1686,7 +1696,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
1686
1696
#[ cfg( test) ]
1687
1697
mod tests {
1688
1698
use routing:: network_graph:: { NetworkGraph , NetGraphMsgHandler , NodeId } ;
1689
- use routing:: router:: { get_route, add_random_cltv_offset, PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees , DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA } ;
1699
+ use routing:: router:: { get_route, add_random_cltv_offset, default_node_features , PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees , DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA } ;
1690
1700
use routing:: scoring:: Score ;
1691
1701
use chain:: transaction:: OutPoint ;
1692
1702
use chain:: keysinterface:: KeysInterface ;
@@ -1847,10 +1857,6 @@ mod tests {
1847
1857
}
1848
1858
}
1849
1859
1850
- fn default_onion_format_flags ( ) -> Vec < u8 > {
1851
- vec ! [ 0 , 2 ]
1852
- }
1853
-
1854
1860
fn build_graph ( ) -> (
1855
1861
Secp256k1 < All > ,
1856
1862
sync:: Arc < NetworkGraph > ,
@@ -2791,7 +2797,7 @@ mod tests {
2791
2797
assert_eq ! ( route. paths[ 0 ] [ 4 ] . short_channel_id, 8 ) ;
2792
2798
assert_eq ! ( route. paths[ 0 ] [ 4 ] . fee_msat, 100 ) ;
2793
2799
assert_eq ! ( route. paths[ 0 ] [ 4 ] . cltv_expiry_delta, 42 ) ;
2794
- assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
2800
+ assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
2795
2801
assert_eq ! ( route. paths[ 0 ] [ 4 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
2796
2802
}
2797
2803
@@ -2867,7 +2873,7 @@ mod tests {
2867
2873
assert_eq ! ( route. paths[ 0 ] [ 4 ] . short_channel_id, 8 ) ;
2868
2874
assert_eq ! ( route. paths[ 0 ] [ 4 ] . fee_msat, 100 ) ;
2869
2875
assert_eq ! ( route. paths[ 0 ] [ 4 ] . cltv_expiry_delta, 42 ) ;
2870
- assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
2876
+ assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
2871
2877
assert_eq ! ( route. paths[ 0 ] [ 4 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
2872
2878
}
2873
2879
@@ -2964,7 +2970,7 @@ mod tests {
2964
2970
assert_eq ! ( route. paths[ 0 ] [ 3 ] . short_channel_id, last_hops[ 0 ] . 0 [ 1 ] . short_channel_id) ;
2965
2971
assert_eq ! ( route. paths[ 0 ] [ 3 ] . fee_msat, 100 ) ;
2966
2972
assert_eq ! ( route. paths[ 0 ] [ 3 ] . cltv_expiry_delta, 42 ) ;
2967
- assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , & vec! [ 0 , 2 ] ) ; // We dont pass flags in from invoices yet
2973
+ assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
2968
2974
assert_eq ! ( route. paths[ 0 ] [ 3 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
2969
2975
}
2970
2976
@@ -3029,14 +3035,14 @@ mod tests {
3029
3035
assert_eq ! ( route. paths[ 0 ] [ 2 ] . short_channel_id, last_hops[ 0 ] . 0 [ 0 ] . short_channel_id) ;
3030
3036
assert_eq ! ( route. paths[ 0 ] [ 2 ] . fee_msat, 0 ) ;
3031
3037
assert_eq ! ( route. paths[ 0 ] [ 2 ] . cltv_expiry_delta, 129 ) ;
3032
- assert_eq ! ( route. paths[ 0 ] [ 2 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3038
+ assert_eq ! ( route. paths[ 0 ] [ 2 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3033
3039
assert_eq ! ( route. paths[ 0 ] [ 2 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3034
3040
3035
3041
assert_eq ! ( route. paths[ 0 ] [ 3 ] . pubkey, nodes[ 6 ] ) ;
3036
3042
assert_eq ! ( route. paths[ 0 ] [ 3 ] . short_channel_id, last_hops[ 0 ] . 0 [ 1 ] . short_channel_id) ;
3037
3043
assert_eq ! ( route. paths[ 0 ] [ 3 ] . fee_msat, 100 ) ;
3038
3044
assert_eq ! ( route. paths[ 0 ] [ 3 ] . cltv_expiry_delta, 42 ) ;
3039
- assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3045
+ assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3040
3046
assert_eq ! ( route. paths[ 0 ] [ 3 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3041
3047
}
3042
3048
@@ -3127,7 +3133,7 @@ mod tests {
3127
3133
assert_eq ! ( route. paths[ 0 ] [ 4 ] . short_channel_id, 8 ) ;
3128
3134
assert_eq ! ( route. paths[ 0 ] [ 4 ] . fee_msat, 100 ) ;
3129
3135
assert_eq ! ( route. paths[ 0 ] [ 4 ] . cltv_expiry_delta, 42 ) ;
3130
- assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3136
+ assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3131
3137
assert_eq ! ( route. paths[ 0 ] [ 4 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3132
3138
}
3133
3139
@@ -3157,7 +3163,7 @@ mod tests {
3157
3163
assert_eq ! ( route. paths[ 0 ] [ 1 ] . short_channel_id, 8 ) ;
3158
3164
assert_eq ! ( route. paths[ 0 ] [ 1 ] . fee_msat, 100 ) ;
3159
3165
assert_eq ! ( route. paths[ 0 ] [ 1 ] . cltv_expiry_delta, 42 ) ;
3160
- assert_eq ! ( route. paths[ 0 ] [ 1 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3166
+ assert_eq ! ( route. paths[ 0 ] [ 1 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3161
3167
assert_eq ! ( route. paths[ 0 ] [ 1 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3162
3168
3163
3169
last_hops[ 0 ] . 0 [ 0 ] . fees . base_msat = 1000 ;
@@ -3194,7 +3200,7 @@ mod tests {
3194
3200
assert_eq ! ( route. paths[ 0 ] [ 3 ] . short_channel_id, 10 ) ;
3195
3201
assert_eq ! ( route. paths[ 0 ] [ 3 ] . fee_msat, 100 ) ;
3196
3202
assert_eq ! ( route. paths[ 0 ] [ 3 ] . cltv_expiry_delta, 42 ) ;
3197
- assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3203
+ assert_eq ! ( route. paths[ 0 ] [ 3 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3198
3204
assert_eq ! ( route. paths[ 0 ] [ 3 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3199
3205
3200
3206
// ...but still use 8 for larger payments as 6 has a variable feerate
@@ -3235,7 +3241,7 @@ mod tests {
3235
3241
assert_eq ! ( route. paths[ 0 ] [ 4 ] . short_channel_id, 8 ) ;
3236
3242
assert_eq ! ( route. paths[ 0 ] [ 4 ] . fee_msat, 2000 ) ;
3237
3243
assert_eq ! ( route. paths[ 0 ] [ 4 ] . cltv_expiry_delta, 42 ) ;
3238
- assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3244
+ assert_eq ! ( route. paths[ 0 ] [ 4 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3239
3245
assert_eq ! ( route. paths[ 0 ] [ 4 ] . channel_features. le_flags( ) , & Vec :: <u8 >:: new( ) ) ; // We can't learn any flags from invoices, sadly
3240
3246
}
3241
3247
@@ -3287,7 +3293,7 @@ mod tests {
3287
3293
assert_eq ! ( route. paths[ 0 ] [ 1 ] . short_channel_id, 8 ) ;
3288
3294
assert_eq ! ( route. paths[ 0 ] [ 1 ] . fee_msat, 1000000 ) ;
3289
3295
assert_eq ! ( route. paths[ 0 ] [ 1 ] . cltv_expiry_delta, 42 ) ;
3290
- assert_eq ! ( route. paths[ 0 ] [ 1 ] . node_features. le_flags( ) , & default_onion_format_flags ( ) ) ; // We dont pass flags in from invoices yet
3296
+ assert_eq ! ( route. paths[ 0 ] [ 1 ] . node_features. le_flags( ) , default_node_features ( ) . le_flags ( ) ) ; // We dont pass flags in from invoices yet
3291
3297
assert_eq ! ( route. paths[ 0 ] [ 1 ] . channel_features. le_flags( ) , & [ 0 ; 0 ] ) ; // We can't learn any flags from invoices, sadly
3292
3298
}
3293
3299
0 commit comments