Skip to content

Commit e746da9

Browse files
Extract send_to_static_invoice util
Makes an upcoming commit cleaner. In the util we allow manually passing in the first_hops that should be used when paying a static invoice, which is useful for only passing in next-hop channels that support the hold_htlcs feature.
1 parent 9c4bb94 commit e746da9

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5448,23 +5448,11 @@ where
54485448
fn send_payment_for_static_invoice(
54495449
&self, payment_id: PaymentId,
54505450
) -> Result<(), Bolt12PaymentError> {
5451-
let best_block_height = self.best_block.read().unwrap().height;
54525451
let mut res = Ok(());
5452+
let first_hops = self.list_usable_channels();
54535453
PersistenceNotifierGuard::optionally_notify(self, || {
5454-
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
5455-
payment_id,
5456-
&self.router,
5457-
self.list_usable_channels(),
5458-
|| self.compute_inflight_htlcs(),
5459-
&self.entropy_source,
5460-
&self.node_signer,
5461-
&self,
5462-
&self.secp_ctx,
5463-
best_block_height,
5464-
&self.logger,
5465-
&self.pending_events,
5466-
|args| self.send_payment_along_path(args),
5467-
);
5454+
let outbound_pmts_res =
5455+
self.send_payment_for_static_invoice_no_persist(payment_id, first_hops);
54685456
match outbound_pmts_res {
54695457
Err(Bolt12PaymentError::UnexpectedInvoice)
54705458
| Err(Bolt12PaymentError::DuplicateInvoice) => {
@@ -5480,6 +5468,27 @@ where
54805468
res
54815469
}
54825470

5471+
/// Useful if the caller is already triggering a persist of the `ChannelManager`.
5472+
fn send_payment_for_static_invoice_no_persist(
5473+
&self, payment_id: PaymentId, first_hops: Vec<ChannelDetails>,
5474+
) -> Result<(), Bolt12PaymentError> {
5475+
let best_block_height = self.best_block.read().unwrap().height;
5476+
self.pending_outbound_payments.send_payment_for_static_invoice(
5477+
payment_id,
5478+
&self.router,
5479+
first_hops,
5480+
|| self.compute_inflight_htlcs(),
5481+
&self.entropy_source,
5482+
&self.node_signer,
5483+
&self,
5484+
&self.secp_ctx,
5485+
best_block_height,
5486+
&self.logger,
5487+
&self.pending_events,
5488+
|args| self.send_payment_along_path(args),
5489+
)
5490+
}
5491+
54835492
/// If we are holding an HTLC on behalf of an often-offline sender, this method allows us to
54845493
/// create a path for the sender to use as the reply path when they send the recipient a
54855494
/// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be

0 commit comments

Comments
 (0)