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