Skip to content

Commit 1d0aca0

Browse files
committed
Prevent Duplicate InvoiceReceived Events with Idempotency Check
Ensures `InvoiceReceived` events are not generated multiple times when `manually_handle_bolt12_invoice` is enabled. Duplicate events for the same invoice could cause confusion—this change introduces an idempotency check to prevent that.
1 parent 5bc9ffa commit 1d0aca0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/ln/channelmanager.rs

+17
Original file line numberDiff line numberDiff line change
@@ -12477,6 +12477,23 @@ where
1247712477
);
1247812478

1247912479
if self.default_configuration.manually_handle_bolt12_invoices {
12480+
// Prevent duplicate `InvoiceReceived` events by checking if this invoice was already processed.
12481+
let already_present = self.pending_events.lock().unwrap().iter().any(|(e, _)| {
12482+
matches!(e, Event::InvoiceReceived { payment_id: existing_id, .. } if existing_id == &payment_id)
12483+
});
12484+
12485+
if already_present {
12486+
return None;
12487+
}
12488+
12489+
match self.pending_outbound_payments.pending_outbound_payments.lock().unwrap().entry(payment_id) {
12490+
hash_map::Entry::Occupied(entry) => match entry.get() {
12491+
PendingOutboundPayment::AwaitingInvoice { .. } => (),
12492+
_ => return None
12493+
},
12494+
hash_map::Entry::Vacant(_) => return None,
12495+
}
12496+
1248012497
let event = Event::InvoiceReceived {
1248112498
payment_id, invoice, context, responder,
1248212499
};

0 commit comments

Comments
 (0)