Extract send_to_static_invoice util
What changed, and why it matters
This commit simply moves existing payment-sending code into a new helper function without changing behavior. It is a code cleanup to make a future change easier. There is no security issue visible in this patch.
No action needed; this is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the core logic of send_payment_for_static_invoice into a new private method send_payment_for_static_invoice_no_persist, which accepts first_hops as a parameter. The original public method now calls this helper passing self.list_usable_channels(). The same arguments are passed to pending_outbound_payments.send_payment_for_static_invoice as before, and the persistence guard remains in the public wrapper. No functional or security-relevant change is introduced.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +23 / −14
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index a93c7c5..69907d8 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -5506,22 +5506,11 @@ where
fn send_payment_for_static_invoice(
&self, payment_id: PaymentId,
) -> Result<(), Bolt12PaymentError> {
- let best_block_height = self.best_block.read().unwrap().height;
let mut res = Ok(());
+ let first_hops = self.list_usable_channels();
PersistenceNotifierGuard::optionally_notify(self, || {
- let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
- payment_id,
- &self.router,
- self.list_usable_channels(),
- || self.compute_inflight_htlcs(),
- &self.entropy_source,
- &self.node_signer,
- &self,
- &self.secp_ctx,
- best_block_height,
- &self.pending_events,
- |args| self.send_payment_along_path(args),
- );
+ let outbound_pmts_res =
+ self.send_payment_for_static_invoice_no_persist(payment_id, first_hops);
match outbound_pmts_res {
Err(Bolt12PaymentError::UnexpectedInvoice)
| Err(Bolt12PaymentError::DuplicateInvoice) => {
@@ -5537,6 +5526,26 @@ where
res
}
+ /// Useful if the caller is already triggering a persist of the `ChannelManager`.
+ fn send_payment_for_static_invoice_no_persist(
+ &self, payment_id: PaymentId, first_hops: Vec<ChannelDetails>,
+ ) -> Result<(), Bolt12PaymentError> {
+ let best_block_height = self.best_block.read().unwrap().height;
+ self.pending_outbound_payments.send_payment_for_static_invoice(
+ payment_id,
+ &self.router,
+ first_hops,
+ || self.compute_inflight_htlcs(),
+ &self.entropy_source,
+ &self.node_signer,
+ &self,
+ &self.secp_ctx,
+ best_block_height,
+ &self.pending_events,
+ |args| self.send_payment_along_path(args),
+ )
+ }
+
/// If we are holding an HTLC on behalf of an often-offline sender, this method allows us to
/// create a path for the sender to use as the reply path when they send the recipient a
/// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.