Skip to content

Commit b8efd9d

Browse files
committed
Refuse circular payments
.. we previously got reports from users trying to pay their own JIT invoice, which we currently don't support (and possibly never will). In order to avoid entering any weird states, we just reject our own circular payment.
1 parent 0c6eaef commit b8efd9d

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
@@ -468,6 +468,25 @@ where
468468
} => {
469469
let payment_id = PaymentId(payment_hash.0);
470470
if let Some(info) = self.payment_store.get(&payment_id) {
471+
if info.direction == PaymentDirection::Outbound {
472+
log_info!(
473+
self.logger,
474+
"Refused inbound payment with ID {}: circular payments are unsupported.",
475+
payment_id
476+
);
477+
self.channel_manager.fail_htlc_backwards(&payment_hash);
478+
479+
let update = PaymentDetailsUpdate {
480+
status: Some(PaymentStatus::Failed),
481+
..PaymentDetailsUpdate::new(payment_id)
482+
};
483+
self.payment_store.update(&update).unwrap_or_else(|e| {
484+
log_error!(self.logger, "Failed to access payment store: {}", e);
485+
panic!("Failed to access payment store");
486+
});
487+
return;
488+
}
489+
471490
if info.status == PaymentStatus::Succeeded
472491
|| matches!(info.kind, PaymentKind::Spontaneous { .. })
473492
{

0 commit comments

Comments
 (0)