@@ -627,6 +627,26 @@ pub enum InboundChannelFunds {
627
627
DualFunded ,
628
628
}
629
629
630
+ /// Used to describe the types of failures that may occur when handling HTLCs.
631
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
632
+ pub enum HTLCHandlingFailure {
633
+ /// The HTLC was failed by the local node.
634
+ Local {
635
+ /// The BOLT 04 failure code providing a specific failure reason.
636
+ failure_code : u16
637
+ } ,
638
+ /// The HTLC was failed by the remote downstream node. The specific reason for failure is not
639
+ /// known because it is encrypted.
640
+ Remote ,
641
+ }
642
+
643
+ impl_writeable_tlv_based_enum ! ( HTLCHandlingFailure ,
644
+ ( 0 , Local ) => {
645
+ ( 0 , failure_code, required)
646
+ } ,
647
+ ( 1 , Remote ) => { } ,
648
+ ) ;
649
+
630
650
/// An Event which you should probably take some action in response to.
631
651
///
632
652
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -1441,6 +1461,10 @@ pub enum Event {
1441
1461
prev_channel_id : ChannelId ,
1442
1462
/// Destination of the HTLC that failed to be processed.
1443
1463
failed_next_destination : HTLCDestination ,
1464
+ /// The cause of the processing failure.
1465
+ ///
1466
+ /// This field will be `None` for objects serialized prior to LDK 0.1.1.
1467
+ reason : Option < HTLCHandlingFailure > ,
1444
1468
} ,
1445
1469
/// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
1446
1470
/// requires confirmed external funds to be readily available to spend.
@@ -1743,10 +1767,11 @@ impl Writeable for Event {
1743
1767
( 8 , path. blinded_tail, option) ,
1744
1768
} )
1745
1769
} ,
1746
- & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
1770
+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination, ref reason } => {
1747
1771
25u8 . write ( writer) ?;
1748
1772
write_tlv_fields ! ( writer, {
1749
1773
( 0 , prev_channel_id, required) ,
1774
+ ( 1 , reason, option) ,
1750
1775
( 2 , failed_next_destination, required) ,
1751
1776
} )
1752
1777
} ,
@@ -2190,13 +2215,16 @@ impl MaybeReadable for Event {
2190
2215
let mut f = || {
2191
2216
let mut prev_channel_id = ChannelId :: new_zero ( ) ;
2192
2217
let mut failed_next_destination_opt = UpgradableRequired ( None ) ;
2218
+ let mut reason = None ;
2193
2219
read_tlv_fields ! ( reader, {
2194
2220
( 0 , prev_channel_id, required) ,
2221
+ ( 1 , reason, option) ,
2195
2222
( 2 , failed_next_destination_opt, upgradable_required) ,
2196
2223
} ) ;
2197
2224
Ok ( Some ( Event :: HTLCHandlingFailed {
2198
2225
prev_channel_id,
2199
2226
failed_next_destination : _init_tlv_based_struct_field ! ( failed_next_destination_opt, upgradable_required) ,
2227
+ reason,
2200
2228
} ) )
2201
2229
} ;
2202
2230
f ( )
0 commit comments