Skip to content

Commit 77a7457

Browse files
committed
Add HTLCHandlingFailed event
Adds a HTLCHandlingFailed that expresses failure by our node to process a specific HTLC. A HTLCDestination enum is defined to express the possible cases that causes the handling to fail.
1 parent 5cca9a0 commit 77a7457

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
860860
events::Event::PendingHTLCsForwardable { .. } => {
861861
nodes[$node].process_pending_htlc_forwards();
862862
},
863+
events::Event::HTLCHandlingFailed { .. } => {},
863864
_ => if out.may_fail.load(atomic::Ordering::Acquire) {
864865
return;
865866
} else {

lightning/src/util/events.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,14 @@ pub enum Event {
540540
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
541541
channel_type: ChannelTypeFeatures,
542542
},
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+
},
543551
}
544552

545553
impl Writeable for Event {
@@ -684,6 +692,13 @@ impl Writeable for Event {
684692
(6, short_channel_id, option),
685693
})
686694
},
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+
},
687702
// Note that, going forward, all new events must only write data inside of
688703
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
689704
// data via `write_tlv_fields`.
@@ -1178,3 +1193,48 @@ impl<T: EventHandler> EventHandler for Arc<T> {
11781193
self.deref().handle_event(event)
11791194
}
11801195
}
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

Comments
 (0)