Rebroadcast channel_announcements when we broadcast a node_announce
[rust-lightning] / lightning / src / ln / channel.rs
index 94bf4c6f7c5567a485d509ccd13e8422e8e7d3ba..51872337801559f5d5630ddada69d3952b3952e0 100644 (file)
@@ -3831,6 +3831,8 @@ impl<Signer: Sign> Channel<Signer> {
        /// closing).
        /// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
        /// https://github.com/lightningnetwork/lightning-rfc/issues/468
+       ///
+       /// This will only return ChannelError::Ignore upon failure.
        pub fn get_channel_announcement(&self, node_id: PublicKey, chain_hash: BlockHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> {
                if !self.config.announced_channel {
                        return Err(ChannelError::Ignore("Channel is not available for public announcements".to_owned()));
@@ -3861,6 +3863,8 @@ impl<Signer: Sign> Channel<Signer> {
                Ok((msg, sig))
        }
 
+       /// Signs the given channel announcement, returning a ChannelError::Ignore if no keys are
+       /// available.
        fn sign_channel_announcement(&self, our_node_secret: &SecretKey, our_node_id: PublicKey, msghash: secp256k1::Message, announcement: msgs::UnsignedChannelAnnouncement, our_bitcoin_sig: Signature) -> Result<msgs::ChannelAnnouncement, ChannelError> {
                if let Some((their_node_sig, their_bitcoin_sig)) = self.announcement_sigs {
                        let were_node_one = announcement.node_id_1 == our_node_id;
@@ -3902,6 +3906,20 @@ impl<Signer: Sign> Channel<Signer> {
                self.sign_channel_announcement(our_node_secret, our_node_id, msghash, announcement, our_bitcoin_sig)
        }
 
+       /// Gets a signed channel_announcement for this channel, if we previously received an
+       /// announcement_signatures from our counterparty.
+       pub fn get_signed_channel_announcement(&self, our_node_secret: &SecretKey, our_node_id: PublicKey, chain_hash: BlockHash) -> Option<msgs::ChannelAnnouncement> {
+               let (announcement, our_bitcoin_sig) = match self.get_channel_announcement(our_node_id.clone(), chain_hash) {
+                       Ok(res) => res,
+                       Err(_) => return None,
+               };
+               let msghash = hash_to_message!(&Sha256d::hash(&announcement.encode()[..])[..]);
+               match self.sign_channel_announcement(our_node_secret, our_node_id, msghash, announcement, our_bitcoin_sig) {
+                       Ok(res) => Some(res),
+                       Err(_) => None,
+               }
+       }
+
        /// May panic if called on a channel that wasn't immediately-previously
        /// self.remove_uncommitted_htlcs_and_mark_paused()'d
        pub fn get_channel_reestablish<L: Deref>(&self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {