Skip to content

Commit 9318a69

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 910c29c commit 9318a69

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
@@ -5377,12 +5377,10 @@ where
53775377
}
53785378

53795379
fn check_refresh_async_receive_offer_cache(&self, timer_tick_occurred: bool) {
5380-
let peers = self.get_peers_for_blinded_path();
53815380
let channels = self.list_usable_channels();
53825381
let entropy = &*self.entropy_source;
53835382
let router = &*self.router;
53845383
let refresh_res = self.flow.check_refresh_async_receive_offer_cache(
5385-
peers,
53865384
channels,
53875385
entropy,
53885386
router,
@@ -5463,10 +5461,7 @@ where
54635461
);
54645462
}
54655463
} else {
5466-
let reply_path = HeldHtlcReplyPath::ToUs {
5467-
payment_id,
5468-
peers: self.get_peers_for_blinded_path(),
5469-
};
5464+
let reply_path = HeldHtlcReplyPath::ToUs { payment_id };
54705465
let enqueue_held_htlc_available_res =
54715466
self.flow.enqueue_held_htlc_available(invoice, reply_path);
54725467
if enqueue_held_htlc_available_res.is_err() {
@@ -12232,9 +12227,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1223212227
/// [`Offer`]: crate::offers::offer::Offer
1223312228
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1223412229
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
12235-
let builder = $self.flow.create_offer_builder(
12236-
&*$self.entropy_source, $self.get_peers_for_blinded_path()
12237-
)?;
12230+
let builder = $self.flow.create_offer_builder(&*$self.entropy_source)?;
1223812231

1223912232
Ok(builder.into())
1224012233
}
@@ -12257,9 +12250,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1225712250
where
1225812251
ME::Target: MessageRouter,
1225912252
{
12260-
let builder = $self.flow.create_offer_builder_using_router(
12261-
router, &*$self.entropy_source, $self.get_peers_for_blinded_path()
12262-
)?;
12253+
let builder = $self.flow.create_offer_builder_using_router(router, &*$self.entropy_source)?;
1226312254

1226412255
Ok(builder.into())
1226512256
}
@@ -12313,8 +12304,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1231312304
let entropy = &*$self.entropy_source;
1231412305

1231512306
let builder = $self.flow.create_refund_builder(
12316-
entropy, amount_msats, absolute_expiry,
12317-
payment_id, $self.get_peers_for_blinded_path()
12307+
entropy, amount_msats, absolute_expiry, payment_id
1231812308
)?;
1231912309

1232012310
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12357,8 +12347,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1235712347
let entropy = &*$self.entropy_source;
1235812348

1235912349
let builder = $self.flow.create_refund_builder_using_router(
12360-
router, entropy, amount_msats, absolute_expiry,
12361-
payment_id, $self.get_peers_for_blinded_path()
12350+
router, entropy, amount_msats, absolute_expiry, payment_id
1236212351
)?;
1236312352

1236412353
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12430,8 +12419,7 @@ where
1243012419
pub fn set_paths_to_static_invoice_server(
1243112420
&self, paths_to_static_invoice_server: Vec<BlindedMessagePath>,
1243212421
) -> Result<(), ()> {
12433-
let peers = self.get_peers_for_blinded_path();
12434-
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server, peers)?;
12422+
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server)?;
1243512423

1243612424
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1243712425
Ok(())
@@ -12559,10 +12547,7 @@ where
1255912547
let invoice_request = builder.build_and_sign()?;
1256012548
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1256112549

12562-
self.flow.enqueue_invoice_request(
12563-
invoice_request.clone(), payment_id, nonce,
12564-
self.get_peers_for_blinded_path()
12565-
)?;
12550+
self.flow.enqueue_invoice_request(invoice_request.clone(), payment_id, nonce,)?;
1256612551

1256712552
create_pending_payment(&invoice_request, nonce)
1256812553
}
@@ -12611,7 +12596,7 @@ where
1261112596

1261212597
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
1261312598

12614-
self.flow.enqueue_invoice(invoice.clone(), refund, self.get_peers_for_blinded_path())?;
12599+
self.flow.enqueue_invoice(invoice.clone(), refund)?;
1261512600

1261612601
Ok(invoice)
1261712602
},
@@ -12687,14 +12672,7 @@ where
1268712672
payer_note,
1268812673
)?;
1268912674

12690-
self.flow
12691-
.enqueue_dns_onion_message(
12692-
onion_message,
12693-
context,
12694-
dns_resolvers,
12695-
self.get_peers_for_blinded_path(),
12696-
)
12697-
.map_err(|_| ())
12675+
self.flow.enqueue_dns_onion_message(onion_message, context, dns_resolvers).map_err(|_| ())
1269812676
}
1269912677

1270012678
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
@@ -12835,8 +12813,7 @@ where
1283512813
pub fn blinded_paths_for_async_recipient(
1283612814
&self, recipient_id: Vec<u8>, relative_expiry: Option<Duration>,
1283712815
) -> Result<Vec<BlindedMessagePath>, ()> {
12838-
let peers = self.get_peers_for_blinded_path();
12839-
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry, peers)
12816+
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry)
1284012817
}
1284112818

1284212819
pub(super) fn duration_since_epoch(&self) -> Duration {
@@ -12870,11 +12847,6 @@ where
1287012847
.collect::<Vec<_>>()
1287112848
}
1287212849

12873-
#[cfg(test)]
12874-
pub(super) fn test_get_peers_for_blinded_path(&self) -> Vec<MessageForwardNode> {
12875-
self.get_peers_for_blinded_path()
12876-
}
12877-
1287812850
#[cfg(test)]
1287912851
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1288012852
/// [`Router::create_blinded_payment_paths`].
@@ -14608,9 +14580,8 @@ where
1460814580
{
1460914581
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1461014582

14611-
let peers = self.get_peers_for_blinded_path();
1461214583
let enqueue_invreq_res =
14613-
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce, peers);
14584+
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce);
1461414585
if enqueue_invreq_res.is_err() {
1461514586
log_warn!(
1461614587
self.logger,
@@ -14818,9 +14789,8 @@ where
1481814789
&self, message: OfferPathsRequest, context: AsyncPaymentsContext,
1481914790
responder: Option<Responder>,
1482014791
) -> Option<(OfferPaths, ResponseInstruction)> {
14821-
let peers = self.get_peers_for_blinded_path();
1482214792
let (message, reply_path_context) =
14823-
match self.flow.handle_offer_paths_request(&message, context, peers) {
14793+
match self.flow.handle_offer_paths_request(&message, context) {
1482414794
Some(msg) => msg,
1482514795
None => return None,
1482614796
};
@@ -14838,7 +14808,6 @@ where
1483814808
message,
1483914809
context,
1484014810
responder.clone(),
14841-
self.get_peers_for_blinded_path(),
1484214811
self.list_usable_channels(),
1484314812
&*self.entropy_source,
1484414813
&*self.router,

0 commit comments

Comments
 (0)