@@ -26,7 +26,7 @@ use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
26
26
use crate :: offers:: invoice:: Bolt12Invoice ;
27
27
use crate :: offers:: static_invoice:: StaticInvoice ;
28
28
use crate :: types:: features:: ChannelTypeFeatures ;
29
- use crate :: ln:: msgs;
29
+ use crate :: ln:: { msgs, LocalHTLCFailureReason } ;
30
30
use crate :: ln:: types:: ChannelId ;
31
31
use crate :: types:: payment:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
32
32
use crate :: onion_message:: messenger:: Responder ;
@@ -525,6 +525,31 @@ impl_writeable_tlv_based_enum_upgradable!(HTLCHandlingType,
525
525
} ,
526
526
) ;
527
527
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
+
528
553
/// Will be used in [`Event::HTLCIntercepted`] to identify the next hop in the HTLC's path.
529
554
/// Currently only used in serialization for the sake of maintaining compatibility. More variants
530
555
/// will be added for general-purpose HTLC forward intercepts as well as trampoline forward
@@ -1462,6 +1487,10 @@ pub enum Event {
1462
1487
prev_channel_id : ChannelId ,
1463
1488
/// The type of HTLC that was handled.
1464
1489
handling_type : HTLCHandlingType ,
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
+ handling_failure : Option < HTLCHandlingFailureReason >
1465
1494
} ,
1466
1495
/// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
1467
1496
/// requires confirmed external funds to be readily available to spend.
@@ -1766,10 +1795,11 @@ impl Writeable for Event {
1766
1795
( 8 , path. blinded_tail, option) ,
1767
1796
} )
1768
1797
} ,
1769
- & Event :: HTLCHandlingFailed { ref prev_channel_id, ref handling_type } => {
1798
+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref handling_type, ref handling_failure } => {
1770
1799
25u8 . write ( writer) ?;
1771
1800
write_tlv_fields ! ( writer, {
1772
1801
( 0 , prev_channel_id, required) ,
1802
+ ( 1 , handling_failure, option) ,
1773
1803
( 2 , handling_type, required) ,
1774
1804
} )
1775
1805
} ,
@@ -2218,14 +2248,17 @@ impl MaybeReadable for Event {
2218
2248
25u8 => {
2219
2249
let mut f = || {
2220
2250
let mut prev_channel_id = ChannelId :: new_zero ( ) ;
2251
+ let mut handling_failure = None ;
2221
2252
let mut handling_type_opt = UpgradableRequired ( None ) ;
2222
2253
read_tlv_fields ! ( reader, {
2223
2254
( 0 , prev_channel_id, required) ,
2255
+ ( 1 , handling_failure, option) ,
2224
2256
( 2 , handling_type_opt, upgradable_required) ,
2225
2257
} ) ;
2226
2258
Ok ( Some ( Event :: HTLCHandlingFailed {
2227
2259
prev_channel_id,
2228
2260
handling_type : _init_tlv_based_struct_field ! ( handling_type_opt, upgradable_required) ,
2261
+ handling_failure,
2229
2262
} ) )
2230
2263
} ;
2231
2264
f ( )
0 commit comments