lnwallet: convert PendingUpdates to FullySynced

This commit improves the channel state machine by converting the
objective PendingUpdates method to a subjective FullySynced method
which is to be used in place of PendingUpdates. The new FullySynced
method is fully encompassing and replaces any upper state required by
the state machine which wraps this one.

The new FullySynced method is identical to PendingUpdates aside from
the fact that: it now also factors in the log message index of the
remote commitment chain, and also introduces a concept of an “owed
commitment”. A commitment chain owes a commitment if the height of the
local commitment chain is higher than that of the remote chain.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-11 21:48:38 -07:00
parent 4cd277c8da
commit 31acace692
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -1725,21 +1725,24 @@ func (lc *LightningChannel) ReceiveNewCommitment(rawSig []byte) error {
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 {
// FullSynced returns a boolean value reflecting if both commitment chains
// (remote+local) are fully in sync. Both commitment chains are fully in sync
// if the tip of each chain includes the latest committed changes from both
// sides.
func (lc *LightningChannel) FullySynced() bool {
lc.RLock()
defer lc.RUnlock()
// TODO(roasbeef): instead check our current counter?
oweCommitment := (lc.localCommitChain.tip().height >
lc.remoteCommitChain.tip().height)
fullySynced := (lc.localCommitChain.tip().ourMessageIndex ==
localUpdatesSynced := (lc.localCommitChain.tip().ourMessageIndex ==
lc.remoteCommitChain.tip().ourMessageIndex)
return !fullySynced
remoteUpdatesSynced := (lc.localCommitChain.tip().theirMessageIndex ==
lc.remoteCommitChain.tip().theirMessageIndex)
return !oweCommitment && localUpdatesSynced && remoteUpdatesSynced
}
// RevokeCurrentCommitment revokes the next lowest unrevoked commitment