@@ -152,6 +152,50 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
152152 ( 12 , OutdatedChannelManager ) => { } ,
153153) ;
154154
155+ /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
156+ #[ derive( Clone , Debug , PartialEq ) ]
157+ pub enum HTLCDestination {
158+ /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
159+ /// there is insufficient capacity in our outbound channel.
160+ NextHopChannel {
161+ /// The `node_id` of the next node. For backwards compatibility, this field is
162+ /// marked as optional, versions prior to 0.0.110 may not always be able to provide
163+ /// counterparty node information.
164+ node_id : Option < PublicKey > ,
165+ /// The outgoing `channel_id` between us and the next node.
166+ channel_id : [ u8 ; 32 ] ,
167+ } ,
168+ /// Scenario where we are unsure of the next node to forward the HTLC to.
169+ UnknownNextHop {
170+ /// Short channel id we are requesting to forward an HTLC to.
171+ requested_forward_scid : u64 ,
172+ } ,
173+ /// Failure scenario where an HTLC may have been forwarded to be intended for us,
174+ /// but is invalid for some reason, so we reject it.
175+ ///
176+ /// Some of the reasons may include:
177+ /// * HTLC Timeouts
178+ /// * Expected MPP amount to claim does not equal HTLC total
179+ /// * Claimable amount does not match expected amount
180+ FailedPayment {
181+ /// The payment hash of the payment we attempted to process.
182+ payment_hash : PaymentHash
183+ } ,
184+ }
185+
186+ impl_writeable_tlv_based_enum_upgradable ! ( HTLCDestination ,
187+ ( 0 , NextHopChannel ) => {
188+ ( 0 , node_id, required) ,
189+ ( 2 , channel_id, required) ,
190+ } ,
191+ ( 2 , UnknownNextHop ) => {
192+ ( 0 , requested_forward_scid, required) ,
193+ } ,
194+ ( 4 , FailedPayment ) => {
195+ ( 0 , payment_hash, required) ,
196+ }
197+ ) ;
198+
155199/// An Event which you should probably take some action in response to.
156200///
157201/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -540,6 +584,24 @@ pub enum Event {
540584 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
541585 channel_type : ChannelTypeFeatures ,
542586 } ,
587+ /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
588+ /// forward it.
589+ ///
590+ /// Some scenarios where this event may be sent include:
591+ /// * Insufficient capacity in the outbound channel
592+ /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
593+ /// * When an unknown SCID is requested for forwarding a payment.
594+ /// * Claiming an amount for an MPP payment that exceeds the HTLC total
595+ /// * The HTLC has timed out
596+ ///
597+ /// This event, however, does not get generated if an HTLC fails to meet the forwarding
598+ /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
599+ HTLCHandlingFailed {
600+ /// The channel over which the HTLC was received.
601+ prev_channel_id : [ u8 ; 32 ] ,
602+ /// Destination of the HTLC that failed to be processed.
603+ failed_next_destination : HTLCDestination ,
604+ } ,
543605}
544606
545607impl Writeable for Event {
@@ -684,6 +746,13 @@ impl Writeable for Event {
684746 ( 6 , short_channel_id, option) ,
685747 } )
686748 } ,
749+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
750+ 25u8 . write ( writer) ?;
751+ write_tlv_fields ! ( writer, {
752+ ( 0 , prev_channel_id, required) ,
753+ ( 2 , failed_next_destination, required) ,
754+ } )
755+ } ,
687756 // Note that, going forward, all new events must only write data inside of
688757 // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
689758 // data via `write_tlv_fields`.
0 commit comments