add a ChannelUnavailable error
[rust-lightning] / src / ln / channel.rs
index 1e28c6f463f3a348b198cd911efabc1ab87d5c82..0a923dc7eedc904da44f31d6ed9f6c74c422b6a3 100644 (file)
@@ -2886,11 +2886,16 @@ impl Channel {
                        }
                }
                if self.channel_state & BOTH_SIDES_SHUTDOWN_MASK != 0 {
-                       return Err(APIError::APIMisuseError{err: "Shutdown already in progress"});
+                       if (self.channel_state & ChannelState::LocalShutdownSent as u32) == ChannelState::LocalShutdownSent as u32 {
+                               return Err(APIError::APIMisuseError{err: "Shutdown already in progress"});
+                       }
+                       else if (self.channel_state & ChannelState::RemoteShutdownSent as u32) == ChannelState::RemoteShutdownSent as u32 {
+                               return Err(APIError::ChannelUnavailable{err: "Shutdown already in progress by remote"});
+                       }
                }
                assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);
                if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
-                       return Err(APIError::APIMisuseError{err: "Cannot begin shutdown while peer is disconnected, maybe force-close instead?"});
+                       return Err(APIError::ChannelUnavailable{err: "Cannot begin shutdown while peer is disconnected, maybe force-close instead?"});
                }
 
                let our_closing_script = self.get_closing_scriptpubkey();