Skip to content

Commit 0c2991f

Browse files
committed
Introduce create_blinded_paths in flow.rs
1. This allow removing an extra function from commons, simplifying the flow trait.
1 parent 7937275 commit 0c2991f

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

lightning/src/ln/channelmanager.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1;
3333
use bitcoin::{secp256k1, Sequence, Weight};
3434

3535
use crate::events::FundingInfo;
36-
use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, MessageForwardNode};
36+
use crate::blinded_path::message::{AsyncPaymentsContext, MessageForwardNode};
3737
use crate::blinded_path::NodeIdLookUp;
3838
use crate::blinded_path::message::BlindedMessagePath;
3939
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
@@ -9534,10 +9534,6 @@ where
95349534
self.pending_outbound_payments.release_invoice_requests_awaiting_invoice()
95359535
}
95369536

9537-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9538-
self.create_blinded_paths(context)
9539-
}
9540-
95419537
fn enqueue_invoice_request(&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>) -> Result<(), Bolt12SemanticError> {
95429538
self.enqueue_invoice_request(invoice_request, reply_paths)
95439539
}
@@ -9757,6 +9753,7 @@ where
97579753
/// [`MessageRouter::create_blinded_paths`].
97589754
///
97599755
/// Errors if the `MessageRouter` errors.
9756+
#[cfg(async_payments)]
97609757
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
97619758
let recipient = self.get_our_node_id();
97629759
let secp_ctx = &self.secp_ctx;

lightning/src/offers/flow.rs

+25-17
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ pub trait OffersMessageCommons {
177177
&self,
178178
) -> Vec<(PaymentId, RetryableInvoiceRequest)>;
179179

180-
/// Creates a collection of blinded paths by delegating to
181-
/// [`MessageRouter::create_blinded_paths`].
182-
///
183-
/// Errors if the `MessageRouter` errors.
184-
///
185-
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
186-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
187-
188180
/// Enqueue invoice request
189181
fn enqueue_invoice_request(
190182
&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>,
@@ -696,7 +688,7 @@ where
696688
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
697689
self.create_compact_blinded_paths(context)
698690
} else {
699-
self.commons.create_blinded_paths(MessageContext::Offers(context))
691+
self.create_blinded_paths(MessageContext::Offers(context))
700692
}
701693
}
702694

@@ -711,6 +703,26 @@ where
711703
now
712704
}
713705

706+
/// Creates a collection of blinded paths by delegating to
707+
/// [`MessageRouter::create_blinded_paths`].
708+
///
709+
/// Errors if the `MessageRouter` errors.
710+
///
711+
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
712+
pub fn create_blinded_paths(
713+
&self, context: MessageContext,
714+
) -> Result<Vec<BlindedMessagePath>, ()> {
715+
let recipient = self.get_our_node_id();
716+
let secp_ctx = &self.secp_ctx;
717+
718+
let peers =
719+
self.commons.get_peer_for_blinded_path().into_iter().map(|node| node.node_id).collect();
720+
721+
self.message_router
722+
.create_blinded_paths(recipient, context, peers, secp_ctx)
723+
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
724+
}
725+
714726
/// Creates a collection of blinded paths by delegating to
715727
/// [`MessageRouter::create_compact_blinded_paths`].
716728
///
@@ -781,10 +793,8 @@ where
781793
nonce,
782794
hmac: Some(hmac),
783795
});
784-
let reply_paths = self
785-
.commons
786-
.create_blinded_paths(context)
787-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
796+
let reply_paths =
797+
self.create_blinded_paths(context).map_err(|_| Bolt12SemanticError::MissingPaths)?;
788798

789799
create_pending_payment(&invoice_request, nonce)?;
790800

@@ -1054,7 +1064,7 @@ where
10541064
nonce,
10551065
hmac: Some(hmac),
10561066
});
1057-
match self.commons.create_blinded_paths(context) {
1067+
match self.create_blinded_paths(context) {
10581068
Ok(reply_paths) => {
10591069
match self.commons.enqueue_invoice_request(invoice_request, reply_paths) {
10601070
Ok(_) => {},
@@ -1512,7 +1522,6 @@ where
15121522
hmac,
15131523
});
15141524
let reply_paths = self
1515-
.commons
15161525
.create_blinded_paths(context)
15171526
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
15181527

@@ -1600,8 +1609,7 @@ where
16001609
name,
16011610
&*self.entropy_source,
16021611
)?;
1603-
let reply_paths =
1604-
self.commons.create_blinded_paths(MessageContext::DNSResolver(context))?;
1612+
let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
16051613
let expiration = StaleExpiration::TimerTicks(1);
16061614
self.commons.add_new_awaiting_offer(
16071615
payment_id,

0 commit comments

Comments
 (0)