|
15 | 15 | use bitcoin::secp256k1::key::PublicKey;
|
16 | 16 |
|
17 | 17 | use ln::channelmanager::ChannelDetails;
|
18 |
| -use ln::features::{ChannelFeatures, NodeFeatures, InvoiceFeatures}; |
| 18 | +use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures}; |
19 | 19 | use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
|
20 | 20 | use routing::network_graph::{NetworkGraph, RoutingFees};
|
21 | 21 | use util::ser::{Writeable, Readable};
|
@@ -314,6 +314,9 @@ fn compute_fees(amount_msat: u64, channel_fees: RoutingFees) -> Option<u64> {
|
314 | 314 |
|
315 | 315 | /// Gets a route from us (payer) to the given target node (payee).
|
316 | 316 | ///
|
| 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 | +/// |
317 | 320 | /// Extra routing hops between known nodes and the target will be used if they are included in
|
318 | 321 | /// last_hops.
|
319 | 322 | ///
|
@@ -396,6 +399,17 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
|
396 | 399 | const ROUTE_CAPACITY_PROVISION_FACTOR: u64 = 3;
|
397 | 400 | let recommended_value_msat = final_value_msat * ROUTE_CAPACITY_PROVISION_FACTOR as u64;
|
398 | 401 |
|
| 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 | + |
399 | 413 | // Step (1).
|
400 | 414 | // Prepare the data we'll use for payee-to-payer search by
|
401 | 415 | // 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
|
484 | 498 | // the absolute liquidity contribution is lowered,
|
485 | 499 | // thus increasing the number of potential channels to be selected.
|
486 | 500 |
|
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 | + }; |
489 | 508 | // Verify the liquidity offered by this channel complies to the minimal contribution.
|
490 | 509 | let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
|
491 | 510 |
|
@@ -866,6 +885,11 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
|
866 | 885 | }
|
867 | 886 | }
|
868 | 887 |
|
| 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 | + |
869 | 893 | // Step (3).
|
870 | 894 | // Stop either when recommended value is reached,
|
871 | 895 | // or if during last iteration no new path was found.
|
|
0 commit comments