@@ -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
///
@@ -879,8 +888,8 @@ pub enum Event {
879
888
payment_hash : Option < PaymentHash > ,
880
889
/// The reason the payment failed. This is only `None` for events generated or serialized
881
890
/// by versions prior to 0.0.115, when deserializing an `Event::InvoiceRequestFailed` (which
882
- /// was removed in 0.0.124), or when downgrading to 0.0.124 or later with a reason that was
883
- /// added after.
891
+ /// was removed in 0.0.124), or when downgrading to a version with a reason that was added
892
+ /// after.
884
893
reason : Option < PaymentFailureReason > ,
885
894
} ,
886
895
/// Indicates that a path for an outbound payment was successful.
@@ -1555,11 +1564,30 @@ impl Writeable for Event {
1555
1564
Some ( payment_hash) => ( payment_hash, true ) ,
1556
1565
None => ( & PaymentHash ( [ 0 ; 32 ] ) , false ) ,
1557
1566
} ;
1567
+ let legacy_reason = match reason {
1568
+ None => & None ,
1569
+ // Variants available prior to version 0.0.124.
1570
+ Some ( PaymentFailureReason :: RecipientRejected )
1571
+ | Some ( PaymentFailureReason :: UserAbandoned )
1572
+ | Some ( PaymentFailureReason :: RetriesExhausted )
1573
+ | Some ( PaymentFailureReason :: PaymentExpired )
1574
+ | Some ( PaymentFailureReason :: RouteNotFound )
1575
+ | Some ( PaymentFailureReason :: UnexpectedError ) => reason,
1576
+ // Variants introduced at version 0.0.124 or later. Prior versions fail to parse
1577
+ // unknown variants, while versions 0.0.124 or later will use None.
1578
+ Some ( PaymentFailureReason :: UnknownRequiredFeatures ) =>
1579
+ & Some ( PaymentFailureReason :: RecipientRejected ) ,
1580
+ Some ( PaymentFailureReason :: InvoiceRequestExpired ) =>
1581
+ & Some ( PaymentFailureReason :: RetriesExhausted ) ,
1582
+ Some ( PaymentFailureReason :: InvoiceRequestRejected ) =>
1583
+ & Some ( PaymentFailureReason :: RecipientRejected ) ,
1584
+ } ;
1558
1585
write_tlv_fields ! ( writer, {
1559
1586
( 0 , payment_id, required) ,
1560
- ( 1 , reason , option) ,
1587
+ ( 1 , legacy_reason , option) ,
1561
1588
( 2 , payment_hash, required) ,
1562
1589
( 3 , invoice_received, required) ,
1590
+ ( 5 , reason, option) ,
1563
1591
} )
1564
1592
} ,
1565
1593
& Event :: OpenChannelRequest { .. } => {
@@ -1927,17 +1955,20 @@ impl MaybeReadable for Event {
1927
1955
let mut payment_hash = PaymentHash ( [ 0 ; 32 ] ) ;
1928
1956
let mut payment_id = PaymentId ( [ 0 ; 32 ] ) ;
1929
1957
let mut reason = None ;
1958
+ let mut legacy_reason = None ;
1930
1959
let mut invoice_received: Option < bool > = None ;
1931
1960
read_tlv_fields ! ( reader, {
1932
1961
( 0 , payment_id, required) ,
1933
- ( 1 , reason , upgradable_option) ,
1962
+ ( 1 , legacy_reason , upgradable_option) ,
1934
1963
( 2 , payment_hash, required) ,
1935
1964
( 3 , invoice_received, option) ,
1965
+ ( 5 , reason, upgradable_option) ,
1936
1966
} ) ;
1937
1967
let payment_hash = match invoice_received {
1938
1968
Some ( invoice_received) => invoice_received. then ( || payment_hash) ,
1939
1969
None => ( payment_hash != PaymentHash ( [ 0 ; 32 ] ) ) . then ( || payment_hash) ,
1940
1970
} ;
1971
+ let reason = reason. or ( legacy_reason) ;
1941
1972
Ok ( Some ( Event :: PaymentFailed {
1942
1973
payment_id,
1943
1974
payment_hash,
0 commit comments