Skip to content

Commit 1cdec04

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 3db0553 commit 1cdec04

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lightning/src/events/mod.rs

Lines changed: 5 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) => {},
@@ -882,6 +885,7 @@ pub enum Event {
882885
payment_hash: PaymentHash,
883886
/// The reason the payment failed. This is only `None` for events generated or serialized
884887
/// by versions prior to 0.0.115.
888+
/// TODO: Will downgrading cause this to be None for UnknownRequiredFeatures?
885889
reason: Option<PaymentFailureReason>,
886890
},
887891
/// Indicates that a path for an outbound payment was successful.

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,8 +4270,12 @@ where
42704270
///
42714271
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
42724272
pub fn abandon_payment(&self, payment_id: PaymentId) {
4273+
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4274+
}
4275+
4276+
fn abandon_payment_with_reason(&self, payment_id: PaymentId, reason: PaymentFailureReason) {
42734277
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4274-
self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events);
4278+
self.pending_outbound_payments.abandon_payment(payment_id, reason, &self.pending_events);
42754279
}
42764280

42774281
/// Send a spontaneous payment, which is a payment that does not require the recipient to have
@@ -10721,17 +10725,6 @@ where
1072110725
let secp_ctx = &self.secp_ctx;
1072210726
let expanded_key = &self.inbound_payment_key;
1072310727

10724-
let abandon_if_payment = |context| {
10725-
match context {
10726-
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10727-
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10728-
self.abandon_payment(payment_id);
10729-
}
10730-
},
10731-
_ => {},
10732-
}
10733-
};
10734-
1073510728
match message {
1073610729
OffersMessage::InvoiceRequest(invoice_request) => {
1073710730
let responder = match responder {
@@ -10851,7 +10844,9 @@ where
1085110844
logger, "Invoice requires unknown features: {:?}",
1085210845
invoice.invoice_features(),
1085310846
);
10854-
abandon_if_payment(context);
10847+
self.abandon_payment_with_reason(
10848+
payment_id, PaymentFailureReason::UnknownRequiredFeatures,
10849+
);
1085510850

1085610851
let error = InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures);
1085710852
let response = match responder {
@@ -10908,10 +10903,21 @@ where
1090810903
Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
1090910904
_ => None,
1091010905
};
10906+
1091110907
let logger = WithContext::from(&self.logger, None, None, payment_hash);
1091210908
log_trace!(logger, "Received invoice_error: {}", invoice_error);
1091310909

10914-
abandon_if_payment(context);
10910+
match context {
10911+
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10912+
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
10913+
self.abandon_payment_with_reason(
10914+
payment_id, PaymentFailureReason::RecipientRejected,
10915+
);
10916+
}
10917+
},
10918+
_ => {},
10919+
}
10920+
1091510921
ResponseInstruction::NoResponse
1091610922
},
1091710923
}

0 commit comments

Comments
 (0)