@@ -26,7 +26,7 @@ use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
2626use crate :: offers:: invoice:: Bolt12Invoice ;
2727use crate :: offers:: static_invoice:: StaticInvoice ;
2828use crate :: types:: features:: ChannelTypeFeatures ;
29- use crate :: ln:: msgs;
29+ use crate :: ln:: { msgs, LocalHTLCFailureReason } ;
3030use crate :: ln:: types:: ChannelId ;
3131use crate :: types:: payment:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
3232use crate :: onion_message:: messenger:: Responder ;
@@ -525,6 +525,31 @@ impl_writeable_tlv_based_enum_upgradable!(HTLCHandlingFailureType,
525525 } ,
526526) ;
527527
528+ /// The reason for HTLC failures in [`Event::HTLCHandlingFailed`].
529+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
530+ pub enum HTLCHandlingFailureReason {
531+ /// The forwarded HTLC was failed back by the downstream node with an encrypted error reason.
532+ Downstream ,
533+ /// The HTLC was failed locally by our node.
534+ Local {
535+ /// The reason that our node chose to fail the HTLC.
536+ reason : LocalHTLCFailureReason ,
537+ } ,
538+ }
539+
540+ impl_writeable_tlv_based_enum ! ( HTLCHandlingFailureReason ,
541+ ( 1 , Downstream ) => { } ,
542+ ( 3 , Local ) => {
543+ ( 0 , reason, required) ,
544+ } ,
545+ ) ;
546+
547+ impl From < LocalHTLCFailureReason > for HTLCHandlingFailureReason {
548+ fn from ( value : LocalHTLCFailureReason ) -> Self {
549+ HTLCHandlingFailureReason :: Local { reason : value }
550+ }
551+ }
552+
528553/// Will be used in [`Event::HTLCIntercepted`] to identify the next hop in the HTLC's path.
529554/// Currently only used in serialization for the sake of maintaining compatibility. More variants
530555/// will be added for general-purpose HTLC forward intercepts as well as trampoline forward
@@ -1462,6 +1487,10 @@ pub enum Event {
14621487 prev_channel_id : ChannelId ,
14631488 /// The type of HTLC handling that failed.
14641489 failure_type : HTLCHandlingFailureType ,
1490+ /// The reason that the HTLC failed.
1491+ ///
1492+ /// This field will be `None` only for objects serialized prior to LDK 0.2.0.
1493+ failure_reason : Option < HTLCHandlingFailureReason >
14651494 } ,
14661495 /// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
14671496 /// requires confirmed external funds to be readily available to spend.
@@ -1766,10 +1795,11 @@ impl Writeable for Event {
17661795 ( 8 , path. blinded_tail, option) ,
17671796 } )
17681797 } ,
1769- & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failure_type } => {
1798+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failure_type, ref failure_reason } => {
17701799 25u8 . write ( writer) ?;
17711800 write_tlv_fields ! ( writer, {
17721801 ( 0 , prev_channel_id, required) ,
1802+ ( 1 , failure_reason, option) ,
17731803 ( 2 , failure_type, required) ,
17741804 } )
17751805 } ,
@@ -2218,14 +2248,17 @@ impl MaybeReadable for Event {
22182248 25u8 => {
22192249 let mut f = || {
22202250 let mut prev_channel_id = ChannelId :: new_zero ( ) ;
2251+ let mut failure_reason = None ;
22212252 let mut failure_type_opt = UpgradableRequired ( None ) ;
22222253 read_tlv_fields ! ( reader, {
22232254 ( 0 , prev_channel_id, required) ,
2255+ ( 1 , failure_reason, option) ,
22242256 ( 2 , failure_type_opt, upgradable_required) ,
22252257 } ) ;
22262258 Ok ( Some ( Event :: HTLCHandlingFailed {
22272259 prev_channel_id,
22282260 failure_type : _init_tlv_based_struct_field ! ( failure_type_opt, upgradable_required) ,
2261+ failure_reason,
22292262 } ) )
22302263 } ;
22312264 f ( )
0 commit comments