Skip to content

Commit fd7da7f

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 3f34ded commit fd7da7f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lightning/src/events/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -10722,17 +10726,6 @@ where
1072210726
let secp_ctx = &self.secp_ctx;
1072310727
let expanded_key = &self.inbound_payment_key;
1072410728

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

1085710852
let error = InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures);
1085810853
let response = match responder {
@@ -10909,10 +10904,21 @@ where
1090910904
Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
1091010905
_ => None,
1091110906
};
10907+
1091210908
let logger = WithContext::from(&self.logger, None, None, payment_hash);
1091310909
log_trace!(logger, "Received invoice_error: {}", invoice_error);
1091410910

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

0 commit comments

Comments
 (0)