Refactor handle_update_fail_malformed_htlc to wrapper error handling function
authorAntoine Riard <ariard@student.42.fr>
Fri, 7 Sep 2018 21:46:47 +0000 (21:46 +0000)
committerAntoine Riard <ariard@student.42.fr>
Fri, 7 Sep 2018 21:46:47 +0000 (21:46 +0000)
src/ln/channelmanager.rs

index 60f6eb20275a243892d9443acfbdf25200250aac..aedb48d36a472685d669115487db3392c4ed1405 100644 (file)
@@ -1812,6 +1812,20 @@ impl ChannelManager {
                }
        }
 
+       fn internal_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), MsgHandleErrInternal> {
+               let mut channel_state = self.channel_state.lock().unwrap();
+               match channel_state.by_id.get_mut(&msg.channel_id) {
+                       Some(chan) => {
+                               if chan.get_their_node_id() != *their_node_id {
+                                       //TODO: here and below MsgHandleErrInternal, #153 case
+                                       return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
+                               }
+                               chan.update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() }).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))
+                       },
+                       None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
+               }
+       }
+
        fn internal_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), MsgHandleErrInternal> {
                let (chan_announcement, chan_update) = {
                        let mut channel_state = self.channel_state.lock().unwrap();
@@ -2054,16 +2068,7 @@ impl ChannelMessageHandler for ChannelManager {
        }
 
        fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), HandleError> {
-               let mut channel_state = self.channel_state.lock().unwrap();
-               match channel_state.by_id.get_mut(&msg.channel_id) {
-                       Some(chan) => {
-                               if chan.get_their_node_id() != *their_node_id {
-                                       return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
-                               }
-                               chan.update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() })
-                       },
-                       None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
-               }
+               handle_error!(self, self.internal_update_fail_malformed_htlc(their_node_id, msg), their_node_id)
        }
 
        fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) -> Result<(msgs::RevokeAndACK, Option<msgs::CommitmentSigned>), HandleError> {