Skip to content

Commit 8d2d5e8

Browse files
committed
Onion message routing to immediate peers.
DefaultMessageRouter always fails. Update it so that it can route to a directly connected peer. This is needed for an Offers minimum viable product.
1 parent 612f903 commit 8d2d5e8

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7170,6 +7170,11 @@ where
71707170
/// the node must be announced. Otherwise, there is no way to find a path to the introduction
71717171
/// node in order to send the [`InvoiceRequest`].
71727172
///
7173+
/// # Limitations
7174+
///
7175+
/// Requires a direct connection to the introduction node in the responding [`InvoiceRequest`]'s
7176+
/// reply path.
7177+
///
71737178
/// [`Offer`]: crate::offers::offer::Offer
71747179
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
71757180
pub fn create_offer_builder(
@@ -7210,13 +7215,19 @@ where
72107215
/// node must be announced. Otherwise, there is no way to find a path to the introduction node
72117216
/// in order to send the [`Bolt12Invoice`].
72127217
///
7218+
/// # Limitations
7219+
///
7220+
/// Requires a direct connection to an introduction node in the responding
7221+
/// [`Bolt12Invoice::payment_paths`].
7222+
///
72137223
/// # Errors
72147224
///
72157225
/// Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link
72167226
/// or if `amount_msats` is invalid.
72177227
///
72187228
/// [`Refund`]: crate::offers::refund::Refund
72197229
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
7230+
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
72207231
pub fn create_refund_builder(
72217232
&self, description: String, amount_msats: u64, absolute_expiry: Duration,
72227233
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
@@ -7273,6 +7284,12 @@ where
72737284
/// node must be announced. Otherwise, there is no way to find a path to the introduction node
72747285
/// in order to send the [`Bolt12Invoice`].
72757286
///
7287+
/// # Limitations
7288+
///
7289+
/// Requires a direct connection to an introduction node in [`Offer::paths`] or to
7290+
/// [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding
7291+
/// [`Bolt12Invoice::payment_paths`].
7292+
///
72767293
/// # Errors
72777294
///
72787295
/// Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link
@@ -7283,6 +7300,7 @@ where
72837300
/// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
72847301
/// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
72857302
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
7303+
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
72867304
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
72877305
pub fn pay_for_offer(
72887306
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -7352,6 +7370,11 @@ where
73527370
/// [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
73537371
/// [`PaymentPreimage`].
73547372
///
7373+
/// # Limitations
7374+
///
7375+
/// Requires a direct connection to an introduction node in [`Refund::paths`] or to
7376+
/// [`Refund::payer_id`], if empty.
7377+
///
73557378
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
73567379
pub fn request_refund_payment(&self, refund: &Refund) -> Result<(), Bolt12SemanticError> {
73577380
let expanded_key = &self.inbound_payment_key;

lightning/src/onion_message/messenger.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,18 @@ pub trait MessageRouter {
177177
) -> Result<OnionMessagePath, ()>;
178178
}
179179

180-
/// A [`MessageRouter`] that always fails.
180+
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
181181
pub struct DefaultMessageRouter;
182182

183183
impl MessageRouter for DefaultMessageRouter {
184184
fn find_path(
185-
&self, _sender: PublicKey, _peers: Vec<PublicKey>, _destination: Destination
185+
&self, _sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
186186
) -> Result<OnionMessagePath, ()> {
187-
Err(())
187+
if peers.contains(&destination.first_node()) {
188+
Ok(OnionMessagePath { intermediate_nodes: vec![], destination })
189+
} else {
190+
Err(())
191+
}
188192
}
189193
}
190194

@@ -214,6 +218,13 @@ impl Destination {
214218
Destination::BlindedPath(BlindedPath { blinded_hops, .. }) => blinded_hops.len(),
215219
}
216220
}
221+
222+
fn first_node(&self) -> PublicKey {
223+
match self {
224+
Destination::Node(node_id) => *node_id,
225+
Destination::BlindedPath(BlindedPath { introduction_node_id: node_id, .. }) => *node_id,
226+
}
227+
}
217228
}
218229

219230
/// Errors that may occur when [sending an onion message].

0 commit comments

Comments
 (0)