Skip to content

Commit 195802d

Browse files
committed
Return outgoing scid along with HTLC failure message
In order to surface `HTLCHandlingFailed` events for HTLCs that we cannot forward, we need to track their intended outgoing short channel ID, if one exists, to provide it as part of the event.
1 parent 0b355fc commit 195802d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,12 +3162,10 @@ where
31623162

31633163
fn decode_update_add_htlc_onion(
31643164
&self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, channel: Option<&mut Channel<SP>>,
3165-
) -> Result<
3166-
(onion_utils::Hop, [u8; 32], Option<Result<PublicKey, secp256k1::Error>>), HTLCFailureMsg
3167-
> {
3165+
) -> Result<(onion_utils::Hop, [u8; 32], Option<Result<PublicKey, secp256k1::Error>>), (HTLCFailureMsg, Option<u64>)> {
31683166
let (next_hop, shared_secret, next_packet_details_opt) = decode_incoming_update_add_htlc_onion(
31693167
msg, &self.node_signer, &self.logger, &self.secp_ctx
3170-
)?;
3168+
).map_err(|fail_msg| (fail_msg, None))?;
31713169

31723170
let next_packet_details = match next_packet_details_opt {
31733171
Some(next_packet_details) => next_packet_details,
@@ -3185,7 +3183,14 @@ where
31853183
};
31863184

31873185
let fail_msg_from_err = |err_msg: &'static str, err_code: u16, chan_update: Option<msgs::ChannelUpdate>| {
3188-
self.process_failed_accept_err(msg, counterparty_node_id, err_msg, err_code, chan_update, is_intro_node_forward, &shared_secret)
3186+
let fail_msg = self.process_failed_accept_err(
3187+
msg, counterparty_node_id, err_msg, err_code, chan_update, is_intro_node_forward, &shared_secret
3188+
);
3189+
let outgoing_scid = match &fail_msg {
3190+
HTLCFailureMsg::Relay(_) => Some(next_packet_details.outgoing_scid),
3191+
HTLCFailureMsg::Malformed(_) => None,
3192+
};
3193+
(fail_msg, outgoing_scid)
31893194
};
31903195

31913196
let res = if let Some(channel) = channel {
@@ -6679,7 +6684,7 @@ where
66796684
msg, counterparty_node_id, shared_secret, next_hop,
66806685
chan.context.config().accept_underpaying_htlcs, next_packet_pk_opt,
66816686
),
6682-
Err(e) => PendingHTLCStatus::Fail(e)
6687+
Err((fail_msg, _)) => PendingHTLCStatus::Fail(fail_msg)
66836688
};
66846689
let create_pending_htlc_status = |chan: &Channel<SP>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
66856690
if msg.blinding_point.is_some() {

0 commit comments

Comments
 (0)