@@ -480,12 +480,16 @@ pub enum HTLCHandlingType {
480
480
channel_id : ChannelId ,
481
481
} ,
482
482
/// Scenario where we are unsure of the next node to forward the HTLC to.
483
+ ///
484
+ /// Deprecated: will only be used in versions before LDK v0.2.0.
483
485
UnknownNextHop {
484
486
/// Short channel id we are requesting to forward an HTLC to.
485
487
requested_forward_scid : u64 ,
486
488
} ,
487
489
/// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
488
490
/// intercept HTLC.
491
+ ///
492
+ /// In LDK v0.2.0 and greater, this variant replaces [`Self::UnknownNextHop`].
489
493
InvalidForward {
490
494
/// Short channel id we are requesting to forward an HTLC to.
491
495
requested_forward_scid : u64
@@ -1797,10 +1801,27 @@ impl Writeable for Event {
1797
1801
} ,
1798
1802
& Event :: HTLCHandlingFailed { ref prev_channel_id, ref handling_type, ref handling_failure } => {
1799
1803
25u8 . write ( writer) ?;
1804
+
1805
+ // The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we want to
1806
+ // continue writing it to allow downgrading. Detect the case where we're
1807
+ // representing it as [`HTLCHandlingType::InvalidForward`] and
1808
+ // [`LocalHTLCFailureReason::UnknownNextHop`] and write the old variant instead.
1809
+ let downgradable_type = match ( handling_type, handling_failure) {
1810
+ ( HTLCHandlingType :: InvalidForward { requested_forward_scid } ,
1811
+ Some ( HTLCHandlingFailureReason :: Local { reason } ) )
1812
+ if * reason == LocalHTLCFailureReason :: UnknownNextPeer =>
1813
+ {
1814
+ HTLCHandlingType :: UnknownNextHop {
1815
+ requested_forward_scid : * requested_forward_scid,
1816
+ }
1817
+ }
1818
+ _ => handling_type. clone ( )
1819
+ } ;
1820
+
1800
1821
write_tlv_fields ! ( writer, {
1801
1822
( 0 , prev_channel_id, required) ,
1802
1823
( 1 , handling_failure, option) ,
1803
- ( 2 , handling_type , required) ,
1824
+ ( 2 , downgradable_type , required) ,
1804
1825
} )
1805
1826
} ,
1806
1827
& Event :: BumpTransaction ( ref event) => {
@@ -2255,11 +2276,32 @@ impl MaybeReadable for Event {
2255
2276
( 1 , handling_failure, option) ,
2256
2277
( 2 , handling_type_opt, upgradable_required) ,
2257
2278
} ) ;
2258
- Ok ( Some ( Event :: HTLCHandlingFailed {
2279
+
2280
+ let mut event = Event :: HTLCHandlingFailed {
2259
2281
prev_channel_id,
2260
2282
handling_type : _init_tlv_based_struct_field ! ( handling_type_opt, upgradable_required) ,
2261
2283
handling_failure,
2262
- } ) )
2284
+ } ;
2285
+
2286
+ // The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we
2287
+ // continue writing it to allow downgrading. If it was written, upgrade
2288
+ // it to its new representation of [`HTLCHandlingType::InvalidForward`] and
2289
+ // [`LocalHTLCFailureReason::UnknownNextHop`]. This will cover both the case
2290
+ // where we have a legacy event
2291
+ match event {
2292
+ Event :: HTLCHandlingFailed { ref handling_type, .. } => {
2293
+ if let HTLCHandlingType :: UnknownNextHop { requested_forward_scid } = handling_type {
2294
+ event = Event :: HTLCHandlingFailed {
2295
+ prev_channel_id,
2296
+ handling_type : HTLCHandlingType :: InvalidForward { requested_forward_scid : * requested_forward_scid } ,
2297
+ handling_failure : Some ( LocalHTLCFailureReason :: UnknownNextPeer . into ( ) ) ,
2298
+ }
2299
+ }
2300
+ }
2301
+ _ => panic ! ( "HTLCHandlingFailed wrong type" )
2302
+ }
2303
+
2304
+ Ok ( Some ( event) )
2263
2305
} ;
2264
2306
f ( )
2265
2307
} ,
0 commit comments