Skip to content

Commit 31b5bbd

Browse files
committed
f: Update design to avoid taking lock twice
1 parent 16d05ff commit 31b5bbd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12482,7 +12482,7 @@ where
1248212482
// This ensures that event generation remains idempotent in case we receive
1248312483
// the same invoice multiple times.
1248412484
self.pending_outbound_payments
12485-
.mark_invoice_received(payment_id, invoice.payment_hash()).ok()?;
12485+
.mark_invoice_received_and_get_details(payment_id, invoice.payment_hash()).ok()?;
1248612486

1248712487
let event = Event::InvoiceReceived {
1248812488
payment_id, invoice, context, responder,

lightning/src/ln/outbound_payment.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,11 @@ impl OutboundPayments {
868868
// is already updated at the time the invoice is received. This ensures that `InvoiceReceived`
869869
// event generation remains idempotent, even if the same invoice is received again before the
870870
// current one is handled by the user.
871-
if !with_manual_handling { self.mark_invoice_received(payment_id, payment_hash)? }
872-
873-
let (retry_strategy, params_config) = self.received_invoice_details(payment_id)?;
871+
let (retry_strategy, params_config) = if with_manual_handling {
872+
self.received_invoice_details(payment_id)?
873+
} else {
874+
self.mark_invoice_received_and_get_details(payment_id, payment_hash)?
875+
};
874876

875877
if invoice.invoice_features().requires_unknown_bits_from(&features) {
876878
self.abandon_payment(
@@ -1778,21 +1780,23 @@ impl OutboundPayments {
17781780
}
17791781
}
17801782

1781-
pub(super) fn mark_invoice_received(
1783+
pub(super) fn mark_invoice_received_and_get_details(
17821784
&self, payment_id: PaymentId, payment_hash: PaymentHash
1783-
) -> Result<(), Bolt12PaymentError> {
1785+
) -> Result<(Retry, RouteParametersConfig), Bolt12PaymentError> {
17841786
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
17851787
hash_map::Entry::Occupied(entry) => match entry.get() {
17861788
PendingOutboundPayment::AwaitingInvoice {
17871789
retry_strategy: retry, route_params_config, ..
17881790
} => {
1791+
let retry = *retry;
1792+
let config = *route_params_config;
17891793
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
17901794
payment_hash,
1791-
retry_strategy: *retry,
1792-
route_params_config: *route_params_config,
1795+
retry_strategy: retry,
1796+
route_params_config: config,
17931797
};
17941798

1795-
Ok(())
1799+
Ok((retry, config))
17961800
},
17971801
_ => Err(Bolt12PaymentError::DuplicateInvoice),
17981802
},

0 commit comments

Comments
 (0)