@@ -479,12 +479,16 @@ pub enum HTLCHandlingType {
479
479
channel_id : ChannelId ,
480
480
} ,
481
481
/// Scenario where we are unsure of the next node to forward the HTLC to.
482
+ ///
483
+ /// Deprecated: will only be used in versions before LDK v0.2.0.
482
484
UnknownNextHop {
483
485
/// Short channel id we are requesting to forward an HTLC to.
484
486
requested_forward_scid : u64 ,
485
487
} ,
486
488
/// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
487
489
/// intercept HTLC.
490
+ ///
491
+ /// In LDK v0.2.0 and greater, this variant replaces [`Self::UnknownNextHop`].
488
492
InvalidForward {
489
493
/// Short channel id we are requesting to forward an HTLC to.
490
494
requested_forward_scid : u64
@@ -1777,10 +1781,27 @@ impl Writeable for Event {
1777
1781
} ,
1778
1782
& Event :: HTLCHandlingFailed { ref prev_channel_id, ref handling_type, ref handling_failure } => {
1779
1783
25u8 . write ( writer) ?;
1784
+
1785
+ // The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we want to
1786
+ // continue writing it to allow downgrading. Detect the case where we're
1787
+ // representing it as [`HTLCHandlingType::InvalidForward`] and
1788
+ // [`LocalHTLCFailureReason::UnknownNextHop`] and write the old variant instead.
1789
+ let downgradable_type = match ( handling_type, handling_failure) {
1790
+ ( HTLCHandlingType :: InvalidForward { requested_forward_scid } ,
1791
+ Some ( HTLCHandlingFailureReason :: Local { reason } ) )
1792
+ if * reason == LocalHTLCFailureReason :: UnknownNextPeer =>
1793
+ {
1794
+ HTLCHandlingType :: UnknownNextHop {
1795
+ requested_forward_scid : * requested_forward_scid,
1796
+ }
1797
+ }
1798
+ _ => handling_type. clone ( )
1799
+ } ;
1800
+
1780
1801
write_tlv_fields ! ( writer, {
1781
1802
( 0 , prev_channel_id, required) ,
1782
1803
( 1 , handling_failure, option) ,
1783
- ( 2 , handling_type , required) ,
1804
+ ( 2 , downgradable_type , required) ,
1784
1805
} )
1785
1806
} ,
1786
1807
& Event :: BumpTransaction ( ref event) => {
@@ -2232,11 +2253,32 @@ impl MaybeReadable for Event {
2232
2253
( 1 , handling_failure, option) ,
2233
2254
( 2 , handling_type_opt, upgradable_required) ,
2234
2255
} ) ;
2235
- Ok ( Some ( Event :: HTLCHandlingFailed {
2256
+
2257
+ let mut event = Event :: HTLCHandlingFailed {
2236
2258
prev_channel_id,
2237
2259
handling_type : _init_tlv_based_struct_field ! ( handling_type_opt, upgradable_required) ,
2238
2260
handling_failure,
2239
- } ) )
2261
+ } ;
2262
+
2263
+ // The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we
2264
+ // continue writing it to allow downgrading. If it was written, upgrade
2265
+ // it to its new representation of [`HTLCHandlingType::InvalidForward`] and
2266
+ // [`LocalHTLCFailureReason::UnknownNextHop`]. This will cover both the case
2267
+ // where we have a legacy event
2268
+ match event {
2269
+ Event :: HTLCHandlingFailed { ref handling_type, .. } => {
2270
+ if let HTLCHandlingType :: UnknownNextHop { requested_forward_scid } = handling_type {
2271
+ event = Event :: HTLCHandlingFailed {
2272
+ prev_channel_id,
2273
+ handling_type : HTLCHandlingType :: InvalidForward { requested_forward_scid : * requested_forward_scid } ,
2274
+ handling_failure : Some ( LocalHTLCFailureReason :: UnknownNextPeer . into ( ) ) ,
2275
+ }
2276
+ }
2277
+ }
2278
+ _ => panic ! ( "HTLCHandlingFailed wrong type" )
2279
+ }
2280
+
2281
+ Ok ( Some ( event) )
2240
2282
} ;
2241
2283
f ( )
2242
2284
} ,
0 commit comments