Skip to content

Commit ef0f249

Browse files
committed
Disable MPP routing when the payee does not support it
1 parent 9e57364 commit ef0f249

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-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: 27 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,9 @@ 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, MPP will only be used if the payee's features are available in the network graph.
319+
///
317320
/// Extra routing hops between known nodes and the target will be used if they are included in
318321
/// last_hops.
319322
///
@@ -396,6 +399,17 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
396399
const ROUTE_CAPACITY_PROVISION_FACTOR: u64 = 3;
397400
let recommended_value_msat = final_value_msat * ROUTE_CAPACITY_PROVISION_FACTOR as u64;
398401

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

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;
501+
// Derive the minimal liquidity contribution with a ratio of 20 (5%, rounded up)
502+
// or 100% if we're not allowed to do multipath payments.
503+
let minimal_value_contribution_msat: u64 = if allow_mpp {
504+
(recommended_value_msat - already_collected_value_msat + 19) / 20
505+
} else {
506+
final_value_msat
507+
};
489508
// Verify the liquidity offered by this channel complies to the minimal contribution.
490509
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
491510

@@ -866,6 +885,11 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
866885
}
867886
}
868887

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

0 commit comments

Comments
 (0)