@@ -502,6 +502,12 @@ impl_writeable_tlv_based_enum!(InterceptNextHop,
502
502
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
503
503
pub enum PaymentFailureReason {
504
504
/// The intended recipient rejected our payment.
505
+ ///
506
+ /// Also used for [`UnknownRequiredFeatures`] and [`InvoiceRequestRejected`] when downgrading to
507
+ /// version prior to 0.0.124.
508
+ ///
509
+ /// [`UnknownRequiredFeatures`]: Self::UnknownRequiredFeatures
510
+ /// [`InvoiceRequestRejected`]: Self::InvoiceRequestRejected
505
511
RecipientRejected ,
506
512
/// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
507
513
///
@@ -517,7 +523,10 @@ pub enum PaymentFailureReason {
517
523
/// The payment expired while retrying, based on the provided
518
524
/// [`PaymentParameters::expiry_time`].
519
525
///
526
+ /// Also used for [`InvoiceRequestExpired`] when downgrading to version prior to 0.0.124.
527
+ ///
520
528
/// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
529
+ /// [`InvoiceRequestExpired`]: Self::InvoiceRequestExpired
521
530
PaymentExpired ,
522
531
/// We failed to find a route while retrying the payment.
523
532
///
@@ -528,12 +537,23 @@ pub enum PaymentFailureReason {
528
537
/// This error should generally never happen. This likely means that there is a problem with
529
538
/// your router.
530
539
UnexpectedError ,
540
+ /// An invoice was received that required unknown features.
541
+ UnknownRequiredFeatures ,
542
+ /// A [`Bolt12Invoice`] was not received in a reasonable amount of time.
543
+ InvoiceRequestExpired ,
544
+ /// An [`InvoiceRequest`] for the payment was rejected by the recipient.
545
+ ///
546
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
547
+ InvoiceRequestRejected ,
531
548
}
532
549
533
- impl_writeable_tlv_based_enum ! ( PaymentFailureReason ,
550
+ impl_writeable_tlv_based_enum_upgradable ! ( PaymentFailureReason ,
534
551
( 0 , RecipientRejected ) => { } ,
552
+ ( 1 , UnknownRequiredFeatures ) => { } ,
535
553
( 2 , UserAbandoned ) => { } ,
554
+ ( 3 , InvoiceRequestExpired ) => { } ,
536
555
( 4 , RetriesExhausted ) => { } ,
556
+ ( 5 , InvoiceRequestRejected ) => { } ,
537
557
( 6 , PaymentExpired ) => { } ,
538
558
( 8 , RouteNotFound ) => { } ,
539
559
( 10 , UnexpectedError ) => { } ,
@@ -769,22 +789,6 @@ pub enum Event {
769
789
/// Sockets for connecting to the node.
770
790
addresses : Vec < msgs:: SocketAddress > ,
771
791
} ,
772
- /// Indicates a request for an invoice failed to yield a response in a reasonable amount of time
773
- /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an
774
- /// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed.
775
- ///
776
- /// # Failure Behavior and Persistence
777
- /// This event will eventually be replayed after failures-to-handle (i.e., the event handler
778
- /// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
779
- ///
780
- /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
781
- /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
782
- /// [`Offer`]: crate::offers::offer::Offer
783
- /// [`Refund`]: crate::offers::refund::Refund
784
- InvoiceRequestFailed {
785
- /// The `payment_id` to have been associated with payment for the requested invoice.
786
- payment_id : PaymentId ,
787
- } ,
788
792
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
789
793
/// received.
790
794
///
@@ -876,12 +880,15 @@ pub enum Event {
876
880
///
877
881
/// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
878
882
payment_id : PaymentId ,
879
- /// The hash that was given to [`ChannelManager::send_payment`].
883
+ /// The hash that was given to [`ChannelManager::send_payment`]. `None` if the payment failed
884
+ /// before receiving an invoice when paying a BOLT12 [`Offer`].
880
885
///
881
886
/// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
882
- payment_hash : PaymentHash ,
887
+ /// [`Offer`]: crate::offers::offer::Offer
888
+ payment_hash : Option < PaymentHash > ,
883
889
/// The reason the payment failed. This is only `None` for events generated or serialized
884
- /// by versions prior to 0.0.115.
890
+ /// by versions prior to 0.0.115, or when downgrading to a version with a reason that was
891
+ /// added after.
885
892
reason : Option < PaymentFailureReason > ,
886
893
} ,
887
894
/// Indicates that a path for an outbound payment was successful.
@@ -1552,10 +1559,34 @@ impl Writeable for Event {
1552
1559
} ,
1553
1560
& Event :: PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
1554
1561
15u8 . write ( writer) ?;
1562
+ let ( payment_hash, invoice_received) = match payment_hash {
1563
+ Some ( payment_hash) => ( payment_hash, true ) ,
1564
+ None => ( & PaymentHash ( [ 0 ; 32 ] ) , false ) ,
1565
+ } ;
1566
+ let legacy_reason = match reason {
1567
+ None => & None ,
1568
+ // Variants available prior to version 0.0.124.
1569
+ Some ( PaymentFailureReason :: RecipientRejected )
1570
+ | Some ( PaymentFailureReason :: UserAbandoned )
1571
+ | Some ( PaymentFailureReason :: RetriesExhausted )
1572
+ | Some ( PaymentFailureReason :: PaymentExpired )
1573
+ | Some ( PaymentFailureReason :: RouteNotFound )
1574
+ | Some ( PaymentFailureReason :: UnexpectedError ) => reason,
1575
+ // Variants introduced at version 0.0.124 or later. Prior versions fail to parse
1576
+ // unknown variants, while versions 0.0.124 or later will use None.
1577
+ Some ( PaymentFailureReason :: UnknownRequiredFeatures ) =>
1578
+ & Some ( PaymentFailureReason :: RecipientRejected ) ,
1579
+ Some ( PaymentFailureReason :: InvoiceRequestExpired ) =>
1580
+ & Some ( PaymentFailureReason :: RetriesExhausted ) ,
1581
+ Some ( PaymentFailureReason :: InvoiceRequestRejected ) =>
1582
+ & Some ( PaymentFailureReason :: RecipientRejected ) ,
1583
+ } ;
1555
1584
write_tlv_fields ! ( writer, {
1556
1585
( 0 , payment_id, required) ,
1557
- ( 1 , reason , option) ,
1586
+ ( 1 , legacy_reason , option) ,
1558
1587
( 2 , payment_hash, required) ,
1588
+ ( 3 , invoice_received, required) ,
1589
+ ( 5 , reason, option) ,
1559
1590
} )
1560
1591
} ,
1561
1592
& Event :: OpenChannelRequest { .. } => {
@@ -1634,12 +1665,6 @@ impl Writeable for Event {
1634
1665
( 8 , funding_txo, required) ,
1635
1666
} ) ;
1636
1667
} ,
1637
- & Event :: InvoiceRequestFailed { ref payment_id } => {
1638
- 33u8 . write ( writer) ?;
1639
- write_tlv_fields ! ( writer, {
1640
- ( 0 , payment_id, required) ,
1641
- } )
1642
- } ,
1643
1668
& Event :: ConnectionNeeded { .. } => {
1644
1669
35u8 . write ( writer) ?;
1645
1670
// Never write ConnectionNeeded events as buffered onion messages aren't serialized.
@@ -1929,15 +1954,24 @@ impl MaybeReadable for Event {
1929
1954
let mut payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
1930
1955
let mut payment_id = PaymentId ( [ 0 ; 32 ] ) ;
1931
1956
let mut reason = None ;
1957
+ let mut legacy_reason = None ;
1958
+ let mut invoice_received: Option < bool > = None ;
1932
1959
read_tlv_fields ! ( reader, {
1933
1960
( 0 , payment_id, required) ,
1934
- ( 1 , reason , upgradable_option) ,
1961
+ ( 1 , legacy_reason , upgradable_option) ,
1935
1962
( 2 , payment_hash, required) ,
1963
+ ( 3 , invoice_received, option) ,
1964
+ ( 5 , reason, upgradable_option) ,
1936
1965
} ) ;
1966
+ let payment_hash = match invoice_received {
1967
+ Some ( invoice_received) => invoice_received. then ( || payment_hash) ,
1968
+ None => ( payment_hash != PaymentHash ( [ 0 ; 32 ] ) ) . then ( || payment_hash) ,
1969
+ } ;
1970
+ let reason = reason. or ( legacy_reason) ;
1937
1971
Ok ( Some ( Event :: PaymentFailed {
1938
1972
payment_id,
1939
1973
payment_hash,
1940
- reason,
1974
+ reason : _init_tlv_based_struct_field ! ( reason , upgradable_option ) ,
1941
1975
} ) )
1942
1976
} ;
1943
1977
f ( )
@@ -2076,13 +2110,16 @@ impl MaybeReadable for Event {
2076
2110
} ;
2077
2111
f ( )
2078
2112
} ,
2113
+ // This was Event::InvoiceRequestFailed prior to version 0.0.124.
2079
2114
33u8 => {
2080
2115
let mut f = || {
2081
2116
_init_and_read_len_prefixed_tlv_fields ! ( reader, {
2082
2117
( 0 , payment_id, required) ,
2083
2118
} ) ;
2084
- Ok ( Some ( Event :: InvoiceRequestFailed {
2119
+ Ok ( Some ( Event :: PaymentFailed {
2085
2120
payment_id : payment_id. 0 . unwrap ( ) ,
2121
+ payment_hash : None ,
2122
+ reason : Some ( PaymentFailureReason :: InvoiceRequestExpired ) ,
2086
2123
} ) )
2087
2124
} ;
2088
2125
f ( )
0 commit comments