]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove MsgHandleErrInternal::from_chan_maybe_close as it's useless
authorMatt Corallo <git@bluematt.me>
Fri, 23 Nov 2018 00:38:28 +0000 (19:38 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Nov 2018 04:57:54 +0000 (23:57 -0500)
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.

src/ln/channel.rs
src/ln/channelmanager.rs

index 1ae3333c1aa862c9262375008003d47f9cc70681..08f2446c05a156272abbca64e98eacae51d2a93e 100644 (file)
@@ -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<TxCreationKeys, ChannelError> {
                //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!");
index 79afb65801b8d534aed15e5de07acdedcc014d72..ad8f70b0304011328686a60a75e8c7091ac869cd 100644 (file)
@@ -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