add a ChannelUnavailable error
authorYuntai Kyong <yuntai.kyong@gmail.com>
Thu, 27 Sep 2018 03:58:05 +0000 (12:58 +0900)
committerYuntai Kyong <yuntai.kyong@gmail.com>
Tue, 2 Oct 2018 23:45:34 +0000 (08:45 +0900)
src/ln/channel.rs
src/ln/channelmanager.rs
src/util/errors.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();
index 50c1c0fa9d774139a2914138159d5f83ede315fd..fd168de4160a0ea1717e1780791ecefb55f47e4d 100644 (file)
@@ -481,7 +481,7 @@ impl ChannelManager {
                                                (res, chan_entry.get().get_their_node_id(), Some(chan_entry.remove_entry().1))
                                        } else { (res, chan_entry.get().get_their_node_id(), None) }
                                },
-                               hash_map::Entry::Vacant(_) => return Err(APIError::APIMisuseError{err: "No such channel"})
+                               hash_map::Entry::Vacant(_) => return Err(APIError::ChannelUnavailable{err: "No such channel"})
                        }
                };
                for htlc_source in res.1.drain(..) {
index f9c7f7111951fa8200c558c59dcdbdcbf13f480b..6513beefe794e82f9651e61b55739a5f7d8b651a 100644 (file)
@@ -26,6 +26,14 @@ pub enum APIError {
                /// A human-readable error message
                err: &'static str
        },
+
+
+       /// We were unable to complete the request since channel is disconnected or
+       /// shutdown in progress initiated by remote
+       ChannelUnavailable {
+               /// A human-readable error message
+               err: &'static str
+       }
 }
 
 impl fmt::Debug for APIError {
@@ -34,6 +42,7 @@ impl fmt::Debug for APIError {
                        APIError::APIMisuseError {ref err} => f.write_str(err),
                        APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate),
                        APIError::RouteError {ref err} => f.write_str(err),
+                       APIError::ChannelUnavailable {ref err} => f.write_str(err),
                }
        }
 }