From 2bb65a3fb8ee6788a6d8db3b1124519494ef2a9f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 21 Jul 2016 16:52:05 -0700 Subject: [PATCH] lnwallet: add PendingUpdates method to channel state machine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new method, “PendingUpdates” to the channel state machine which is intended to be a source to give callers a hint as to when an additional commitment signature should be sent independent of any request/response book keeping. --- lnwallet/channel.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 3c7e4e40a..897382005 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -821,6 +821,18 @@ func (lc *LightningChannel) ReceiveNewCommitment(rawSig []byte, return nil } +// PendingUpdates returns a boolean value reflecting if there are any pending +// updates which need to be committed. The state machine has pending updates if +// the local log index on the local and remote chain tip aren't identical. This +// indicates that either we have pending updates they need to commit, or vice +// versa. +func (lc *LightningChannel) PendingUpdates() bool { + fullySynced := (lc.localCommitChain.tip().ourMessageIndex == + lc.remoteCommitChain.tip().ourMessageIndex) + + return !fullySynced +} + // RevokeCurrentCommitment revokes the next lowest unrevoked commitment // transaction in the local commitment chain. As a result the edge of our // revocation window is extended by one, and the tail of our local commitment