From 7bb290fe3a6a38a1f94628c20f3ca1757f2be90f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 25 Mar 2018 15:48:12 -0400 Subject: [PATCH] Stop allowing new commitments without updates/revoke --- src/ln/channel.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 361dd89be..fe1cfd24a 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -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(); -- 2.39.5