Skip to content

Commit 800d82e

Browse files
committed
Disable MPP routing when the payee does not support it
1 parent cbe4e8a commit 800d82e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lightning/src/ln/features.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ impl<T: sealed::BasicMPP> Features<T> {
574574
<T as sealed::BasicMPP>::requires_feature(&self.flags)
575575
}
576576
// We currently never test for this since we don't actually *generate* multipath routes.
577-
#[allow(dead_code)]
578577
pub(crate) fn supports_basic_mpp(&self) -> bool {
579578
<T as sealed::BasicMPP>::supports_feature(&self.flags)
580579
}

lightning/src/routing/router.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use bitcoin::secp256k1::key::PublicKey;
1616

1717
use ln::channelmanager::ChannelDetails;
18-
use ln::features::{ChannelFeatures, NodeFeatures, InvoiceFeatures};
18+
use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
1919
use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2020
use routing::network_graph::{NetworkGraph, RoutingFees};
2121
use util::ser::{Writeable, Readable};
@@ -314,6 +314,10 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> {
314314

315315
/// Gets a route from us (payer) to the given target node (payee).
316316
///
317+
/// If the payee provided features in their invoice, they should be provided via payee_features.
318+
/// Without this, any knowledge we have of the payee's features may be used if they are available
319+
/// in the network graph, however MPP routing will be disabled and routing is more likely to fail.
320+
///
317321
/// Extra routing hops between known nodes and the target will be used if they are included in
318322
/// last_hops.
319323
///
@@ -396,6 +400,17 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
396400
const ROUTE_CAPACITY_PROVISION_FACTOR: u64 = 3;
397401
let recommended_value_msat = final_value_msat * ROUTE_CAPACITY_PROVISION_FACTOR as u64;
398402

403+
// Allow MPP only if we have a features set from somewhere that indicates the payee supports
404+
// it. If the payee supports it they're supposed to include it in the invoice, so that should
405+
// work reliably.
406+
let allow_mpp = if let Some(features) = &payee_features {
407+
features.supports_basic_mpp()
408+
} else if let Some(node) = network.get_nodes().get(&payee) {
409+
if let Some(node_info) = node.announcement_info.as_ref() {
410+
node_info.features.supports_basic_mpp()
411+
} else { false }
412+
} else { false };
413+
399414
// Step (1).
400415
// Prepare the data we'll use for payee-to-payer search by
401416
// inserting first hops suggested by the caller as targets.
@@ -484,8 +499,13 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
484499
// the absolute liquidity contribution is lowered,
485500
// thus increasing the number of potential channels to be selected.
486501

487-
// Derive the minimal liquidity contribution with a ratio of 20 (5%, rounded up).
488-
let minimal_value_contribution_msat: u64 = (recommended_value_msat - already_collected_value_msat + 19) / 20;
502+
// Derive the minimal liquidity contribution with a ratio of 20 (5%, rounded up)
503+
// or 100% if we're not allowed to do multipath payments.
504+
let minimal_value_contribution_msat: u64 = if allow_mpp {
505+
(recommended_value_msat - already_collected_value_msat + 19) / 20
506+
} else {
507+
final_value_msat
508+
};
489509
// Verify the liquidity offered by this channel complies to the minimal contribution.
490510
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
491511

@@ -866,6 +886,11 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
866886
}
867887
}
868888

889+
if !allow_mpp {
890+
// If we don't support MPP, no use trying to gather more value ever.
891+
break 'paths_collection;
892+
}
893+
869894
// Step (3).
870895
// Stop either when recommended value is reached,
871896
// or if during last iteration no new path was found.

0 commit comments

Comments
 (0)