Skip to content

Commit 9698772

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 6680b40 commit 9698772

File tree

3 files changed

+51
-120
lines changed

3 files changed

+51
-120
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ fn create_static_invoice_builder<'a>(
302302
payment_secret,
303303
relative_expiry_secs,
304304
recipient.node.list_usable_channels(),
305-
recipient.node.test_get_peers_for_blinded_path(),
306305
)
307306
.unwrap()
308307
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,12 +5441,10 @@ where
54415441
}
54425442

54435443
fn check_refresh_async_receive_offer_cache(&self, timer_tick_occurred: bool) {
5444-
let peers = self.get_peers_for_blinded_path();
54455444
let channels = self.list_usable_channels();
54465445
let entropy = &*self.entropy_source;
54475446
let router = &*self.router;
54485447
let refresh_res = self.flow.check_refresh_async_receive_offer_cache(
5449-
peers,
54505448
channels,
54515449
entropy,
54525450
router,
@@ -5534,10 +5532,7 @@ where
55345532
);
55355533
}
55365534
} else {
5537-
let reply_path = HeldHtlcReplyPath::ToUs {
5538-
payment_id,
5539-
peers: self.get_peers_for_blinded_path(),
5540-
};
5535+
let reply_path = HeldHtlcReplyPath::ToUs { payment_id };
55415536
let enqueue_held_htlc_available_res =
55425537
self.flow.enqueue_held_htlc_available(invoice, reply_path);
55435538
if enqueue_held_htlc_available_res.is_err() {
@@ -12264,9 +12259,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1226412259
/// [`Offer`]: crate::offers::offer::Offer
1226512260
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1226612261
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
12267-
let builder = $self.flow.create_offer_builder(
12268-
&*$self.entropy_source, $self.get_peers_for_blinded_path()
12269-
)?;
12262+
let builder = $self.flow.create_offer_builder(&*$self.entropy_source)?;
1227012263

1227112264
Ok(builder.into())
1227212265
}
@@ -12289,9 +12282,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
1228912282
where
1229012283
ME::Target: MessageRouter,
1229112284
{
12292-
let builder = $self.flow.create_offer_builder_using_router(
12293-
router, &*$self.entropy_source, $self.get_peers_for_blinded_path()
12294-
)?;
12285+
let builder = $self.flow.create_offer_builder_using_router(router, &*$self.entropy_source)?;
1229512286

1229612287
Ok(builder.into())
1229712288
}
@@ -12345,8 +12336,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1234512336
let entropy = &*$self.entropy_source;
1234612337

1234712338
let builder = $self.flow.create_refund_builder(
12348-
entropy, amount_msats, absolute_expiry,
12349-
payment_id, $self.get_peers_for_blinded_path()
12339+
entropy, amount_msats, absolute_expiry, payment_id
1235012340
)?;
1235112341

1235212342
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12389,8 +12379,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1238912379
let entropy = &*$self.entropy_source;
1239012380

1239112381
let builder = $self.flow.create_refund_builder_using_router(
12392-
router, entropy, amount_msats, absolute_expiry,
12393-
payment_id, $self.get_peers_for_blinded_path()
12382+
router, entropy, amount_msats, absolute_expiry, payment_id
1239412383
)?;
1239512384

1239612385
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
@@ -12462,8 +12451,7 @@ where
1246212451
pub fn set_paths_to_static_invoice_server(
1246312452
&self, paths_to_static_invoice_server: Vec<BlindedMessagePath>,
1246412453
) -> Result<(), ()> {
12465-
let peers = self.get_peers_for_blinded_path();
12466-
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server, peers)?;
12454+
self.flow.set_paths_to_static_invoice_server(paths_to_static_invoice_server)?;
1246712455

1246812456
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1246912457
Ok(())
@@ -12643,10 +12631,7 @@ where
1264312631
let invoice_request = builder.build_and_sign()?;
1264412632
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
1264512633

12646-
self.flow.enqueue_invoice_request(
12647-
invoice_request.clone(), payment_id, nonce,
12648-
self.get_peers_for_blinded_path()
12649-
)?;
12634+
self.flow.enqueue_invoice_request(invoice_request.clone(), payment_id, nonce,)?;
1265012635

1265112636
let retryable_invoice_request = RetryableInvoiceRequest {
1265212637
invoice_request: invoice_request.clone(),
@@ -12701,7 +12686,7 @@ where
1270112686

1270212687
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
1270312688

12704-
self.flow.enqueue_invoice(invoice.clone(), refund, self.get_peers_for_blinded_path())?;
12689+
self.flow.enqueue_invoice(invoice.clone(), refund)?;
1270512690

1270612691
Ok(invoice)
1270712692
},
@@ -12765,14 +12750,7 @@ where
1276512750
optional_params.payer_note,
1276612751
)?;
1276712752

12768-
self.flow
12769-
.enqueue_dns_onion_message(
12770-
onion_message,
12771-
context,
12772-
dns_resolvers,
12773-
self.get_peers_for_blinded_path(),
12774-
)
12775-
.map_err(|_| ())
12753+
self.flow.enqueue_dns_onion_message(onion_message, context, dns_resolvers).map_err(|_| ())
1277612754
}
1277712755

1277812756
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
@@ -12913,8 +12891,7 @@ where
1291312891
pub fn blinded_paths_for_async_recipient(
1291412892
&self, recipient_id: Vec<u8>, relative_expiry: Option<Duration>,
1291512893
) -> Result<Vec<BlindedMessagePath>, ()> {
12916-
let peers = self.get_peers_for_blinded_path();
12917-
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry, peers)
12894+
self.flow.blinded_paths_for_async_recipient(recipient_id, relative_expiry)
1291812895
}
1291912896

1292012897
pub(super) fn duration_since_epoch(&self) -> Duration {
@@ -12948,11 +12925,6 @@ where
1294812925
.collect::<Vec<_>>()
1294912926
}
1295012927

12951-
#[cfg(test)]
12952-
pub(super) fn test_get_peers_for_blinded_path(&self) -> Vec<MessageForwardNode> {
12953-
self.get_peers_for_blinded_path()
12954-
}
12955-
1295612928
#[cfg(test)]
1295712929
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1295812930
/// [`Router::create_blinded_payment_paths`].
@@ -14735,9 +14707,8 @@ where
1473514707
{
1473614708
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1473714709

14738-
let peers = self.get_peers_for_blinded_path();
1473914710
let enqueue_invreq_res =
14740-
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce, peers);
14711+
self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce);
1474114712
if enqueue_invreq_res.is_err() {
1474214713
log_warn!(
1474314714
self.logger,
@@ -14945,9 +14916,8 @@ where
1494514916
&self, message: OfferPathsRequest, context: AsyncPaymentsContext,
1494614917
responder: Option<Responder>,
1494714918
) -> Option<(OfferPaths, ResponseInstruction)> {
14948-
let peers = self.get_peers_for_blinded_path();
1494914919
let (message, reply_path_context) =
14950-
match self.flow.handle_offer_paths_request(&message, context, peers) {
14920+
match self.flow.handle_offer_paths_request(&message, context) {
1495114921
Some(msg) => msg,
1495214922
None => return None,
1495314923
};
@@ -14965,7 +14935,6 @@ where
1496514935
message,
1496614936
context,
1496714937
responder.clone(),
14968-
self.get_peers_for_blinded_path(),
1496914938
self.list_usable_channels(),
1497014939
&*self.entropy_source,
1497114940
&*self.router,

0 commit comments

Comments
 (0)