@@ -540,6 +540,19 @@ pub enum Event {
540
540
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
541
541
channel_type : ChannelTypeFeatures ,
542
542
} ,
543
+ /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
544
+ /// forward it. Some scenarios where this event may be sent include:
545
+ /// 1. While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
546
+ /// 2. When forwarding for a phantom payment, the scid to forward to was invalid
547
+ /// 3. Attempting to claim a payment without any HTLCs left over
548
+ /// 4. Claiming an amount for an MPP payment that exceeds the HTLC total
549
+ /// 5. The HTLC has timed out
550
+ HTLCHandlingFailed {
551
+ /// The channel over which the HTLC was received.
552
+ prev_channel_id : [ u8 ; 32 ] ,
553
+ /// Destination of the HTLC that failed to be processed.
554
+ failed_next_destination : HTLCDestination ,
555
+ } ,
543
556
}
544
557
545
558
impl Writeable for Event {
@@ -684,6 +697,13 @@ impl Writeable for Event {
684
697
( 6 , short_channel_id, option) ,
685
698
} )
686
699
} ,
700
+ & Event :: HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
701
+ 25u8 . write ( writer) ?;
702
+ write_tlv_fields ! ( writer, {
703
+ ( 0 , prev_channel_id, required) ,
704
+ ( 2 , failed_next_destination, required) ,
705
+ } )
706
+ } ,
687
707
// Note that, going forward, all new events must only write data inside of
688
708
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
689
709
// data via `write_tlv_fields`.
@@ -1178,3 +1198,48 @@ impl<T: EventHandler> EventHandler for Arc<T> {
1178
1198
self . deref ( ) . handle_event ( event)
1179
1199
}
1180
1200
}
1201
+
1202
+ /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
1203
+ #[ derive( Clone , Debug , PartialEq ) ]
1204
+ pub enum HTLCDestination {
1205
+ /// We tried forwarding to a channel, but failed to do so. An example of such an instance
1206
+ /// is when a channel closes while we were waiting to forward to it.
1207
+ NextHopChannel {
1208
+ /// The node_id of the next node. For backwards compatibility, this field is
1209
+ /// marked as optional, since prior versions may not always be able to provide
1210
+ /// counterparty node information.
1211
+ node_id : Option < PublicKey > ,
1212
+ /// The outgoing channel_id between us and the next node.
1213
+ channel_id : [ u8 ; 32 ] ,
1214
+ } ,
1215
+ /// Scenario where we are unsure of the next node to forward the HTLC to.
1216
+ UnknownNextHop {
1217
+ /// Short channel id we are requesting to forward a HTLC to.
1218
+ requested_forward_scid : u64 ,
1219
+ } ,
1220
+ /// Failure scenario where an HTLC may have been forwarded to be intended for us,
1221
+ /// but is invalid for some reason, so we reject it.
1222
+ ///
1223
+ /// Some of the reasons may include:
1224
+ /// 1. HTLC Timeouts
1225
+ /// 2. Expected MPP amount to claim does not equal HTLC total
1226
+ /// 3. Claimable amount does not match expected amount
1227
+ /// 4. Attempting to claim a payment without any HTLCs left over
1228
+ FailedPayment {
1229
+ /// The payment hash of the payment we attempted to process.
1230
+ payment_hash : PaymentHash
1231
+ } ,
1232
+ }
1233
+
1234
+ impl_writeable_tlv_based_enum_upgradable ! ( HTLCDestination ,
1235
+ ( 0 , NextHopChannel ) => {
1236
+ ( 0 , node_id, required) ,
1237
+ ( 2 , channel_id, required) ,
1238
+ } ,
1239
+ ( 2 , UnknownNextHop ) => {
1240
+ ( 0 , requested_forward_scid, required) ,
1241
+ } ,
1242
+ ( 4 , FailedPayment ) => {
1243
+ ( 0 , payment_hash, required) ,
1244
+ }
1245
+ ) ;
0 commit comments