From: Matt Corallo Date: Fri, 23 Nov 2018 00:38:28 +0000 (-0500) Subject: Remove MsgHandleErrInternal::from_chan_maybe_close as it's useless X-Git-Tag: v0.0.12~264^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=fe3d706d5b35c7ace87ebc7f529b98b727ffb18f;p=rust-lightning Remove MsgHandleErrInternal::from_chan_maybe_close as it's useless Technically funding_transaction_generated was fine using it, but calling force_shutdown on an empty Channel inside the channel_state lock isn't a big deal and almost any other use of it would be unsafe. --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 1ae3333c1..08f2446c0 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1004,6 +1004,7 @@ impl Channel { #[inline] /// Creates a set of keys for build_commitment_transaction to generate a transaction which we /// will sign and send to our counterparty. + /// If an Err is returned, it is a ChannelError::Close (for get_outbound_funding_created) fn build_remote_transaction_keys(&self) -> Result { //TODO: Ensure that the payment_key derived here ends up in the library users' wallet as we //may see payments to it! @@ -2949,6 +2950,7 @@ impl Channel { } } + /// If an Err is returned, it is a ChannelError::Close (for get_outbound_funding_created) fn get_outbound_funding_created_signature(&mut self) -> Result<(Signature, Transaction), ChannelError> { let funding_script = self.get_funding_redeemscript(); @@ -2966,6 +2968,7 @@ impl Channel { /// or if called on an inbound channel. /// Note that channel_id changes during this call! /// Do NOT broadcast the funding transaction until after a successful funding_signed call! + /// If an Err is returned, it is a ChannelError::Close. pub fn get_outbound_funding_created(&mut self, funding_txo: OutPoint) -> Result<(msgs::FundingCreated, ChannelMonitor), ChannelError> { if !self.channel_outbound { panic!("Tried to create outbound funding_created message on an inbound channel!"); diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 79afb6580..ad8f70b03 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -215,28 +215,6 @@ impl MsgHandleErrInternal { shutdown_finish: None, } } - #[inline] - fn from_chan_maybe_close(err: ChannelError, channel_id: [u8; 32]) -> Self { - Self { - err: match err { - ChannelError::Ignore(msg) => HandleError { - err: msg, - action: Some(msgs::ErrorAction::IgnoreError), - }, - ChannelError::Close(msg) => HandleError { - err: msg, - action: Some(msgs::ErrorAction::SendErrorMessage { - msg: msgs::ErrorMessage { - channel_id, - data: msg.to_string() - }, - }), - }, - }, - needs_channel_force_close: true, - shutdown_finish: None, - } - } } /// Pass to fail_htlc_backwwards to indicate the reason to fail the payment @@ -1363,7 +1341,9 @@ impl ChannelManager { match channel_state.by_id.remove(temporary_channel_id) { Some(mut chan) => { (chan.get_outbound_funding_created(funding_txo) - .map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, chan.channel_id())) + .map_err(|e| if let ChannelError::Close(msg) = e { + MsgHandleErrInternal::from_finish_shutdown(msg, chan.channel_id(), chan.force_shutdown(), None) + } else { unreachable!(); }) , chan) }, None => return