Skip to content

Commit c896461

Browse files
authored
Merge pull request #827 from TheBlueMatt/2021-03-invoice-features
Disable MPP routing when the payee does not support it
2 parents 2cb655b + b9fef85 commit c896461

File tree

8 files changed

+255
-149
lines changed

8 files changed

+255
-149
lines changed

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
414414
},
415415
4 => {
416416
let value = slice_to_be24(get_slice!(3)) as u64;
417-
let route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
417+
let route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, None, &Vec::new(), value, 42, Arc::clone(&logger)) {
418418
Ok(route) => route,
419419
Err(_) => return,
420420
};
@@ -431,7 +431,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
431431
},
432432
15 => {
433433
let value = slice_to_be24(get_slice!(3)) as u64;
434-
let mut route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
434+
let mut route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, None, &Vec::new(), value, 42, Arc::clone(&logger)) {
435435
Ok(route) => route,
436436
Err(_) => return,
437437
};

fuzz/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
238238
}
239239
let last_hops = &last_hops_vec[..];
240240
for target in node_pks.iter() {
241-
let _ = get_route(&our_pubkey, &net_graph, target,
241+
let _ = get_route(&our_pubkey, &net_graph, target, None,
242242
first_hops.map(|c| c.iter().collect::<Vec<_>>()).as_ref().map(|a| a.as_slice()),
243243
&last_hops.iter().collect::<Vec<_>>(),
244244
slice_to_be64(get_slice!(8)), slice_to_be32(get_slice!(4)), Arc::clone(&logger));

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

lightning/src/ln/features.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ mod sealed {
140140
required_features: [],
141141
optional_features: [],
142142
});
143+
define_context!(InvoiceContext {
144+
required_features: [,,,],
145+
optional_features: [
146+
// Byte 0
147+
,
148+
// Byte 1
149+
VariableLengthOnion | PaymentSecret,
150+
// Byte 2
151+
BasicMPP,
152+
],
153+
});
143154

144155
/// Defines a feature with the given bits for the specified [`Context`]s. The generated trait is
145156
/// useful for manipulating feature flags.
@@ -252,13 +263,13 @@ mod sealed {
252263
"Feature flags for `option_upfront_shutdown_script`.");
253264
define_feature!(7, GossipQueries, [InitContext, NodeContext],
254265
"Feature flags for `gossip_queries`.");
255-
define_feature!(9, VariableLengthOnion, [InitContext, NodeContext],
266+
define_feature!(9, VariableLengthOnion, [InitContext, NodeContext, InvoiceContext],
256267
"Feature flags for `var_onion_optin`.");
257268
define_feature!(13, StaticRemoteKey, [InitContext, NodeContext],
258269
"Feature flags for `option_static_remotekey`.");
259-
define_feature!(15, PaymentSecret, [InitContext, NodeContext],
270+
define_feature!(15, PaymentSecret, [InitContext, NodeContext, InvoiceContext],
260271
"Feature flags for `payment_secret`.");
261-
define_feature!(17, BasicMPP, [InitContext, NodeContext],
272+
define_feature!(17, BasicMPP, [InitContext, NodeContext, InvoiceContext],
262273
"Feature flags for `basic_mpp`.");
263274
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
264275
"Feature flags for `opt_shutdown_anysegwit`.");
@@ -323,6 +334,8 @@ pub type InitFeatures = Features<sealed::InitContext>;
323334
pub type NodeFeatures = Features<sealed::NodeContext>;
324335
/// Features used within a `channel_announcement` message.
325336
pub type ChannelFeatures = Features<sealed::ChannelContext>;
337+
/// Features used within an invoice.
338+
pub type InvoiceFeatures = Features<sealed::InvoiceContext>;
326339

327340
impl InitFeatures {
328341
/// Writes all features present up to, and including, 13.
@@ -359,6 +372,14 @@ impl InitFeatures {
359372
}
360373
}
361374

375+
impl InvoiceFeatures {
376+
/// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
377+
/// context `C` are included in the result.
378+
pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
379+
self.to_context_internal()
380+
}
381+
}
382+
362383
impl<T: sealed::Context> Features<T> {
363384
/// Create a blank Features with no features set
364385
pub fn empty() -> Self {
@@ -553,7 +574,6 @@ impl<T: sealed::BasicMPP> Features<T> {
553574
<T as sealed::BasicMPP>::requires_feature(&self.flags)
554575
}
555576
// We currently never test for this since we don't actually *generate* multipath routes.
556-
#[allow(dead_code)]
557577
pub(crate) fn supports_basic_mpp(&self) -> bool {
558578
<T as sealed::BasicMPP>::supports_feature(&self.flags)
559579
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ pub const TEST_FINAL_CLTV: u32 = 32;
10251025
pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash) {
10261026
let net_graph_msg_handler = &origin_node.net_graph_msg_handler;
10271027
let logger = test_utils::TestLogger::new();
1028-
let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
1028+
let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
10291029
assert_eq!(route.paths.len(), 1);
10301030
assert_eq!(route.paths[0].len(), expected_route.len());
10311031
for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {
@@ -1038,7 +1038,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
10381038
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
10391039
let logger = test_utils::TestLogger::new();
10401040
let net_graph_msg_handler = &origin_node.net_graph_msg_handler;
1041-
let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
1041+
let route = get_route(&origin_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), None, None, &Vec::new(), recv_value, TEST_FINAL_CLTV, &logger).unwrap();
10421042
assert_eq!(route.paths.len(), 1);
10431043
assert_eq!(route.paths[0].len(), expected_route.len());
10441044
for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {

0 commit comments

Comments
 (0)