Skip to content

Commit 8ee9a71

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 1868f99 commit 8ee9a71

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 5 deletions
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};
@@ -9659,10 +9659,6 @@ where
96599659
self.pending_outbound_payments.release_invoice_requests_awaiting_invoice()
96609660
}
96619661

9662-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9663-
self.create_blinded_paths(context)
9664-
}
9665-
96669662
fn enqueue_invoice_request(&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>) -> Result<(), Bolt12SemanticError> {
96679663
self.enqueue_invoice_request(invoice_request, reply_paths)
96689664
}
@@ -9869,6 +9865,7 @@ where
98699865
/// [`MessageRouter::create_blinded_paths`].
98709866
///
98719867
/// Errors if the `MessageRouter` errors.
9868+
#[cfg(async_payments)]
98729869
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
98739870
let recipient = self.get_our_node_id();
98749871
let secp_ctx = &self.secp_ctx;

lightning/src/offers/flow.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,6 @@ pub trait OffersMessageCommons {
167167
&self,
168168
) -> Vec<(PaymentId, RetryableInvoiceRequest)>;
169169

170-
/// Creates a collection of blinded paths by delegating to
171-
/// [`MessageRouter::create_blinded_paths`].
172-
///
173-
/// Errors if the `MessageRouter` errors.
174-
///
175-
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
176-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
177-
178170
/// Enqueue invoice request
179171
fn enqueue_invoice_request(
180172
&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>,
@@ -686,7 +678,7 @@ where
686678
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
687679
self.create_compact_blinded_paths(context)
688680
} else {
689-
self.commons.create_blinded_paths(MessageContext::Offers(context))
681+
self.create_blinded_paths(MessageContext::Offers(context))
690682
}
691683
}
692684

@@ -701,6 +693,26 @@ where
701693
now
702694
}
703695

696+
/// Creates a collection of blinded paths by delegating to
697+
/// [`MessageRouter::create_blinded_paths`].
698+
///
699+
/// Errors if the `MessageRouter` errors.
700+
///
701+
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
702+
pub fn create_blinded_paths(
703+
&self, context: MessageContext,
704+
) -> Result<Vec<BlindedMessagePath>, ()> {
705+
let recipient = self.get_our_node_id();
706+
let secp_ctx = &self.secp_ctx;
707+
708+
let peers =
709+
self.commons.get_peer_for_blinded_path().into_iter().map(|node| node.node_id).collect();
710+
711+
self.message_router
712+
.create_blinded_paths(recipient, context, peers, secp_ctx)
713+
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
714+
}
715+
704716
/// Creates a collection of blinded paths by delegating to
705717
/// [`MessageRouter::create_compact_blinded_paths`].
706718
///
@@ -771,10 +783,8 @@ where
771783
nonce,
772784
hmac: Some(hmac),
773785
});
774-
let reply_paths = self
775-
.commons
776-
.create_blinded_paths(context)
777-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
786+
let reply_paths =
787+
self.create_blinded_paths(context).map_err(|_| Bolt12SemanticError::MissingPaths)?;
778788

779789
create_pending_payment(&invoice_request, nonce)?;
780790

@@ -1043,7 +1053,7 @@ where
10431053
nonce,
10441054
hmac: Some(hmac),
10451055
});
1046-
match self.commons.create_blinded_paths(context) {
1056+
match self.create_blinded_paths(context) {
10471057
Ok(reply_paths) => {
10481058
match self.commons.enqueue_invoice_request(invoice_request, reply_paths) {
10491059
Ok(_) => {},
@@ -1396,7 +1406,6 @@ where
13961406
hmac,
13971407
});
13981408
let reply_paths = self
1399-
.commons
14001409
.create_blinded_paths(context)
14011410
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
14021411

@@ -1484,8 +1493,7 @@ where
14841493
name,
14851494
&*self.entropy_source,
14861495
)?;
1487-
let reply_paths =
1488-
self.commons.create_blinded_paths(MessageContext::DNSResolver(context))?;
1496+
let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
14891497
let expiration = StaleExpiration::TimerTicks(1);
14901498
self.commons.add_new_awaiting_offer(
14911499
payment_id,

0 commit comments

Comments
 (0)