Skip to content

Commit d2dcc14

Browse files
committed
Remove Event::InvoiceRequestFailed
Now that Event::PaymentFailed has an option payment_hash, it can be used in replace of Event::InvoiceRequestFailed. This allows for including a reason when abandoning a payment before an invoice is received.
1 parent 40c3004 commit d2dcc14

File tree

4 files changed

+33
-48
lines changed

4 files changed

+33
-48
lines changed

lightning/src/events/mod.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -772,22 +772,6 @@ pub enum Event {
772772
/// Sockets for connecting to the node.
773773
addresses: Vec<msgs::SocketAddress>,
774774
},
775-
/// Indicates a request for an invoice failed to yield a response in a reasonable amount of time
776-
/// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an
777-
/// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed.
778-
///
779-
/// # Failure Behavior and Persistence
780-
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
781-
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
782-
///
783-
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
784-
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
785-
/// [`Offer`]: crate::offers::offer::Offer
786-
/// [`Refund`]: crate::offers::refund::Refund
787-
InvoiceRequestFailed {
788-
/// The `payment_id` to have been associated with payment for the requested invoice.
789-
payment_id: PaymentId,
790-
},
791775
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
792776
/// received.
793777
///
@@ -886,7 +870,8 @@ pub enum Event {
886870
/// [`Offer`]: crate::offers::offer::Offer
887871
payment_hash: Option<PaymentHash>,
888872
/// The reason the payment failed. This is only `None` for events generated or serialized
889-
/// by versions prior to 0.0.115.
873+
/// by versions prior to 0.0.115 or when deserializing an `Event::InvoiceRequestFailed`,
874+
/// which was removed in 0.0.124.
890875
/// TODO: Will downgrading cause this to be None for UnknownRequiredFeatures?
891876
reason: Option<PaymentFailureReason>,
892877
},
@@ -1636,12 +1621,6 @@ impl Writeable for Event {
16361621
(8, funding_txo, required),
16371622
});
16381623
},
1639-
&Event::InvoiceRequestFailed { ref payment_id } => {
1640-
33u8.write(writer)?;
1641-
write_tlv_fields!(writer, {
1642-
(0, payment_id, required),
1643-
})
1644-
},
16451624
&Event::ConnectionNeeded { .. } => {
16461625
35u8.write(writer)?;
16471626
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
@@ -2078,13 +2057,16 @@ impl MaybeReadable for Event {
20782057
};
20792058
f()
20802059
},
2060+
// This was Event::InvoiceRequestFailed prior to version 0.0.124.
20812061
33u8 => {
20822062
let mut f = || {
20832063
_init_and_read_len_prefixed_tlv_fields!(reader, {
20842064
(0, payment_id, required),
20852065
});
2086-
Ok(Some(Event::InvoiceRequestFailed {
2066+
Ok(Some(Event::PaymentFailed {
20872067
payment_id: payment_id.0.unwrap(),
2068+
payment_hash: None,
2069+
reason: None,
20882070
}))
20892071
};
20902072
f()

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,7 @@ where
17451745
/// ```
17461746
///
17471747
/// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
1748-
/// and pays the [`Bolt12Invoice`] response. In addition to success and failure events,
1749-
/// [`ChannelManager`] may also generate an [`Event::InvoiceRequestFailed`].
1748+
/// and pays the [`Bolt12Invoice`] response.
17501749
///
17511750
/// ```
17521751
/// # use lightning::events::{Event, EventsProvider};
@@ -1788,7 +1787,6 @@ where
17881787
/// match event {
17891788
/// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
17901789
/// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
1791-
/// Event::InvoiceRequestFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
17921790
/// // ...
17931791
/// # _ => {},
17941792
/// }
@@ -4260,15 +4258,13 @@ where
42604258
/// # Requested Invoices
42614259
///
42624260
/// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning
4263-
/// the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`]
4264-
/// and prevent any attempts at paying it once received. The other events may only be generated
4265-
/// once the invoice has been received.
4261+
/// the payment prior to receiving the invoice will result in an [`Event::PaymentFailed`] and
4262+
/// prevent any attempts at paying it once received.
42664263
///
42674264
/// # Restart Behavior
42684265
///
42694266
/// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
4270-
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
4271-
/// [`Event::InvoiceRequestFailed`].
4267+
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
42724268
///
42734269
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
42744270
pub fn abandon_payment(&self, payment_id: PaymentId) {
@@ -8845,7 +8841,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
88458841
///
88468842
/// To revoke the refund, use [`ChannelManager::abandon_payment`] prior to receiving the
88478843
/// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
8848-
/// with an [`Event::InvoiceRequestFailed`].
8844+
/// with an [`Event::PaymentFailed`].
88498845
///
88508846
/// If `max_total_routing_fee_msat` is not specified, The default from
88518847
/// [`RouteParameters::from_payment_params_and_value`] is applied.
@@ -8961,7 +8957,7 @@ where
89618957
///
89628958
/// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
89638959
/// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
8964-
/// payment will fail with an [`Event::InvoiceRequestFailed`].
8960+
/// payment will fail with an [`Event::PaymentFailed`].
89658961
///
89668962
/// # Privacy
89678963
///

lightning/src/ln/offers_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ fn fails_authentication_when_handling_invoice_request() {
13321332
assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None);
13331333

13341334
david.node.abandon_payment(payment_id);
1335-
get_event!(david, Event::InvoiceRequestFailed);
1335+
get_event!(david, Event::PaymentFailed);
13361336

13371337
// Send the invoice request to Alice using an invalid blinded path.
13381338
let payment_id = PaymentId([2; 32]);
@@ -1419,7 +1419,7 @@ fn fails_authentication_when_handling_invoice_for_offer() {
14191419
david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
14201420
.unwrap();
14211421
david.node.abandon_payment(payment_id);
1422-
get_event!(david, Event::InvoiceRequestFailed);
1422+
get_event!(david, Event::PaymentFailed);
14231423

14241424
// Don't send the invoice request, but grab its reply path to use with a different request.
14251425
let invalid_reply_path = {
@@ -1547,7 +1547,7 @@ fn fails_authentication_when_handling_invoice_for_refund() {
15471547

15481548
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
15491549
david.node.abandon_payment(payment_id);
1550-
get_event!(david, Event::InvoiceRequestFailed);
1550+
get_event!(david, Event::PaymentFailed);
15511551

15521552
// Send the invoice to David using an invalid blinded path.
15531553
let invalid_path = refund.paths().first().unwrap().clone();
@@ -1931,11 +1931,11 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
19311931
assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
19321932

19331933
// Confirm that david drops this failed payment from his pending outbound payments.
1934-
match get_event!(david, Event::InvoiceRequestFailed) {
1935-
Event::InvoiceRequestFailed { payment_id: pay_id } => {
1936-
assert_eq!(pay_id, payment_id)
1934+
match get_event!(david, Event::PaymentFailed) {
1935+
Event::PaymentFailed { payment_id: actual_payment_id, .. } => {
1936+
assert_eq!(payment_id, actual_payment_id);
19371937
},
1938-
_ => panic!("No Event::InvoiceRequestFailed"),
1938+
_ => panic!("No Event::PaymentFailed"),
19391939
}
19401940
}
19411941

lightning/src/ln/outbound_payment.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,9 +1708,12 @@ impl OutboundPayments {
17081708
},
17091709
};
17101710
if is_stale {
1711-
pending_events.push_back(
1712-
(events::Event::InvoiceRequestFailed { payment_id: *payment_id }, None)
1713-
);
1711+
let event = events::Event::PaymentFailed {
1712+
payment_id: *payment_id,
1713+
payment_hash: None,
1714+
reason: None,
1715+
};
1716+
pending_events.push_back((event, None));
17141717
false
17151718
} else {
17161719
true
@@ -1870,8 +1873,10 @@ impl OutboundPayments {
18701873
payment.remove();
18711874
}
18721875
} else if let PendingOutboundPayment::AwaitingInvoice { .. } = payment.get() {
1873-
pending_events.lock().unwrap().push_back((events::Event::InvoiceRequestFailed {
1876+
pending_events.lock().unwrap().push_back((events::Event::PaymentFailed {
18741877
payment_id,
1878+
payment_hash: None,
1879+
reason: Some(reason),
18751880
}, None));
18761881
payment.remove();
18771882
}
@@ -2200,7 +2205,7 @@ mod tests {
22002205
assert!(!pending_events.lock().unwrap().is_empty());
22012206
assert_eq!(
22022207
pending_events.lock().unwrap().pop_front(),
2203-
Some((Event::InvoiceRequestFailed { payment_id }, None)),
2208+
Some((Event::PaymentFailed { payment_id, payment_hash: None, reason: None }, None)),
22042209
);
22052210
assert!(pending_events.lock().unwrap().is_empty());
22062211

@@ -2249,7 +2254,7 @@ mod tests {
22492254
assert!(!pending_events.lock().unwrap().is_empty());
22502255
assert_eq!(
22512256
pending_events.lock().unwrap().pop_front(),
2252-
Some((Event::InvoiceRequestFailed { payment_id }, None)),
2257+
Some((Event::PaymentFailed { payment_id, payment_hash: None, reason: None }, None)),
22532258
);
22542259
assert!(pending_events.lock().unwrap().is_empty());
22552260

@@ -2289,7 +2294,9 @@ mod tests {
22892294
assert!(!pending_events.lock().unwrap().is_empty());
22902295
assert_eq!(
22912296
pending_events.lock().unwrap().pop_front(),
2292-
Some((Event::InvoiceRequestFailed { payment_id }, None)),
2297+
Some((Event::PaymentFailed {
2298+
payment_id, payment_hash: None, reason: Some(PaymentFailureReason::UserAbandoned),
2299+
}, None)),
22932300
);
22942301
assert!(pending_events.lock().unwrap().is_empty());
22952302
}

0 commit comments

Comments
 (0)