Skip to content

Commit 7f71532

Browse files
f avoid unncessarily remove'ing InvoiceReceived entries
1 parent d072621 commit 7f71532

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

lightning/src/ln/outbound_payment.rs

+20-25
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ impl OutboundPayments {
881881
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
882882
}
883883
self.send_payment_for_bolt12_invoice_internal(
884-
payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops,
884+
payment_id, payment_hash, None, None, route_params, retry_strategy, router, first_hops,
885885
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
886886
logger, pending_events, send_payment_along_path
887887
)
@@ -891,10 +891,10 @@ impl OutboundPayments {
891891
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
892892
>(
893893
&self, payment_id: PaymentId, payment_hash: PaymentHash,
894-
keysend_preimage: Option<PaymentPreimage>, mut route_params: RouteParameters,
895-
retry_strategy: Retry, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
896-
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
897-
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
894+
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
895+
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
896+
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
897+
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
898898
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
899899
send_payment_along_path: SP,
900900
) -> Result<(), Bolt12PaymentError>
@@ -952,27 +952,21 @@ impl OutboundPayments {
952952
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
953953
payment_params, entropy_source, best_block_height
954954
);
955-
let mut invoice_request_opt = None;
956-
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
957-
match outbounds.entry(payment_id) {
958-
hash_map::Entry::Occupied(entry) => match entry.remove() {
959-
PendingOutboundPayment::InvoiceReceived { .. } => {
960-
outbounds.insert(payment_id, retryable_payment);
961-
},
962-
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
963-
invoice_request_opt = Some(invoice_request);
964-
outbounds.insert(payment_id, retryable_payment);
955+
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
956+
hash_map::Entry::Occupied(entry) => match entry.get() {
957+
PendingOutboundPayment::InvoiceReceived { .. }
958+
| PendingOutboundPayment::StaticInvoiceReceived { .. } => {
959+
*entry.into_mut() = retryable_payment;
965960
},
966961
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
967962
},
968963
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
969964
}
970-
core::mem::drop(outbounds);
971965

972966
let result = self.pay_route_internal(
973-
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request_opt.as_ref(),
974-
payment_id, Some(route_params.final_value_msat), onion_session_privs, node_signer,
975-
best_block_height, &send_payment_along_path
967+
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request, payment_id,
968+
Some(route_params.final_value_msat), onion_session_privs, node_signer, best_block_height,
969+
&send_payment_along_path
976970
);
977971
log_info!(
978972
logger, "Sending payment with id {} and hash {} returned {:?}", payment_id,
@@ -1088,23 +1082,24 @@ impl OutboundPayments {
10881082
IH: Fn() -> InFlightHtlcs,
10891083
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
10901084
{
1091-
let (payment_hash, keysend_preimage, route_params, retry_strategy) =
1085+
let (payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request) =
10921086
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
10931087
hash_map::Entry::Occupied(entry) => match entry.get() {
10941088
PendingOutboundPayment::StaticInvoiceReceived {
1095-
payment_hash, route_params, retry_strategy, keysend_preimage, ..
1089+
payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, ..
10961090
} => {
1097-
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy)
1091+
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy,
1092+
invoice_request.clone())
10981093
},
10991094
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
11001095
},
11011096
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
11021097
};
11031098

11041099
self.send_payment_for_bolt12_invoice_internal(
1105-
payment_id, payment_hash, Some(keysend_preimage), route_params, retry_strategy, router,
1106-
first_hops, inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx,
1107-
best_block_height, logger, pending_events, send_payment_along_path
1100+
payment_id, payment_hash, Some(keysend_preimage), Some(&invoice_request), route_params,
1101+
retry_strategy, router, first_hops, inflight_htlcs, entropy_source, node_signer,
1102+
node_id_lookup, secp_ctx, best_block_height, logger, pending_events, send_payment_along_path
11081103
)
11091104
}
11101105

0 commit comments

Comments
 (0)