Skip to content

Commit

Permalink
f avoid unncessarily remove'ing InvoiceReceived entries
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Oct 24, 2024
1 parent 22eabde commit a3c31f6
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl OutboundPayments {
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
}
self.send_payment_for_bolt12_invoice_internal(
payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops,
payment_id, payment_hash, None, None, route_params, retry_strategy, router, first_hops,
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
logger, pending_events, send_payment_along_path
)
Expand All @@ -891,10 +891,10 @@ impl OutboundPayments {
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
>(
&self, payment_id: PaymentId, payment_hash: PaymentHash,
keysend_preimage: Option<PaymentPreimage>, mut route_params: RouteParameters,
retry_strategy: Retry, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
send_payment_along_path: SP,
) -> Result<(), Bolt12PaymentError>
Expand Down Expand Up @@ -952,27 +952,21 @@ impl OutboundPayments {
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
payment_params, entropy_source, best_block_height
);
let mut invoice_request_opt = None;
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
match outbounds.entry(payment_id) {
hash_map::Entry::Occupied(entry) => match entry.remove() {
PendingOutboundPayment::InvoiceReceived { .. } => {
outbounds.insert(payment_id, retryable_payment);
},
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
invoice_request_opt = Some(invoice_request);
outbounds.insert(payment_id, retryable_payment);
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
hash_map::Entry::Occupied(entry) => match entry.get() {
PendingOutboundPayment::InvoiceReceived { .. }
| PendingOutboundPayment::StaticInvoiceReceived { .. } => {
*entry.into_mut() = retryable_payment;
},
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
},
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
}
core::mem::drop(outbounds);

let result = self.pay_route_internal(
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request_opt.as_ref(),
payment_id, Some(route_params.final_value_msat), onion_session_privs, node_signer,
best_block_height, &send_payment_along_path
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request, payment_id,
Some(route_params.final_value_msat), onion_session_privs, node_signer, best_block_height,
&send_payment_along_path
);
log_info!(
logger, "Sending payment with id {} and hash {} returned {:?}", payment_id,
Expand Down Expand Up @@ -1088,23 +1082,24 @@ impl OutboundPayments {
IH: Fn() -> InFlightHtlcs,
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
{
let (payment_hash, keysend_preimage, route_params, retry_strategy) =
let (payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request) =
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
hash_map::Entry::Occupied(entry) => match entry.get() {
PendingOutboundPayment::StaticInvoiceReceived {
payment_hash, route_params, retry_strategy, keysend_preimage, ..
payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, ..
} => {
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy)
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy,
invoice_request.clone())
},
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
},
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
};

self.send_payment_for_bolt12_invoice_internal(
payment_id, payment_hash, Some(keysend_preimage), route_params, retry_strategy, router,
first_hops, inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx,
best_block_height, logger, pending_events, send_payment_along_path
payment_id, payment_hash, Some(keysend_preimage), Some(&invoice_request), route_params,
retry_strategy, router, first_hops, inflight_htlcs, entropy_source, node_signer,
node_id_lookup, secp_ctx, best_block_height, logger, pending_events, send_payment_along_path
)
}

Expand Down

0 comments on commit a3c31f6

Please sign in to comment.