Skip to content

Commit 5e8062d

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 5e8062d

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lightning/src/routing/router.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,9 @@ where L::Target: Logger {
11011101
} }
11021102
}
11031103

1104-
let empty_node_features = NodeFeatures::empty();
1104+
let mut onion_format_optional_features = NodeFeatures::empty();
1105+
onion_format_optional_features.set_variable_length_onion_optional();
1106+
11051107
// Find ways (channels with destination) to reach a given node and store them
11061108
// in the corresponding data structures (routing graph etc).
11071109
// $fee_to_target_msat represents how much it costs to reach to this node from the payee,
@@ -1132,7 +1134,7 @@ where L::Target: Logger {
11321134
let features = if let Some(node_info) = $node.announcement_info.as_ref() {
11331135
&node_info.features
11341136
} else {
1135-
&empty_node_features
1137+
&onion_format_optional_features
11361138
};
11371139

11381140
if !features.requires_unknown_bits() {
@@ -1312,7 +1314,7 @@ where L::Target: Logger {
13121314
// traversing the graph and arrange the path out of what we found.
13131315
if node_id == our_node_id {
13141316
let mut new_entry = dist.remove(&our_node_id).unwrap();
1315-
let mut ordered_hops = vec!((new_entry.clone(), NodeFeatures::empty()));
1317+
let mut ordered_hops = vec!((new_entry.clone(), onion_format_optional_features.clone()));
13161318

13171319
'path_walk: loop {
13181320
let mut features_set = false;
@@ -1330,7 +1332,7 @@ where L::Target: Logger {
13301332
if let Some(node_info) = node.announcement_info.as_ref() {
13311333
ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
13321334
} else {
1333-
ordered_hops.last_mut().unwrap().1 = NodeFeatures::empty();
1335+
ordered_hops.last_mut().unwrap().1 = onion_format_optional_features.clone();
13341336
}
13351337
} else {
13361338
// We can fill in features for everything except hops which were
@@ -1357,7 +1359,7 @@ where L::Target: Logger {
13571359
// so that fees paid for a HTLC forwarding on the current channel are
13581360
// associated with the previous channel (where they will be subtracted).
13591361
ordered_hops.last_mut().unwrap().0.fee_msat = new_entry.hop_use_fee_msat;
1360-
ordered_hops.push((new_entry.clone(), NodeFeatures::empty()));
1362+
ordered_hops.push((new_entry.clone(), onion_format_optional_features.clone()));
13611363
}
13621364
ordered_hops.last_mut().unwrap().0.fee_msat = value_contribution_msat;
13631365
ordered_hops.last_mut().unwrap().0.hop_use_fee_msat = 0;
@@ -1845,6 +1847,10 @@ mod tests {
18451847
}
18461848
}
18471849

1850+
fn default_onion_format_flags() -> Vec<u8> {
1851+
vec![0, 2]
1852+
}
1853+
18481854
fn build_graph() -> (
18491855
Secp256k1<All>,
18501856
sync::Arc<NetworkGraph>,
@@ -2785,7 +2791,7 @@ mod tests {
27852791
assert_eq!(route.paths[0][4].short_channel_id, 8);
27862792
assert_eq!(route.paths[0][4].fee_msat, 100);
27872793
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
2794+
assert_eq!(route.paths[0][4].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
27892795
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
27902796
}
27912797

@@ -2861,7 +2867,7 @@ mod tests {
28612867
assert_eq!(route.paths[0][4].short_channel_id, 8);
28622868
assert_eq!(route.paths[0][4].fee_msat, 100);
28632869
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
2870+
assert_eq!(route.paths[0][4].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
28652871
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
28662872
}
28672873

@@ -2958,7 +2964,7 @@ mod tests {
29582964
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
29592965
assert_eq!(route.paths[0][3].fee_msat, 100);
29602966
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
2967+
assert_eq!(route.paths[0][3].node_features.le_flags(), &vec![0, 2]); // We dont pass flags in from invoices yet
29622968
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
29632969
}
29642970

@@ -3023,14 +3029,14 @@ mod tests {
30233029
assert_eq!(route.paths[0][2].short_channel_id, last_hops[0].0[0].short_channel_id);
30243030
assert_eq!(route.paths[0][2].fee_msat, 0);
30253031
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
3032+
assert_eq!(route.paths[0][2].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
30273033
assert_eq!(route.paths[0][2].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30283034

30293035
assert_eq!(route.paths[0][3].pubkey, nodes[6]);
30303036
assert_eq!(route.paths[0][3].short_channel_id, last_hops[0].0[1].short_channel_id);
30313037
assert_eq!(route.paths[0][3].fee_msat, 100);
30323038
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
3039+
assert_eq!(route.paths[0][3].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
30343040
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
30353041
}
30363042

@@ -3121,7 +3127,7 @@ mod tests {
31213127
assert_eq!(route.paths[0][4].short_channel_id, 8);
31223128
assert_eq!(route.paths[0][4].fee_msat, 100);
31233129
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
3130+
assert_eq!(route.paths[0][4].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
31253131
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31263132
}
31273133

@@ -3151,7 +3157,7 @@ mod tests {
31513157
assert_eq!(route.paths[0][1].short_channel_id, 8);
31523158
assert_eq!(route.paths[0][1].fee_msat, 100);
31533159
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
3160+
assert_eq!(route.paths[0][1].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
31553161
assert_eq!(route.paths[0][1].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31563162

31573163
last_hops[0].0[0].fees.base_msat = 1000;
@@ -3188,7 +3194,7 @@ mod tests {
31883194
assert_eq!(route.paths[0][3].short_channel_id, 10);
31893195
assert_eq!(route.paths[0][3].fee_msat, 100);
31903196
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
3197+
assert_eq!(route.paths[0][3].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
31923198
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
31933199

31943200
// ...but still use 8 for larger payments as 6 has a variable feerate
@@ -3229,7 +3235,7 @@ mod tests {
32293235
assert_eq!(route.paths[0][4].short_channel_id, 8);
32303236
assert_eq!(route.paths[0][4].fee_msat, 2000);
32313237
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
3238+
assert_eq!(route.paths[0][4].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
32333239
assert_eq!(route.paths[0][4].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
32343240
}
32353241

@@ -3281,7 +3287,7 @@ mod tests {
32813287
assert_eq!(route.paths[0][1].short_channel_id, 8);
32823288
assert_eq!(route.paths[0][1].fee_msat, 1000000);
32833289
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
3290+
assert_eq!(route.paths[0][1].node_features.le_flags(), &default_onion_format_flags()); // We dont pass flags in from invoices yet
32853291
assert_eq!(route.paths[0][1].channel_features.le_flags(), &[0; 0]); // We can't learn any flags from invoices, sadly
32863292
}
32873293

0 commit comments

Comments
 (0)