From: Yuntai Kyong Date: Thu, 27 Sep 2018 03:58:05 +0000 (+0900) Subject: add a ChannelUnavailable error X-Git-Tag: v0.0.12~296^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=18ce6c8fd8e29ab9352c3241e4e5b9c69a4798f5;p=rust-lightning add a ChannelUnavailable error --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 1e28c6f46..0a923dc7e 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -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(); diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 50c1c0fa9..fd168de41 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -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(..) { diff --git a/src/util/errors.rs b/src/util/errors.rs index f9c7f7111..6513beefe 100644 --- a/src/util/errors.rs +++ b/src/util/errors.rs @@ -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), } } }