Skip to content

Commit ea506e3

Browse files
f Fix features assignment and naming
1 parent 18557ce commit ea506e3

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

lightning/src/routing/router.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,17 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> {
602602
}
603603
}
604604

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+
605616
/// Finds a route from us (payer) to the given target node (payee).
606617
///
607618
/// If the payee provided features in their invoice, they should be provided via `params.payee`.
@@ -1101,8 +1112,7 @@ where L::Target: Logger {
11011112
} }
11021113
}
11031114

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();
11061116

11071117
// Find ways (channels with destination) to reach a given node and store them
11081118
// in the corresponding data structures (routing graph etc).
@@ -1134,7 +1144,7 @@ where L::Target: Logger {
11341144
let features = if let Some(node_info) = $node.announcement_info.as_ref() {
11351145
&node_info.features
11361146
} else {
1137-
&onion_format_optional_features
1147+
&default_node_features
11381148
};
11391149

11401150
if !features.requires_unknown_bits() {
@@ -1314,7 +1324,7 @@ where L::Target: Logger {
13141324
// traversing the graph and arrange the path out of what we found.
13151325
if node_id == our_node_id {
13161326
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()));
13181328

13191329
'path_walk: loop {
13201330
let mut features_set = false;
@@ -1332,7 +1342,7 @@ where L::Target: Logger {
13321342
if let Some(node_info) = node.announcement_info.as_ref() {
13331343
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
13341344
} else {
1335-
ordered_hops.last_mut().unwrap().1 = onion_format_optional_features.clone();
1345+
ordered_hops.last_mut().unwrap().1 = default_node_features.clone();
13361346
}
13371347
} else {
13381348
// We can fill in features for everything except hops which were
@@ -1359,7 +1369,7 @@ where L::Target: Logger {
13591369
// so that fees paid for a HTLC forwarding on the current channel are
13601370
// associated with the previous channel (where they will be subtracted).
13611371
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()));
13631373
}
13641374
ordered_hops.last_mut().unwrap().0.fee_msat = value_contribution_msat;
13651375
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,
16861696
#[cfg(test)]
16871697
mod tests {
16881698
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};
16901700
use routing::scoring::Score;
16911701
use chain::transaction::OutPoint;
16921702
use chain::keysinterface::KeysInterface;
@@ -1847,10 +1857,6 @@ mod tests {
18471857
}
18481858
}
18491859

1850-
fn default_onion_format_flags() -> Vec<u8> {
1851-
vec![0, 2]
1852-
}
1853-
18541860
fn build_graph() -> (
18551861
Secp256k1<All>,
18561862
sync::Arc<NetworkGraph>,
@@ -2791,7 +2797,7 @@ mod tests {
27912797
assert_eq!(route.paths[0][4].short_channel_id, 8);
27922798
assert_eq!(route.paths[0][4].fee_msat, 100);
27932799
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
27952801
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
27962802
}
27972803

@@ -2867,7 +2873,7 @@ mod tests {
28672873
assert_eq!(route.paths[0][4].short_channel_id, 8);
28682874
assert_eq!(route.paths[0][4].fee_msat, 100);
28692875
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
28712877
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
28722878
}
28732879

@@ -2964,7 +2970,7 @@ mod tests {
29642970
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
29652971
assert_eq!(route.paths[0][3].fee_msat, 100);
29662972
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
29682974
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
29692975
}
29702976

@@ -3029,14 +3035,14 @@ mod tests {
30293035
assert_eq!(route.paths[0][2].short_channel_id, last_hops[0].0[0].short_channel_id);
30303036
assert_eq!(route.paths[0][2].fee_msat, 0);
30313037
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
30333039
assert_eq!(route.paths[0][2].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30343040

30353041
assert_eq!(route.paths[0][3].pubkey, nodes[6]);
30363042
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
30373043
assert_eq!(route.paths[0][3].fee_msat, 100);
30383044
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
30403046
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30413047
}
30423048

@@ -3127,7 +3133,7 @@ mod tests {
31273133
assert_eq!(route.paths[0][4].short_channel_id, 8);
31283134
assert_eq!(route.paths[0][4].fee_msat, 100);
31293135
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
31313137
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31323138
}
31333139

@@ -3157,7 +3163,7 @@ mod tests {
31573163
assert_eq!(route.paths[0][1].short_channel_id, 8);
31583164
assert_eq!(route.paths[0][1].fee_msat, 100);
31593165
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
31613167
assert_eq!(route.paths[0][1].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31623168

31633169
last_hops[0].0[0].fees.base_msat = 1000;
@@ -3194,7 +3200,7 @@ mod tests {
31943200
assert_eq!(route.paths[0][3].short_channel_id, 10);
31953201
assert_eq!(route.paths[0][3].fee_msat, 100);
31963202
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
31983204
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31993205

32003206
// ...but still use 8 for larger payments as 6 has a variable feerate
@@ -3235,7 +3241,7 @@ mod tests {
32353241
assert_eq!(route.paths[0][4].short_channel_id, 8);
32363242
assert_eq!(route.paths[0][4].fee_msat, 2000);
32373243
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
32393245
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
32403246
}
32413247

@@ -3287,7 +3293,7 @@ mod tests {
32873293
assert_eq!(route.paths[0][1].short_channel_id, 8);
32883294
assert_eq!(route.paths[0][1].fee_msat, 1000000);
32893295
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
32913297
assert_eq!(route.paths[0][1].channel_features.le_flags(), &[0; 0]); // We can't learn any flags from invoices, sadly
32923298
}
32933299

0 commit comments

Comments
 (0)