Skip to content

Commit 90d8409

Browse files
amackillopmartinsaposnic
authored andcommitted
Deduplicate PaymentReceived events on restart
PaymentClaimed events can be replayed on every Node startup. Since nodes are pinged at minimum every 30 minutes, this causes duplicate PaymentReceived events to stack up in the queue when the event queue is not being actively processed. These stacked events can cause payouts to fail as they timeout before the queue is drained to the actual events related to a payout. Add a check before queuing PaymentReceived to skip if an event for that payment_id already exists in the queue, preventing duplicates.
1 parent ec8c62e commit 90d8409

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/event.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ where
358358
Ok(())
359359
}
360360

361+
fn contains_payment_received(&self, payment_id: &PaymentId) -> bool {
362+
let locked_queue = self.queue.lock().unwrap();
363+
locked_queue.iter().any(|event| {
364+
matches!(event, Event::PaymentReceived { payment_id: Some(id), .. } if id == payment_id)
365+
})
366+
}
367+
361368
fn persist_queue(&self, locked_queue: &VecDeque<Event>) -> Result<(), Error> {
362369
let data = EventQueueSerWrapper(locked_queue).encode();
363370
self.kv_store
@@ -938,6 +945,18 @@ where
938945
},
939946
}
940947

948+
// Check if a PaymentReceived event for this payment already exists in the queue.
949+
// This handles the case where PaymentClaimed is replayed on restart - we only
950+
// want to queue one PaymentReceived event per payment.
951+
if self.event_queue.contains_payment_received(&payment_id) {
952+
log_debug!(
953+
self.logger,
954+
"Skipping duplicate PaymentReceived for payment {}: event already queued",
955+
payment_id,
956+
);
957+
return Ok(());
958+
}
959+
941960
let event = Event::PaymentReceived {
942961
payment_id: Some(payment_id),
943962
payment_hash,

0 commit comments

Comments
 (0)