Skip to content

Commit c172251

Browse files
Use cached peers in OffersMessageFlow
In the previous commit, we started caching the set of peers in the OffersMessageFlow that are used when creating blinded paths. Here we start using that cache and stop passing in the peers for every method.
1 parent f10ccfa commit c172251

File tree

3 files changed

+48
-122
lines changed

3 files changed

+48
-122
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ fn create_static_invoice_builder<'a>(
276276
payment_secret,
277277
relative_expiry_secs,
278278
recipient.node.list_usable_channels(),
279-
recipient.node.test_get_peers_for_blinded_path(),
280279
)
281280
.unwrap()
282281
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,12 +5384,10 @@ where
53845384
}
53855385

53865386
fn check_refresh_async_receive_offer_cache(&self, timer_tick_occurred: bool) {
5387-
let peers = self.get_peers_for_blinded_path();
53885387
let channels = self.list_usable_channels();
53895388
let entropy = &*self.entropy_source;
53905389
let router = &*self.router;
53915390
let refresh_res = self.flow.check_refresh_async_receive_offer_cache(
5392-
peers,
53935391
channels,
53945392
entropy,
53955393
router,
@@ -5470,10 +5468,7 @@ where
54705468
);
54715469
}
54725470
} else {
5473-
let reply_path = HeldHtlcReplyPath::ToUs {
5474-
payment_id,
5475-
peers: self.get_peers_for_blinded_path(),
5476-
};
5471+
let reply_path = HeldHtlcReplyPath::ToUs { payment_id };
54775472
let enqueue_held_htlc_available_res =
54785473
self.flow.enqueue_held_htlc_available(invoice, reply_path);
54795474
if enqueue_held_htlc_available_res.is_err() {
@@ -12239,9 +12234,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1223912234
/// [`Offer`]: crate::offers::offer::Offer
1224012235
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1224112236
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
12242-
let builder = $self.flow.create_offer_builder(
12243-
&*$self.entropy_source, $self.get_peers_for_blinded_path()
12244-
)?;
12237+
let builder = $self.flow.create_offer_builder(&*$self.entropy_source)?;
1224512238

1224612239
Ok(builder.into())
1224712240
}
@@ -12264,9 +12257,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1226412257
where
1226512258
ME::Target: MessageRouter,
1226612259
{
12267-
let builder = $self.flow.create_offer_builder_using_router(
12268-
router, &*$self.entropy_source, $self.get_peers_for_blinded_path()
12269-
)?;
12260+
let builder = $self.flow.create_offer_builder_using_router(router, &*$self.entropy_source)?;
1227012261

1227112262
Ok(builder.into())
1227212263
}
@@ -12320,8 +12311,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1232012311
let entropy = &*$self.entropy_source;
1232112312

1232212313
let builder = $self.flow.create_refund_builder(
12323-
entropy, amount_msats, absolute_expiry,
12324-
payment_id, $self.get_peers_for_blinded_path()
12314+
entropy, amount_msats, absolute_expiry, payment_id
1232512315
)?;
1232612316

1232712317
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12364,8 +12354,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1236412354
let entropy = &*$self.entropy_source;
1236512355

1236612356
let builder = $self.flow.create_refund_builder_using_router(
12367-
router, entropy, amount_msats, absolute_expiry,
12368-
payment_id, $self.get_peers_for_blinded_path()
12357+
router, entropy, amount_msats, absolute_expiry, payment_id
1236912358
)?;
1237012359

1237112360
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12437,8 +12426,7 @@ where
1243712426
pub fn set_paths_to_static_invoice_server(
1243812427
&self, paths_to_static_invoice_server: Vec<BlindedMessagePath>,
1243912428
) -> Result<(), ()> {
12440-
let peers = self.get_peers_for_blinded_path();
12441-
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server, peers)?;
12429+
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server)?;
1244212430

1244312431
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1244412432
Ok(())
@@ -12566,10 +12554,7 @@ where
1256612554
let invoice_request = builder.build_and_sign()?;
1256712555
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1256812556

12569-
self.flow.enqueue_invoice_request(
12570-
invoice_request.clone(), payment_id, nonce,
12571-
self.get_peers_for_blinded_path()
12572-
)?;
12557+
self.flow.enqueue_invoice_request(invoice_request.clone(), payment_id, nonce,)?;
1257312558

1257412559
create_pending_payment(&invoice_request, nonce)
1257512560
}
@@ -12618,7 +12603,7 @@ where
1261812603

1261912604
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
1262012605

12621-
self.flow.enqueue_invoice(invoice.clone(), refund, self.get_peers_for_blinded_path())?;
12606+
self.flow.enqueue_invoice(invoice.clone(), refund)?;
1262212607

1262312608
Ok(invoice)
1262412609
},
@@ -12694,14 +12679,7 @@ where
1269412679
payer_note,
1269512680
)?;
1269612681

12697-
self.flow
12698-
.enqueue_dns_onion_message(
12699-
onion_message,
12700-
context,
12701-
dns_resolvers,
12702-
self.get_peers_for_blinded_path(),
12703-
)
12704-
.map_err(|_| ())
12682+
self.flow.enqueue_dns_onion_message(onion_message, context, dns_resolvers).map_err(|_| ())
1270512683
}
1270612684

1270712685
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
@@ -12842,8 +12820,7 @@ where
1284212820
pub fn blinded_paths_for_async_recipient(
1284312821
&self, recipient_id: Vec<u8>, relative_expiry: Option<Duration>,
1284412822
) -> Result<Vec<BlindedMessagePath>, ()> {
12845-
let peers = self.get_peers_for_blinded_path();
12846-
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry, peers)
12823+
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry)
1284712824
}
1284812825

1284912826
pub(super) fn duration_since_epoch(&self) -> Duration {
@@ -12877,11 +12854,6 @@ where
1287712854
.collect::<Vec<_>>()
1287812855
}
1287912856

12880-
#[cfg(test)]
12881-
pub(super) fn test_get_peers_for_blinded_path(&self) -> Vec<MessageForwardNode> {
12882-
self.get_peers_for_blinded_path()
12883-
}
12884-
1288512857
#[cfg(test)]
1288612858
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1288712859
/// [`Router::create_blinded_payment_paths`].
@@ -14615,9 +14587,8 @@ where
1461514587
{
1461614588
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1461714589

14618-
let peers = self.get_peers_for_blinded_path();
1461914590
let enqueue_invreq_res =
14620-
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce, peers);
14591+
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce);
1462114592
if enqueue_invreq_res.is_err() {
1462214593
log_warn!(
1462314594
self.logger,
@@ -14825,9 +14796,8 @@ where
1482514796
&self, message: OfferPathsRequest, context: AsyncPaymentsContext,
1482614797
responder: Option<Responder>,
1482714798
) -> Option<(OfferPaths, ResponseInstruction)> {
14828-
let peers = self.get_peers_for_blinded_path();
1482914799
let (message, reply_path_context) =
14830-
match self.flow.handle_offer_paths_request(&message, context, peers) {
14800+
match self.flow.handle_offer_paths_request(&message, context) {
1483114801
Some(msg) => msg,
1483214802
None => return None,
1483314803
};
@@ -14845,7 +14815,6 @@ where
1484514815
message,
1484614816
context,
1484714817
responder.clone(),
14848-
self.get_peers_for_blinded_path(),
1484914818
self.list_usable_channels(),
1485014819
&*self.entropy_source,
1485114820
&*self.router,

0 commit comments

Comments
 (0)