@@ -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,26 @@ 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 {
1812
+ reason : LocalHTLCFailureReason :: UnknownNextPeer
1813
+ } ) )
1814
+ => HTLCHandlingType :: UnknownNextHop {
1815
+ requested_forward_scid : * requested_forward_scid,
1816
+ } ,
1817
+ _ => handling_type. clone ( )
1818
+ } ;
1819
+
1800
1820
write_tlv_fields ! ( writer, {
1801
1821
( 0 , prev_channel_id, required) ,
1802
1822
( 1 , handling_failure, option) ,
1803
- ( 2 , handling_type , required) ,
1823
+ ( 2 , downgradable_type , required) ,
1804
1824
} )
1805
1825
} ,
1806
1826
& Event :: BumpTransaction ( ref event) => {
@@ -2255,11 +2275,31 @@ impl MaybeReadable for Event {
2255
2275
( 1 , handling_failure, option) ,
2256
2276
( 2 , handling_type_opt, upgradable_required) ,
2257
2277
} ) ;
2258
- Ok ( Some ( Event :: HTLCHandlingFailed {
2278
+
2279
+ let mut event = Event :: HTLCHandlingFailed {
2259
2280
prev_channel_id,
2260
2281
handling_type : _init_tlv_based_struct_field ! ( handling_type_opt, upgradable_required) ,
2261
2282
handling_failure,
2262
- } ) )
2283
+ } ;
2284
+
2285
+ // The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we
2286
+ // continue writing it to allow downgrading. If it was written, upgrade
2287
+ // it to its new representation of [`HTLCHandlingType::InvalidForward`] and
2288
+ // [`LocalHTLCFailureReason::UnknownNextHop`]. This will cover both the case
2289
+ // where we have a legacy event and new events that are written with the legacy
2290
+ // type be downgradable.
2291
+ match event {
2292
+ Event :: HTLCHandlingFailed { handling_type : HTLCHandlingType :: UnknownNextHop { requested_forward_scid } , .. } => {
2293
+ event = Event :: HTLCHandlingFailed {
2294
+ prev_channel_id,
2295
+ handling_type : HTLCHandlingType :: InvalidForward { requested_forward_scid } ,
2296
+ handling_failure : Some ( LocalHTLCFailureReason :: UnknownNextPeer . into ( ) ) ,
2297
+ }
2298
+ }
2299
+ _ => panic ! ( "HTLCHandlingFailed wrong type" )
2300
+ }
2301
+
2302
+ Ok ( Some ( event) )
2263
2303
} ;
2264
2304
f ( )
2265
2305
} ,
0 commit comments