]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Construct from-message `HTLCFailReason` via a constructor method
authorMatt Corallo <git@bluematt.me>
Thu, 1 Dec 2022 19:18:16 +0000 (19:18 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 1 Dec 2022 19:18:16 +0000 (19:18 +0000)
lightning/src/ln/channelmanager.rs

index 3b1c9d54eea3e05426d745fd2ffd3bf78183122a..eddb5589e4ffb4e4232ce100c6b818a55f4b6c4f 100644 (file)
@@ -309,6 +309,10 @@ impl HTLCFailReason {
                Self::Reason { failure_code, data: Vec::new() }
        }
 
+       pub(super) fn from_msg(msg: &msgs::UpdateFailHTLC) -> Self {
+               Self::LightningError { err: msg.reason.clone() }
+       }
+
        fn get_encrypted_failure_packet(&self, incoming_packet_shared_secret: &[u8; 32], phantom_shared_secret: &Option<[u8; 32]>) -> msgs::OnionErrorPacket {
                match self {
                        HTLCFailReason::Reason { ref failure_code, ref data } => {
@@ -5125,7 +5129,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
                                if chan.get().get_counterparty_node_id() != *counterparty_node_id {
                                        return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
                                }
-                               try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::LightningError { err: msg.reason.clone() }), chan);
+                               try_chan_entry!(self, chan.get_mut().update_fail_htlc(&msg, HTLCFailReason::from_msg(msg)), chan);
                        },
                        hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
                }