Skip to content

Commit a316ef4

Browse files
Default to creating BOLT4 tlv payload format onions
Default to creating tlv onions for nodes for which we haven't received any features through node announcements or which aren't in the `network_graph`, and where no other features are known such as invoice features nor features in the init msg for nodes we have channels to.
1 parent 711bcef commit a316ef4

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

lightning/src/routing/router.rs

Lines changed: 28 additions & 16 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,7 +1112,8 @@ where L::Target: Logger {
11011112
} }
11021113
}
11031114

1104-
let empty_node_features = NodeFeatures::empty();
1115+
let default_node_features = default_node_features();
1116+
11051117
// Find ways (channels with destination) to reach a given node and store them
11061118
// in the corresponding data structures (routing graph etc).
11071119
// $fee_to_target_msat represents how much it costs to reach to this node from the payee,
@@ -1132,7 +1144,7 @@ where L::Target: Logger {
11321144
let features = if let Some(node_info) = $node.announcement_info.as_ref() {
11331145
&node_info.features
11341146
} else {
1135-
&empty_node_features
1147+
&default_node_features
11361148
};
11371149

11381150
if !features.requires_unknown_bits() {
@@ -1312,7 +1324,7 @@ where L::Target: Logger {
13121324
// traversing the graph and arrange the path out of what we found.
13131325
if node_id == our_node_id {
13141326
let mut new_entry = dist.remove(&our_node_id).unwrap();
1315-
let mut ordered_hops = vec!((new_entry.clone(), NodeFeatures::empty()));
1327+
let mut ordered_hops = vec!((new_entry.clone(), default_node_features.clone()));
13161328

13171329
'path_walk: loop {
13181330
let mut features_set = false;
@@ -1330,7 +1342,7 @@ where L::Target: Logger {
13301342
if let Some(node_info) = node.announcement_info.as_ref() {
13311343
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
13321344
} else {
1333-
ordered_hops.last_mut().unwrap().1 = NodeFeatures::empty();
1345+
ordered_hops.last_mut().unwrap().1 = default_node_features.clone();
13341346
}
13351347
} else {
13361348
// We can fill in features for everything except hops which were
@@ -1357,7 +1369,7 @@ where L::Target: Logger {
13571369
// so that fees paid for a HTLC forwarding on the current channel are
13581370
// associated with the previous channel (where they will be subtracted).
13591371
ordered_hops.last_mut().unwrap().0.fee_msat = new_entry.hop_use_fee_msat;
1360-
ordered_hops.push((new_entry.clone(), NodeFeatures::empty()));
1372+
ordered_hops.push((new_entry.clone(), default_node_features.clone()));
13611373
}
13621374
ordered_hops.last_mut().unwrap().0.fee_msat = value_contribution_msat;
13631375
ordered_hops.last_mut().unwrap().0.hop_use_fee_msat = 0;
@@ -1684,7 +1696,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
16841696
#[cfg(test)]
16851697
mod tests {
16861698
use routing::network_graph::{NetworkGraph, NetGraphMsgHandler, NodeId};
1687-
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};
16881700
use routing::scoring::Score;
16891701
use chain::transaction::OutPoint;
16901702
use chain::keysinterface::KeysInterface;
@@ -2785,7 +2797,7 @@ mod tests {
27852797
assert_eq!(route.paths[0][4].short_channel_id, 8);
27862798
assert_eq!(route.paths[0][4].fee_msat, 100);
27872799
assert_eq!(route.paths[0][4].cltv_expiry_delta, 42);
2788-
assert_eq!(route.paths[0][4].node_features.le_flags(), &Vec::<u8>::new()); // 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
27892801
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
27902802
}
27912803

@@ -2861,7 +2873,7 @@ mod tests {
28612873
assert_eq!(route.paths[0][4].short_channel_id, 8);
28622874
assert_eq!(route.paths[0][4].fee_msat, 100);
28632875
assert_eq!(route.paths[0][4].cltv_expiry_delta, 42);
2864-
assert_eq!(route.paths[0][4].node_features.le_flags(), &Vec::<u8>::new()); // 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
28652877
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
28662878
}
28672879

@@ -2958,7 +2970,7 @@ mod tests {
29582970
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
29592971
assert_eq!(route.paths[0][3].fee_msat, 100);
29602972
assert_eq!(route.paths[0][3].cltv_expiry_delta, 42);
2961-
assert_eq!(route.paths[0][3].node_features.le_flags(), &Vec::<u8>::new()); // 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
29622974
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
29632975
}
29642976

@@ -3023,14 +3035,14 @@ mod tests {
30233035
assert_eq!(route.paths[0][2].short_channel_id, last_hops[0].0[0].short_channel_id);
30243036
assert_eq!(route.paths[0][2].fee_msat, 0);
30253037
assert_eq!(route.paths[0][2].cltv_expiry_delta, 129);
3026-
assert_eq!(route.paths[0][2].node_features.le_flags(), &Vec::<u8>::new()); // 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
30273039
assert_eq!(route.paths[0][2].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30283040

30293041
assert_eq!(route.paths[0][3].pubkey, nodes[6]);
30303042
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
30313043
assert_eq!(route.paths[0][3].fee_msat, 100);
30323044
assert_eq!(route.paths[0][3].cltv_expiry_delta, 42);
3033-
assert_eq!(route.paths[0][3].node_features.le_flags(), &Vec::<u8>::new()); // 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
30343046
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30353047
}
30363048

@@ -3121,7 +3133,7 @@ mod tests {
31213133
assert_eq!(route.paths[0][4].short_channel_id, 8);
31223134
assert_eq!(route.paths[0][4].fee_msat, 100);
31233135
assert_eq!(route.paths[0][4].cltv_expiry_delta, 42);
3124-
assert_eq!(route.paths[0][4].node_features.le_flags(), &Vec::<u8>::new()); // 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
31253137
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31263138
}
31273139

@@ -3151,7 +3163,7 @@ mod tests {
31513163
assert_eq!(route.paths[0][1].short_channel_id, 8);
31523164
assert_eq!(route.paths[0][1].fee_msat, 100);
31533165
assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
3154-
assert_eq!(route.paths[0][1].node_features.le_flags(), &Vec::<u8>::new()); // 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
31553167
assert_eq!(route.paths[0][1].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31563168

31573169
last_hops[0].0[0].fees.base_msat = 1000;
@@ -3188,7 +3200,7 @@ mod tests {
31883200
assert_eq!(route.paths[0][3].short_channel_id, 10);
31893201
assert_eq!(route.paths[0][3].fee_msat, 100);
31903202
assert_eq!(route.paths[0][3].cltv_expiry_delta, 42);
3191-
assert_eq!(route.paths[0][3].node_features.le_flags(), &Vec::<u8>::new()); // 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
31923204
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31933205

31943206
// ...but still use 8 for larger payments as 6 has a variable feerate
@@ -3229,7 +3241,7 @@ mod tests {
32293241
assert_eq!(route.paths[0][4].short_channel_id, 8);
32303242
assert_eq!(route.paths[0][4].fee_msat, 2000);
32313243
assert_eq!(route.paths[0][4].cltv_expiry_delta, 42);
3232-
assert_eq!(route.paths[0][4].node_features.le_flags(), &Vec::<u8>::new()); // 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
32333245
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
32343246
}
32353247

@@ -3281,7 +3293,7 @@ mod tests {
32813293
assert_eq!(route.paths[0][1].short_channel_id, 8);
32823294
assert_eq!(route.paths[0][1].fee_msat, 1000000);
32833295
assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
3284-
assert_eq!(route.paths[0][1].node_features.le_flags(), &[0; 0]); // 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
32853297
assert_eq!(route.paths[0][1].channel_features.le_flags(), &[0; 0]); // We can't learn any flags from invoices, sadly
32863298
}
32873299

0 commit comments

Comments
 (0)