From 18ce6c8fd8e29ab9352c3241e4e5b9c69a4798f5 Mon Sep 17 00:00:00 2001 From: Yuntai Kyong Date: Thu, 27 Sep 2018 12:58:05 +0900 Subject: [PATCH] add a ChannelUnavailable error --- src/ln/channel.rs | 9 +++++++-- src/ln/channelmanager.rs | 2 +- src/util/errors.rs | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 1e28c6f4..0a923dc7 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 50c1c0fa..fd168de4 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 f9c7f711..6513beef 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), } } } -- 2.30.2