]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Stop allowing new commitments without updates/revoke
authorMatt Corallo <git@bluematt.me>
Sun, 25 Mar 2018 19:48:12 +0000 (15:48 -0400)
committerMatt Corallo <git@bluematt.me>
Sun, 25 Mar 2018 21:02:28 +0000 (17:02 -0400)
src/ln/channel.rs

index 361dd89befed7021f5aca6429f42b613a28b197a..fe1cfd24a25d74ce890ee6336a1311539af1a365 100644 (file)
@@ -1621,6 +1621,19 @@ impl Channel {
                if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
                        return Err(HandleError{err: "Cannot create commitment tx until channel is fully established", msg: None});
                }
+               if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
+                       return Err(HandleError{err: "Cannot create commitment tx until remote revokes their previous commitment", msg: None});
+               }
+               let mut have_updates = false; // TODO initialize with "have we sent a fee update?"
+               for htlc in self.pending_htlcs.iter() {
+                       if htlc.state == HTLCState::LocalAnnounced {
+                               have_updates = true;
+                       }
+                       if have_updates { break; }
+               }
+               if !have_updates {
+                       return Err(HandleError{err: "Cannot create commitment tx until we have some updates to send", msg: None});
+               }
 
                let funding_script = self.get_funding_redeemscript();