Skip to content

Commit

Permalink
Add from_update_add_htlc to MsgHandlerInternal impl
Browse files Browse the repository at this point in the history
  Have the same functionality as `send_err_msg_no_close` but with
  `payment_hash` added as a new required argument.
  • Loading branch information
jbesraa committed May 9, 2024
1 parent 4b89261 commit 99539d7
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 @@ -581,6 +581,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 @@ -7638,7 +7655,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 @@ -7697,7 +7714,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 99539d7

Please sign in to comment.