@@ -14,8 +14,8 @@ use crate::io::{
1414use crate :: logger:: { log_error, log_info, Logger } ;
1515
1616use lightning:: chain:: chaininterface:: ConfirmationTarget ;
17- use lightning:: events:: Event as LdkEvent ;
1817use lightning:: events:: PaymentPurpose ;
18+ use lightning:: events:: { Event as LdkEvent , PaymentFailureReason } ;
1919use lightning:: impl_writeable_tlv_based_enum;
2020use lightning:: ln:: { ChannelId , PaymentHash } ;
2121use lightning:: routing:: gossip:: NodeId ;
@@ -52,6 +52,10 @@ pub enum Event {
5252 PaymentFailed {
5353 /// The hash of the payment.
5454 payment_hash : PaymentHash ,
55+ /// The reason why the payment failed.
56+ ///
57+ /// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
58+ reason : Option < PaymentFailureReason > ,
5559 } ,
5660 /// A payment has been received.
5761 PaymentReceived {
@@ -103,6 +107,7 @@ impl_writeable_tlv_based_enum!(Event,
103107 } ,
104108 ( 1 , PaymentFailed ) => {
105109 ( 0 , payment_hash, required) ,
110+ ( 1 , reason, option) ,
106111 } ,
107112 ( 2 , PaymentReceived ) => {
108113 ( 0 , payment_hash, required) ,
@@ -609,11 +614,12 @@ where
609614 panic ! ( "Failed to push to event queue" ) ;
610615 } ) ;
611616 }
612- LdkEvent :: PaymentFailed { payment_hash, .. } => {
617+ LdkEvent :: PaymentFailed { payment_hash, reason , .. } => {
613618 log_info ! (
614619 self . logger,
615- "Failed to send payment to payment hash {:?}." ,
616- hex_utils:: to_string( & payment_hash. 0 )
620+ "Failed to send payment to payment hash {:?} due to {:?}." ,
621+ hex_utils:: to_string( & payment_hash. 0 ) ,
622+ reason
617623 ) ;
618624
619625 let update = PaymentDetailsUpdate {
@@ -624,12 +630,12 @@ where
624630 log_error ! ( self . logger, "Failed to access payment store: {}" , e) ;
625631 panic ! ( "Failed to access payment store" ) ;
626632 } ) ;
627- self . event_queue . add_event ( Event :: PaymentFailed { payment_hash } ) . unwrap_or_else (
628- |e| {
633+ self . event_queue
634+ . add_event ( Event :: PaymentFailed { payment_hash, reason } )
635+ . unwrap_or_else ( |e| {
629636 log_error ! ( self . logger, "Failed to push to event queue: {}" , e) ;
630637 panic ! ( "Failed to push to event queue" ) ;
631- } ,
632- ) ;
638+ } ) ;
633639 }
634640
635641 LdkEvent :: PaymentPathSuccessful { .. } => { }
0 commit comments