Skip to content

Commit

Permalink
Add from_update_add_htlc to MsgHandlerInternal impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Apr 8, 2024
1 parent 4436b65 commit 64dc482
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,23 @@ struct MsgHandleErrInternal {
payment_hash: Option<PaymentHash>
}
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 {
Expand Down Expand Up @@ -6959,7 +6976,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;
Expand Down Expand Up @@ -7018,7 +7035,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(())
}
Expand Down

0 comments on commit 64dc482

Please sign in to comment.