@@ -480,12 +480,16 @@ pub enum HTLCHandlingFailureType {
480480 channel_id : ChannelId ,
481481 } ,
482482 /// 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.
483485 UnknownNextHop {
484486 /// Short channel id we are requesting to forward an HTLC to.
485487 requested_forward_scid : u64 ,
486488 } ,
487489 /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
488490 /// intercept HTLC.
491+ ///
492+ /// In LDK v0.2.0 and greater, this variant replaces [`Self::UnknownNextHop`].
489493 InvalidForward {
490494 /// Short channel id we are requesting to forward an HTLC to.
491495 requested_forward_scid : u64
@@ -1797,10 +1801,26 @@ impl Writeable for Event {
17971801 } ,
17981802 & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failure_type, ref failure_reason } => {
17991803 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+
18001820 write_tlv_fields ! ( writer, {
18011821 ( 0 , prev_channel_id, required) ,
18021822 ( 1 , failure_reason, option) ,
1803- ( 2 , failure_type , required) ,
1823+ ( 2 , downgradable_type , required) ,
18041824 } )
18051825 } ,
18061826 & Event :: BumpTransaction ( ref event) => {
@@ -2255,11 +2275,31 @@ impl MaybeReadable for Event {
22552275 ( 1 , failure_reason, option) ,
22562276 ( 2 , failure_type_opt, upgradable_required) ,
22572277 } ) ;
2258- Ok ( Some ( Event :: HTLCHandlingFailed {
2278+
2279+ let mut event = Event :: HTLCHandlingFailed {
22592280 prev_channel_id,
22602281 failure_type : _init_tlv_based_struct_field ! ( failure_type_opt, upgradable_required) ,
22612282 failure_reason,
2262- } ) )
2283+ } ;
2284+
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+ }
2301+
2302+ Ok ( Some ( event) )
22632303 } ;
22642304 f ( )
22652305 } ,
0 commit comments