Skip to content

Commit fbaf093

Browse files
committed
Don't use UserAbandoned reason for auto-failing
A BOLT12 payment may be abandoned when handling the invoice or when receiving an InvoiceError message. When abandoning the payment, don't use UserAbandoned as the reason since that is meant for when the user calls ChannelManager::abandon_payment.
1 parent 144d488 commit fbaf093

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

lightning/src/events/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl_writeable_tlv_based_enum!(InterceptNextHop,
501501
/// The reason the payment failed. Used in [`Event::PaymentFailed`].
502502
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
503503
pub enum PaymentFailureReason {
504-
/// The intended recipient rejected our payment.
504+
/// The intended recipient rejected our payment or invoice request.
505505
RecipientRejected,
506506
/// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
507507
///
@@ -528,10 +528,13 @@ pub enum PaymentFailureReason {
528528
/// This error should generally never happen. This likely means that there is a problem with
529529
/// your router.
530530
UnexpectedError,
531+
/// An invoice was received that required unknown features.
532+
UnknownRequiredFeatures,
531533
}
532534

533535
impl_writeable_tlv_based_enum!(PaymentFailureReason,
534536
(0, RecipientRejected) => {},
537+
(1, UnknownRequiredFeatures) => {},
535538
(2, UserAbandoned) => {},
536539
(4, RetriesExhausted) => {},
537540
(6, PaymentExpired) => {},

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4275,8 +4275,12 @@ where
42754275
///
42764276
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
42774277
pub fn abandon_payment(&self, payment_id: PaymentId) {
4278+
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4279+
}
4280+
4281+
fn abandon_payment_with_reason(&self, payment_id: PaymentId, reason: PaymentFailureReason) {
42784282
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4279-
self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events);
4283+
self.pending_outbound_payments.abandon_payment(payment_id, reason, &self.pending_events);
42804284
}
42814285

42824286
/// Send a spontaneous payment, which is a payment that does not require the recipient to have
@@ -10729,17 +10733,6 @@ where
1072910733
let secp_ctx = &self.secp_ctx;
1073010734
let expanded_key = &self.inbound_payment_key;
1073110735

10732-
let abandon_if_payment = |context| {
10733-
match context {
10734-
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10735-
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10736-
self.abandon_payment(payment_id);
10737-
}
10738-
},
10739-
_ => {},
10740-
}
10741-
};
10742-
1074310736
match message {
1074410737
OffersMessage::InvoiceRequest(invoice_request) => {
1074510738
let responder = match responder {
@@ -10859,7 +10852,9 @@ where
1085910852
logger, "Invoice requires unknown features: {:?}",
1086010853
invoice.invoice_features(),
1086110854
);
10862-
abandon_if_payment(context);
10855+
self.abandon_payment_with_reason(
10856+
payment_id, PaymentFailureReason::UnknownRequiredFeatures,
10857+
);
1086310858

1086410859
let error = InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures);
1086510860
let response = match responder {
@@ -10916,10 +10911,21 @@ where
1091610911
Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
1091710912
_ => None,
1091810913
};
10914+
1091910915
let logger = WithContext::from(&self.logger, None, None, payment_hash);
1092010916
log_trace!(logger, "Received invoice_error: {}", invoice_error);
1092110917

10922-
abandon_if_payment(context);
10918+
match context {
10919+
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10920+
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10921+
self.abandon_payment_with_reason(
10922+
payment_id, PaymentFailureReason::RecipientRejected,
10923+
);
10924+
}
10925+
},
10926+
_ => {},
10927+
}
10928+
1092310929
ResponseInstruction::NoResponse
1092410930
},
1092510931
}

0 commit comments

Comments
 (0)