From 835f5aa8af039d4617c030db28385142d7078467 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 22 Mar 2024 16:00:53 +0200 Subject: [PATCH] Add `from_update_add_htlc` to `MsgHandlerInternal` impl --- lightning/src/ln/channelmanager.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 46ad7fafb20..f5af9ec2471 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -575,6 +575,23 @@ struct MsgHandleErrInternal { payment_hash: Option } impl MsgHandleErrInternal { + #[inline] + fn from_update_add_htlc(err: String, channel_id: ChannelId, payment_hash: PaymentHash) -> Self { + Self { + err: LightningError { + err: err.clone(), + action: msgs::ErrorAction::SendErrorMessage { + msg: msgs::ErrorMessage { + channel_id, + data: err + }, + }, + }, + closes_channel: false, + shutdown_finish: None, + payment_hash: Some(payment_hash) + } + } #[inline] fn send_err_msg_no_close(err: String, channel_id: ChannelId) -> Self { Self { @@ -6780,7 +6797,7 @@ where let peer_state_mutex = per_peer_state.get(counterparty_node_id) .ok_or_else(|| { debug_assert!(false); - MsgHandleErrInternal::send_err_msg_no_close(format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id), msg.channel_id) + MsgHandleErrInternal::from_update_add_htlc(format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id), msg.channel_id, msg.payment_hash) })?; let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; @@ -6838,7 +6855,7 @@ where "Got an update_add_htlc message for an unfunded channel!".into())), chan_phase_entry); } }, - hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id)) + hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::from_update_add_htlc(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id, msg.payment_hash)) } Ok(()) }