Update msg_targets with new, must-roundtrip, and hole messages
[rust-lightning] / src / ln / channel.rs
index 4fb4f47f0868a38afe9d0cafb2e19fe89f3b49c3..f890f03968903b137b99e34db09f6f4e4f4890ee 100644 (file)
@@ -2275,18 +2275,22 @@ impl Channel {
 
        /// Gets an UnsignedChannelAnnouncement, as well as a signature covering it using our
        /// bitcoin_key, if available, for this channel. The channel must be publicly announceable and
-       /// available for use (have exchanged FundingLocked messages in both directions. Should be used
+       /// available for use (have exchanged FundingLocked messages in both directions). Should be used
        /// for both loose and in response to an AnnouncementSignatures message from the remote peer.
-       /// Note that you can get an announcement for a channel which is closing, though you should
-       /// likely not announce such a thing. In case its already been announced, a channel_update
-       /// message can mark the channel disabled.
+       /// Will only fail if we're not in a state where channel_announcement may be sent (including
+       /// closing).
+       /// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
+       /// https://github.com/lightningnetwork/lightning-rfc/issues/468
        pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), HandleError> {
                if !self.announce_publicly {
                        return Err(HandleError{err: "Channel is not available for public announcements", action: None});
                }
-               if self.channel_state & (ChannelState::ChannelFunded as u32) != (ChannelState::ChannelFunded as u32) {
+               if self.channel_state & (ChannelState::ChannelFunded as u32) == 0 {
                        return Err(HandleError{err: "Cannot get a ChannelAnnouncement until the channel funding has been locked", action: None});
                }
+               if (self.channel_state & (ChannelState::LocalShutdownSent as u32 | ChannelState::ShutdownComplete as u32)) != 0 {
+                       return Err(HandleError{err: "Cannot get a ChannelAnnouncement once the channel is closing", action: None});
+               }
 
                let were_node_one = our_node_id.serialize()[..] < self.their_node_id.serialize()[..];
                let our_bitcoin_key = PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.funding_key);
@@ -2299,6 +2303,7 @@ impl Channel {
                        node_id_2: if were_node_one { self.get_their_node_id() } else { our_node_id },
                        bitcoin_key_1: if were_node_one { our_bitcoin_key } else { self.their_funding_pubkey.unwrap() },
                        bitcoin_key_2: if were_node_one { self.their_funding_pubkey.unwrap() } else { our_bitcoin_key },
+                       excess_data: Vec::new(),
                };
 
                let msghash = Message::from_slice(&Sha256dHash::from_data(&msg.encode()[..])[..]).unwrap();