Skip to content

Commit 5a85596

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 8e124d8 commit 5a85596

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9607,23 +9607,6 @@ where
96079607
self.pending_outbound_payments.release_invoice_requests_awaiting_invoice()
96089608
}
96099609

9610-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9611-
let recipient = self.get_our_node_id();
9612-
let secp_ctx = &self.secp_ctx;
9613-
9614-
let peers = self.per_peer_state.read().unwrap()
9615-
.iter()
9616-
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9617-
.filter(|(_, peer)| peer.is_connected)
9618-
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9619-
.map(|(node_id, _)| *node_id)
9620-
.collect::<Vec<_>>();
9621-
9622-
self.message_router
9623-
.create_blinded_paths(recipient, context, peers, secp_ctx)
9624-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9625-
}
9626-
96279610
fn enqueue_invoice_request(
96289611
&self,
96299612
invoice_request: InvoiceRequest,
@@ -9840,6 +9823,29 @@ where
98409823
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
98419824
}
98429825

9826+
/// Creates a collection of blinded paths by delegating to
9827+
/// [`MessageRouter::create_blinded_paths`].
9828+
///
9829+
/// Errors if the `MessageRouter` errors.
9830+
///
9831+
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
9832+
pub fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9833+
let recipient = self.get_our_node_id();
9834+
let secp_ctx = &self.secp_ctx;
9835+
9836+
let peers = self.per_peer_state.read().unwrap()
9837+
.iter()
9838+
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9839+
.filter(|(_, peer)| peer.is_connected)
9840+
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9841+
.map(|(node_id, _)| *node_id)
9842+
.collect::<Vec<_>>();
9843+
9844+
self.message_router
9845+
.create_blinded_paths(recipient, context, peers, secp_ctx)
9846+
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9847+
}
9848+
98439849
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
98449850
/// are used when constructing the phantom invoice's route hints.
98459851
///

lightning/src/offers/flow.rs

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

175-
/// Creates a collection of blinded paths by delegating to
176-
/// [`MessageRouter::create_blinded_paths`].
177-
///
178-
/// Errors if the `MessageRouter` errors.
179-
///
180-
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
181-
fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()>;
182-
183175
/// Enqueue invoice request
184176
fn enqueue_invoice_request(
185177
&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>,
@@ -674,7 +666,7 @@ where
674666
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
675667
self.create_compact_blinded_paths(context)
676668
} else {
677-
self.commons.create_blinded_paths(MessageContext::Offers(context))
669+
self.create_blinded_paths(MessageContext::Offers(context))
678670
}
679671
}
680672

@@ -689,6 +681,26 @@ where
689681
now
690682
}
691683

684+
/// Creates a collection of blinded paths by delegating to
685+
/// [`MessageRouter::create_blinded_paths`].
686+
///
687+
/// Errors if the `MessageRouter` errors.
688+
///
689+
/// [`MessageRouter::create_blinded_paths`]: crate::onion_message::messenger::MessageRouter::create_blinded_paths
690+
pub fn create_blinded_paths(
691+
&self, context: MessageContext,
692+
) -> Result<Vec<BlindedMessagePath>, ()> {
693+
let recipient = self.get_our_node_id();
694+
let secp_ctx = &self.secp_ctx;
695+
696+
let peers =
697+
self.commons.get_peer_for_blinded_path().into_iter().map(|node| node.node_id).collect();
698+
699+
self.message_router
700+
.create_blinded_paths(recipient, context, peers, secp_ctx)
701+
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
702+
}
703+
692704
/// Creates a collection of blinded paths by delegating to
693705
/// [`MessageRouter::create_compact_blinded_paths`].
694706
///
@@ -759,10 +771,8 @@ where
759771
nonce,
760772
hmac: Some(hmac),
761773
});
762-
let reply_paths = self
763-
.commons
764-
.create_blinded_paths(context)
765-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
774+
let reply_paths =
775+
self.create_blinded_paths(context).map_err(|_| Bolt12SemanticError::MissingPaths)?;
766776

767777
create_pending_payment(&invoice_request, nonce)?;
768778

@@ -1032,7 +1042,7 @@ where
10321042
nonce,
10331043
hmac: Some(hmac),
10341044
});
1035-
match self.commons.create_blinded_paths(context) {
1045+
match self.create_blinded_paths(context) {
10361046
Ok(reply_paths) => {
10371047
match self.commons.enqueue_invoice_request(invoice_request, reply_paths) {
10381048
Ok(_) => {},
@@ -1385,7 +1395,6 @@ where
13851395
hmac,
13861396
});
13871397
let reply_paths = self
1388-
.commons
13891398
.create_blinded_paths(context)
13901399
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
13911400

@@ -1473,8 +1482,7 @@ where
14731482
name,
14741483
&*self.entropy_source,
14751484
)?;
1476-
let reply_paths =
1477-
self.commons.create_blinded_paths(MessageContext::DNSResolver(context))?;
1485+
let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
14781486
let expiration = StaleExpiration::TimerTicks(1);
14791487
self.commons.add_new_awaiting_offer(
14801488
payment_id,

0 commit comments

Comments
 (0)