Skip to content

Commit 32f98e4

Browse files
Support pathfinding to blinded routes
1 parent 54f8895 commit 32f98e4

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lightning/src/routing/router.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use bitcoin::secp256k1::PublicKey;
1313
use bitcoin::hashes::Hash;
1414
use bitcoin::hashes::sha256::Hash as Sha256;
1515

16+
use crate::offers::invoice::BlindedPayInfo;
1617
use crate::ln::PaymentHash;
1718
use crate::ln::channelmanager::{ChannelDetails, PaymentId};
1819
use crate::ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
1920
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
21+
use crate::onion_message::BlindedPath;
2022
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
2123
use crate::routing::scoring::{ChannelUsage, LockableScore, Score};
2224
use crate::util::ser::{Writeable, Readable, ReadableArgs, Writer};
@@ -543,6 +545,24 @@ impl PaymentParameters {
543545
Self { route_hints, ..self }
544546
}
545547

548+
/// Includes hints for routing to a payee who is being paid to via `BlindedPath`s for privacy.
549+
pub fn with_blinded_route_hints(self, blinded_paths: Vec<(BlindedPath, BlindedPayInfo)>) -> Self {
550+
let route_hints = blinded_paths.into_iter().map(|(path, payinfo)| {
551+
RouteHint(vec![RouteHintHop {
552+
src_node_id: path.introduction_node_id,
553+
short_channel_id: 0, // TODO is this too weird?
554+
fees: RoutingFees {
555+
base_msat: payinfo.fee_base_msat,
556+
proportional_millionths: payinfo.fee_proportional_millionths,
557+
},
558+
cltv_expiry_delta: payinfo.cltv_expiry_delta,
559+
htlc_minimum_msat: Some(payinfo.htlc_minimum_msat),
560+
htlc_maximum_msat: Some(payinfo.htlc_maximum_msat),
561+
}])
562+
}).collect();
563+
Self { route_hints, ..self }
564+
}
565+
546566
/// Includes a payment expiration in seconds relative to the UNIX epoch.
547567
///
548568
/// (C-not exported) since bindings don't support move semantics
@@ -600,11 +620,17 @@ impl Readable for RouteHint {
600620
/// A channel descriptor for a hop along a payment path.
601621
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
602622
pub struct RouteHintHop {
603-
/// The node_id of the non-target end of the route
623+
/// The node_id of the non-target end of the route. May be the introduction node id of a
624+
/// [`BlindedPath`].
625+
///
626+
/// [`BlindedPath`]: crate::onion_message::BlindedPath
604627
pub src_node_id: PublicKey,
605-
/// The short_channel_id of this channel
628+
/// The short_channel_id of this channel. May be 0 if this route hint corresponds to a
629+
/// [`BlindedPath`].
630+
///
631+
/// [`BlindedPath`]: crate::onion_message::BlindedPath
606632
pub short_channel_id: u64,
607-
/// The fees which must be paid to use this channel
633+
/// The fees which must be paid to use this channel or blinded path.
608634
pub fees: RoutingFees,
609635
/// The difference in CLTV values between this node and the next node.
610636
pub cltv_expiry_delta: u16,

0 commit comments

Comments
 (0)