@@ -481,7 +481,8 @@ pub enum HTLCHandlingFailureType {
481
481
} ,
482
482
/// Scenario where we are unsure of the next node to forward the HTLC to.
483
483
///
484
- /// Deprecated: will only be used in versions before LDK v0.2.0.
484
+ /// Deprecated: will only be used in versions before LDK v0.2.0. Downgrades will result in
485
+ /// this type being represented as [`Self::InvalidForward`].
485
486
UnknownNextHop {
486
487
/// Short channel id we are requesting to forward an HTLC to.
487
488
requested_forward_scid : u64 ,
@@ -1801,26 +1802,10 @@ impl Writeable for Event {
1801
1802
} ,
1802
1803
& Event :: HTLCHandlingFailed { ref prev_channel_id, ref failure_type, ref failure_reason } => {
1803
1804
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 ( failure_type, failure_reason) {
1810
- ( HTLCHandlingFailureType :: InvalidForward { requested_forward_scid } ,
1811
- Some ( HTLCHandlingFailureReason :: Local {
1812
- reason : LocalHTLCFailureReason :: UnknownNextPeer
1813
- } ) )
1814
- => HTLCHandlingFailureType :: UnknownNextHop {
1815
- requested_forward_scid : * requested_forward_scid,
1816
- } ,
1817
- _ => failure_type. clone ( )
1818
- } ;
1819
-
1820
1805
write_tlv_fields ! ( writer, {
1821
1806
( 0 , prev_channel_id, required) ,
1822
1807
( 1 , failure_reason, option) ,
1823
- ( 2 , downgradable_type , required) ,
1808
+ ( 2 , failure_type , required) ,
1824
1809
} )
1825
1810
} ,
1826
1811
& Event :: BumpTransaction ( ref event) => {
@@ -2276,30 +2261,34 @@ impl MaybeReadable for Event {
2276
2261
( 2 , failure_type_opt, upgradable_required) ,
2277
2262
} ) ;
2278
2263
2279
- let mut event = Event :: HTLCHandlingFailed {
2264
+ let event = Event :: HTLCHandlingFailed {
2280
2265
prev_channel_id,
2281
2266
failure_type : _init_tlv_based_struct_field ! ( failure_type_opt, upgradable_required) ,
2282
2267
failure_reason,
2283
2268
} ;
2284
2269
2285
- // The [`HTLCHandlingFailureType::UnknownNextPeer`] variant is deprecated, but
2286
- // we continue writing it to allow downgrading. If it was written, upgrade
2287
- // it to its new representation of [`HTLCHandlingFailureType::InvalidForward`]
2288
- // and [`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 { failure_type : HTLCHandlingFailureType :: UnknownNextHop { requested_forward_scid } , .. } => {
2293
- event = Event :: HTLCHandlingFailed {
2294
- prev_channel_id,
2295
- failure_type : HTLCHandlingFailureType :: InvalidForward { requested_forward_scid } ,
2296
- failure_reason : Some ( LocalHTLCFailureReason :: UnknownNextPeer . into ( ) ) ,
2297
- }
2298
- }
2299
- _ => panic ! ( "HTLCHandlingFailed wrong type" )
2300
- }
2270
+ // If a legacy HTLCHandlingFailureType::UnknownNextHop was written, upgrade
2271
+ // it to its new representation, otherwise leave unchanged.
2272
+ Ok ( Some ( match event {
2273
+ Event :: HTLCHandlingFailed { prev_channel_id, ref failure_type, ref failure_reason } => {
2274
+ match failure_type {
2275
+ HTLCHandlingFailureType :: UnknownNextHop { requested_forward_scid } => {
2276
+ debug_assert ! ( failure_reason. is_none( ) ,
2277
+ "new failure reason should not be written with legacy UnknownNextHop type" ) ;
2301
2278
2302
- Ok ( Some ( event) )
2279
+ Event :: HTLCHandlingFailed {
2280
+ prev_channel_id,
2281
+ failure_type : HTLCHandlingFailureType :: InvalidForward {
2282
+ requested_forward_scid : * requested_forward_scid,
2283
+ } ,
2284
+ failure_reason : Some ( LocalHTLCFailureReason :: UnknownNextPeer . into ( ) ) ,
2285
+ }
2286
+ }
2287
+ _ => event,
2288
+ }
2289
+ } ,
2290
+ _ => panic ! ( "Event::HTLCHandlingFailed type incorrect" ) ,
2291
+ } ) )
2303
2292
} ;
2304
2293
f ( )
2305
2294
} ,
0 commit comments