@@ -152,6 +152,51 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
152
152
( 12 , OutdatedChannelManager ) => { } ,
153
153
) ;
154
154
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, since prior versions 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 a 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
+ /// * Attempting to claim a payment without any HTLCs left over
181
+ FailedPayment {
182
+ /// The payment hash of the payment we attempted to process.
183
+ payment_hash : PaymentHash
184
+ } ,
185
+ }
186
+
187
+ impl_writeable_tlv_based_enum_upgradable ! ( HTLCDestination ,
188
+ ( 0 , NextHopChannel ) => {
189
+ ( 0 , node_id, required) ,
190
+ ( 2 , channel_id, required) ,
191
+ } ,
192
+ ( 2 , UnknownNextHop ) => {
193
+ ( 0 , requested_forward_scid, required) ,
194
+ } ,
195
+ ( 4 , FailedPayment ) => {
196
+ ( 0 , payment_hash, required) ,
197
+ }
198
+ ) ;
199
+
155
200
/// An Event which you should probably take some action in response to.
156
201
///
157
202
/// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
@@ -540,6 +585,19 @@ pub enum Event {
540
585
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
541
586
channel_type : ChannelTypeFeatures ,
542
587
} ,
588
+ /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
589
+ /// forward it. Some scenarios where this event may be sent include:
590
+ /// * Insufficient capacity in the outbound channel
591
+ /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
592
+ /// * When forwarding for a phantom payment, the scid to forward to was invalid
593
+ /// * Claiming an amount for an MPP payment that exceeds the HTLC total
594
+ /// * The HTLC has timed out
595
+ HTLCHandlingFailed {
596
+ /// The channel over which the HTLC was received.
597
+ prev_channel_id : [ u8 ; 32 ] ,
598
+ /// Destination of the HTLC that failed to be processed.
599
+ failed_next_destination : HTLCDestination ,
600
+ } ,
543
601
}
544
602
545
603
impl Writeable for Event {
@@ -684,6 +742,13 @@ impl Writeable for Event {
684
742
( 6 , short_channel_id, option) ,
685
743
} )
686
744
} ,
745
+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
746
+ 25u8 . write ( writer) ?;
747
+ write_tlv_fields ! ( writer, {
748
+ ( 0 , prev_channel_id, required) ,
749
+ ( 2 , failed_next_destination, required) ,
750
+ } )
751
+ } ,
687
752
// Note that, going forward, all new events must only write data inside of
688
753
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
689
754
// data via `write_tlv_fields`.
0 commit comments